Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 090fe01

Browse files
Migrate to Swift3.0
1 parent 9b2558d commit 090fe01

33 files changed

Lines changed: 761 additions & 726 deletions

PullToRefreshKit.xcodeproj/project.pbxproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,11 +868,12 @@
868868
isa = PBXProject;
869869
attributes = {
870870
LastSwiftUpdateCheck = 0730;
871-
LastUpgradeCheck = 0730;
871+
LastUpgradeCheck = 0800;
872872
ORGANIZATIONNAME = Leo;
873873
TargetAttributes = {
874874
52E8FB3B1D336E26000D0BF1 = {
875875
CreatedOnToolsVersion = 7.3.1;
876+
LastSwiftMigration = 0800;
876877
};
877878
};
878879
};
@@ -1170,6 +1171,7 @@
11701171
isa = XCBuildConfiguration;
11711172
buildSettings = {
11721173
ALWAYS_SEARCH_USER_PATHS = NO;
1174+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
11731175
CLANG_ANALYZER_NONNULL = YES;
11741176
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
11751177
CLANG_CXX_LIBRARY = "libc++";
@@ -1180,8 +1182,10 @@
11801182
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
11811183
CLANG_WARN_EMPTY_BODY = YES;
11821184
CLANG_WARN_ENUM_CONVERSION = YES;
1185+
CLANG_WARN_INFINITE_RECURSION = YES;
11831186
CLANG_WARN_INT_CONVERSION = YES;
11841187
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1188+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
11851189
CLANG_WARN_UNREACHABLE_CODE = YES;
11861190
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
11871191
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -1216,6 +1220,7 @@
12161220
isa = XCBuildConfiguration;
12171221
buildSettings = {
12181222
ALWAYS_SEARCH_USER_PATHS = NO;
1223+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
12191224
CLANG_ANALYZER_NONNULL = YES;
12201225
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
12211226
CLANG_CXX_LIBRARY = "libc++";
@@ -1226,8 +1231,10 @@
12261231
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
12271232
CLANG_WARN_EMPTY_BODY = YES;
12281233
CLANG_WARN_ENUM_CONVERSION = YES;
1234+
CLANG_WARN_INFINITE_RECURSION = YES;
12291235
CLANG_WARN_INT_CONVERSION = YES;
12301236
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1237+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
12311238
CLANG_WARN_UNREACHABLE_CODE = YES;
12321239
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
12331240
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -1246,6 +1253,7 @@
12461253
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
12471254
MTL_ENABLE_DEBUG_INFO = NO;
12481255
SDKROOT = iphoneos;
1256+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
12491257
TARGETED_DEVICE_FAMILY = "1,2";
12501258
VALIDATE_PRODUCT = YES;
12511259
};
@@ -1259,6 +1267,7 @@
12591267
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
12601268
PRODUCT_BUNDLE_IDENTIFIER = Leo.PullToRefreshKit;
12611269
PRODUCT_NAME = "$(TARGET_NAME)";
1270+
SWIFT_VERSION = 3.0;
12621271
};
12631272
name = Debug;
12641273
};
@@ -1270,6 +1279,7 @@
12701279
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
12711280
PRODUCT_BUNDLE_IDENTIFIER = Leo.PullToRefreshKit;
12721281
PRODUCT_NAME = "$(TARGET_NAME)";
1282+
SWIFT_VERSION = 3.0;
12731283
};
12741284
name = Release;
12751285
};

PullToRefreshKit/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
22+
func applicationWillResignActive(_ application: UIApplication) {
2323
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2424
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
2525
}
2626

27-
func applicationDidEnterBackground(application: UIApplication) {
27+
func applicationDidEnterBackground(_ application: UIApplication) {
2828
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
2929
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3030
}
3131

32-
func applicationWillEnterForeground(application: UIApplication) {
32+
func applicationWillEnterForeground(_ application: UIApplication) {
3333
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3434
}
3535

36-
func applicationDidBecomeActive(application: UIApplication) {
36+
func applicationDidBecomeActive(_ application: UIApplication) {
3737
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
3838
}
3939

40-
func applicationWillTerminate(application: UIApplication) {
40+
func applicationWillTerminate(_ application: UIApplication) {
4141
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4242
}
4343

PullToRefreshKit/BaseTableViewController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ class BaseTableViewController: UITableViewController {
1212
var models = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
15-
self.tableView.tableFooterView = UIView(frame: CGRectZero)
15+
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
1616
}
17-
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
17+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
1818
return models.count
1919
}
20-
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
20+
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
2121
return 44.0
2222
}
23-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
24-
var cell = tableView.dequeueReusableCellWithIdentifier("cell")
23+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
24+
var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
2525
if cell == nil {
26-
cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
26+
cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
2727
}
28-
cell?.textLabel?.text = "\(models[indexPath.row])"
28+
cell?.textLabel?.text = "\(models[(indexPath as NSIndexPath).row])"
2929
return cell!
3030
}
3131
deinit{
32-
print("Deinit of \(NSStringFromClass(self.dynamicType))")
32+
print("Deinit of \(NSStringFromClass(type(of: self)))")
3333
}
3434
}

PullToRefreshKit/ConfigBannerController.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,46 @@ class ConfigBannerController: UIViewController {
1717
self.automaticallyAdjustsScrollViewInsets = false
1818
setUpViews()
1919

20-
scrollView.setUpLeftRefresh { [weak self] in
21-
self?.navigationController?.popViewControllerAnimated(true)
20+
_ = scrollView.setUpLeftRefresh { [weak self] in
21+
_ = self?.navigationController?.popViewController(animated: true)
2222
}.SetUp { (left) in
2323
left.setText("👉滑动关闭", mode: RefreshKitLeftRightText.scrollToAction)
2424
left.setText("松开关闭", mode: RefreshKitLeftRightText.releaseToAction)
25-
left.textLabel.textColor = UIColor.orangeColor()
25+
left.textLabel.textColor = UIColor.orange
2626
}
27-
scrollView.setUpRightRefresh { [weak self] in
28-
self?.navigationController?.popViewControllerAnimated(true)
27+
_ = scrollView.setUpRightRefresh { [weak self] in
28+
_ = self?.navigationController?.popViewController(animated: true)
2929
}.SetUp { (right) in
3030
right.setText("👈滑动关闭", mode: RefreshKitLeftRightText.scrollToAction)
3131
right.setText("松开关闭", mode: RefreshKitLeftRightText.releaseToAction)
32-
right.textLabel.textColor = UIColor.orangeColor()
32+
right.textLabel.textColor = UIColor.orange
3333
}
3434
}
3535

3636
func setUpViews(){
37-
view.backgroundColor = UIColor.whiteColor()
38-
let screenWidth = UIScreen.mainScreen().bounds.size.width;
37+
view.backgroundColor = UIColor.white
38+
let screenWidth = UIScreen.main.bounds.size.width;
3939
let scrollheight = screenWidth / 8.0 * 5.0
40-
scrollView.frame = CGRectMake(0, 0, screenWidth, scrollheight)
40+
scrollView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: scrollheight)
4141
scrollView.center = self.view.center
4242
self.view.addSubview(scrollView)
43-
let imageView1 = UIImageView(frame:CGRectMake(0, 0, screenWidth, scrollheight))
43+
let imageView1 = UIImageView(frame:CGRect(x: 0, y: 0, width: screenWidth, height: scrollheight))
4444
imageView1.image = UIImage(named: "banner1.jpg")
4545
scrollView.addSubview(imageView1)
4646

47-
let imageView2 = UIImageView(frame:CGRectMake(screenWidth, 0, screenWidth, scrollheight))
47+
let imageView2 = UIImageView(frame:CGRect(x: screenWidth, y: 0, width: screenWidth, height: scrollheight))
4848
imageView2.image = UIImage(named: "banner2.jpg")
4949
scrollView.addSubview(imageView2)
5050

51-
scrollView.pagingEnabled = true
52-
scrollView.contentSize = CGSizeMake(screenWidth * 2, scrollheight)
51+
scrollView.isPagingEnabled = true
52+
scrollView.contentSize = CGSize(width: screenWidth * 2, height: scrollheight)
5353
let desLabel = UILabel().SetUp { (label) in
54-
label.frame = CGRectMake(0, 0, screenWidth, 40)
55-
label.font = UIFont.systemFontOfSize(14)
56-
label.center = CGPointMake(scrollView.center.x, scrollView.center.y - CGRectGetWidth(scrollView.frame)/2 - 20)
54+
label.frame = CGRect(x: 0, y: 0, width: screenWidth, height: 40)
55+
label.font = UIFont.systemFont(ofSize: 14)
56+
label.center = CGPoint(x: scrollView.center.x, y: scrollView.center.y - scrollView.frame.width/2 - 20)
5757
label.text = "向左或向右滑动Banner"
58-
label.textAlignment = .Center
58+
label.textAlignment = .center
5959
}
6060
view.addSubview(desLabel)
6161
}
62-
}
62+
}

PullToRefreshKit/ConfigHeaderFooterController.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,53 @@ class ConfigDefaultHeaderFooterController: UITableViewController {
1313

1414
override func viewDidLoad() {
1515
super.viewDidLoad()
16-
self.tableView.tableFooterView = UIView(frame: CGRectZero)
16+
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
1717

1818
//Header
19-
self.tableView.setUpHeaderRefresh { [weak self] in
19+
_ = self.tableView.setUpHeaderRefresh { [weak self] in
2020
delay(1.5, closure: {
2121
self?.models = (self?.models.map({_ in random100()}))!
2222
self?.tableView.reloadData()
23-
self?.tableView.endHeaderRefreshing(.Success,delay: 0.3)
23+
self?.tableView.endHeaderRefreshing(.success,delay: 0.3)
2424
})
2525
}.SetUp { (header) in
2626
header.setText("Pull to refresh", mode: .pullToRefresh)
2727
header.setText("Release to refresh", mode: .releaseToRefresh)
2828
header.setText("Success", mode: .refreshSuccess)
2929
header.setText("Refreshing...", mode: .refreshing)
3030
header.setText("Failed", mode: .refreshFailure)
31-
header.textLabel.textColor = UIColor.orangeColor()
31+
header.textLabel.textColor = UIColor.orange
3232
header.durationWhenHide = 0.4
3333
}
3434
//Footer
3535

36-
self.tableView.setUpFooterRefresh { [weak self] in
36+
_ = self.tableView.setUpFooterRefresh { [weak self] in
3737
delay(1.5, closure: {
3838
self?.models.append(random100())
3939
self?.tableView.reloadData()
4040
self?.tableView.endFooterRefreshing()
4141
})
4242
}.SetUp { (footer) in
43-
footer.setText("Pull up to refresh", mode: RefreshKitFooterText.PullToRefresh)
44-
footer.setText("No data any more", mode: RefreshKitFooterText.NoMoreData)
45-
footer.setText("Refreshing...", mode: RefreshKitFooterText.Refreshing)
46-
footer.setText("Tap to load more", mode: RefreshKitFooterText.TapToRefresh)
47-
footer.textLabel.textColor = UIColor.orangeColor()
48-
footer.refreshMode = .Tap
43+
footer.setText("Pull up to refresh", mode: RefreshKitFooterText.pullToRefresh)
44+
footer.setText("No data any more", mode: RefreshKitFooterText.noMoreData)
45+
footer.setText("Refreshing...", mode: RefreshKitFooterText.refreshing)
46+
footer.setText("Tap to load more", mode: RefreshKitFooterText.tapToRefresh)
47+
footer.textLabel.textColor = UIColor.orange
48+
footer.refreshMode = .tap
4949
}
5050
}
51-
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
51+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
5252
return models.count
5353
}
54-
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
54+
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
5555
return 44.0
5656
}
57-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
58-
var cell = tableView.dequeueReusableCellWithIdentifier("cell")
57+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
58+
var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
5959
if cell == nil {
60-
cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
60+
cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
6161
}
62-
cell?.textLabel?.text = "\(models[indexPath.row])"
62+
cell?.textLabel?.text = "\(models[(indexPath as NSIndexPath).row])"
6363
return cell!
6464
}
6565
deinit{

PullToRefreshKit/CurveMaskTableViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class CurveMaskTableViewController:BaseTableViewController{
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515
//Setup
16-
let curveHeader = CurveRefreshHeader(frame: CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0))
17-
self.tableView.setUpHeaderRefresh(curveHeader) { [weak self] in
16+
let curveHeader = CurveRefreshHeader(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 0))
17+
_ = self.tableView.setUpHeaderRefresh(curveHeader) { [weak self] in
1818
delay(1.5, closure: {
1919
self?.models = (self?.models.map({_ in random100()}))!
2020
self?.tableView.reloadData()
@@ -23,4 +23,4 @@ class CurveMaskTableViewController:BaseTableViewController{
2323
}
2424
// self.tableView.beginHeaderRefreshing()
2525
}
26-
}
26+
}

0 commit comments

Comments
 (0)