Skip to content

Commit 794f085

Browse files
Merge pull request #226 from xmartlabs/Swift3
Convert XLPagerTabStrip to Swift 3
2 parents d6011fe + 9d80d20 commit 794f085

34 files changed

+595
-548
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: objective-c
2-
osx_image: xcode7.3
2+
osx_image: xcode8
33
env:
4-
- DESTINATION="OS=9.3,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator9.3
4+
- DESTINATION="OS=10.0,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator10.0
55
before_install:
66
- brew update
77
#- brew outdated carthage || brew upgrade carthage
@@ -10,7 +10,7 @@ before_install:
1010
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
1111

1212
script:
13-
- xctool clean build -project XLPagerTabStrip.xcodeproj -scheme XLPagerTabStrip -sdk iphonesimulator9.3
14-
#- xctool test -project XLPagerTabStrip.xcodeproj -scheme XLPagerTabStrip -sdk iphonesimulator9.3
13+
- xcodebuild clean build -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK"
14+
#- xcodebuild test -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK"
1515
- xcodebuild -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION"
1616
-configuration Debug ONLY_ACTIVE_ARCH=NO test | xcpretty -c

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Change Log
22
All notable changes to XLPagerTabStrip will be documented in this file.
33

4+
### [6.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)
5+
6+
* Swift 3 support
7+
* **Breaking change**: Swiftified names of functions (you can see more details about it [here](https://github.com/xmartlabs/XLPagerTabStrip/Migration.md))
8+
9+
### [5.1.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)
10+
11+
* Xcode 8 support. (Swift 2.3)
12+
413
### [5.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)
514

615
* Xcode 7.3 support.

Example.xcodeproj/project.pbxproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,15 @@
295295
isa = PBXProject;
296296
attributes = {
297297
LastSwiftUpdateCheck = 0720;
298-
LastUpgradeCheck = 0720;
298+
LastUpgradeCheck = 0800;
299299
TargetAttributes = {
300300
28F828CB1C4B714D00330CF4 = {
301301
CreatedOnToolsVersion = 7.2;
302+
LastSwiftMigration = 0800;
302303
};
303304
28F828DF1C4B714D00330CF4 = {
304305
CreatedOnToolsVersion = 7.2;
306+
LastSwiftMigration = 0800;
305307
TestTargetID = 28F828CB1C4B714D00330CF4;
306308
};
307309
};
@@ -441,8 +443,10 @@
441443
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
442444
CLANG_WARN_EMPTY_BODY = YES;
443445
CLANG_WARN_ENUM_CONVERSION = YES;
446+
CLANG_WARN_INFINITE_RECURSION = YES;
444447
CLANG_WARN_INT_CONVERSION = YES;
445448
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
449+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
446450
CLANG_WARN_UNREACHABLE_CODE = YES;
447451
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
448452
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -485,8 +489,10 @@
485489
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
486490
CLANG_WARN_EMPTY_BODY = YES;
487491
CLANG_WARN_ENUM_CONVERSION = YES;
492+
CLANG_WARN_INFINITE_RECURSION = YES;
488493
CLANG_WARN_INT_CONVERSION = YES;
489494
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
495+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
490496
CLANG_WARN_UNREACHABLE_CODE = YES;
491497
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
492498
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -505,36 +511,39 @@
505511
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
506512
MTL_ENABLE_DEBUG_INFO = NO;
507513
SDKROOT = iphoneos;
514+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
508515
VALIDATE_PRODUCT = YES;
509516
};
510517
name = Release;
511518
};
512519
28F828EA1C4B714D00330CF4 /* Debug */ = {
513520
isa = XCBuildConfiguration;
514521
buildSettings = {
522+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
515523
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
516524
CLANG_ENABLE_MODULES = YES;
517-
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
518525
INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist";
519526
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
520527
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example;
521528
PRODUCT_NAME = "$(TARGET_NAME)";
522529
SWIFT_OBJC_BRIDGING_HEADER = "";
523530
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
531+
SWIFT_VERSION = 3.0;
524532
};
525533
name = Debug;
526534
};
527535
28F828EB1C4B714D00330CF4 /* Release */ = {
528536
isa = XCBuildConfiguration;
529537
buildSettings = {
538+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
530539
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
531540
CLANG_ENABLE_MODULES = YES;
532-
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
533541
INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist";
534542
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
535543
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example;
536544
PRODUCT_NAME = "$(TARGET_NAME)";
537545
SWIFT_OBJC_BRIDGING_HEADER = "";
546+
SWIFT_VERSION = 3.0;
538547
};
539548
name = Release;
540549
};
@@ -547,6 +556,7 @@
547556
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.ExampleUITests;
548557
PRODUCT_NAME = "$(TARGET_NAME)";
549558
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
559+
SWIFT_VERSION = 3.0;
550560
TEST_TARGET_NAME = Example;
551561
USES_XCTRUNNER = YES;
552562
};
@@ -560,6 +570,7 @@
560570
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
561571
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.ExampleUITests;
562572
PRODUCT_NAME = "$(TARGET_NAME)";
573+
SWIFT_VERSION = 3.0;
563574
TEST_TARGET_NAME = Example;
564575
USES_XCTRUNNER = YES;
565576
};

Example/Example/AppDelegate.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313
var window: UIWindow?
1414

1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1717
// Override point for customization after application launch.
1818

1919
UITabBar.appearance().tintColor = UIColor.init(red: 0.027, green: 0.725, blue: 0.608, alpha: 1)
20-
UIApplication.sharedApplication().statusBarStyle = .LightContent
20+
UIApplication.shared.statusBarStyle = .lightContent
2121

2222
let _ = YoutubeExampleViewController(nibName: nil, bundle: nil)
2323

2424
return true
2525
}
2626

27-
func applicationWillResignActive(application: UIApplication) {
27+
func applicationWillResignActive(_ application: UIApplication) {
2828
// 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.
2929
// 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.
3030
}
3131

32-
func applicationDidEnterBackground(application: UIApplication) {
32+
func applicationDidEnterBackground(_ application: UIApplication) {
3333
// 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.
3434
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3535
}
3636

37-
func applicationWillEnterForeground(application: UIApplication) {
37+
func applicationWillEnterForeground(_ application: UIApplication) {
3838
// 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.
3939
}
4040

41-
func applicationDidBecomeActive(application: UIApplication) {
41+
func applicationDidBecomeActive(_ application: UIApplication) {
4242
// 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.
4343
}
4444

45-
func applicationWillTerminate(application: UIApplication) {
45+
func applicationWillTerminate(_ application: UIApplication) {
4646
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4747
}
4848

Example/Example/BarExampleViewController.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,44 @@ class BarExampleViewController: BarPagerTabStripViewController {
3535
override func viewDidLoad() {
3636

3737
// set up style before super view did load is executed
38-
settings.style.selectedBarBackgroundColor = .orangeColor()
38+
settings.style.selectedBarBackgroundColor = .orange
3939
// -
4040

4141
super.viewDidLoad()
4242
}
4343

4444
// MARK: - PagerTabStripDataSource
4545

46-
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
46+
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
4747

48-
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
48+
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
4949
let child_2 = ChildExampleViewController(itemInfo: "View")
50-
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
50+
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
5151
let child_4 = ChildExampleViewController(itemInfo: "View 2")
5252

5353
guard isReload else {
5454
return [child_1, child_2, child_3, child_4]
5555
}
5656

5757
var childViewControllers = [child_1, child_2, child_3, child_4]
58-
for (index, _) in childViewControllers.enumerate(){
58+
for (index, _) in childViewControllers.enumerated(){
5959
let nElements = childViewControllers.count - index
6060
let n = (Int(arc4random()) % nElements) + index
6161
if n != index{
6262
swap(&childViewControllers[index], &childViewControllers[n])
6363
}
6464
}
65-
let nItems = 1 + (rand() % 4)
65+
let nItems = 1 + (arc4random() % 4)
6666
return Array(childViewControllers.prefix(Int(nItems)))
6767
}
6868

6969
override func reloadPagerTabStripView() {
7070
isReload = true
71-
if rand() % 2 == 0 {
72-
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
71+
if arc4random() % 2 == 0 {
72+
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
7373
}
7474
else {
75-
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
75+
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
7676
}
7777
super.reloadPagerTabStripView()
7878
}

Example/Example/ButtonBarExampleViewController.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
3232
override func viewDidLoad() {
3333
super.viewDidLoad()
3434

35-
buttonBarView.selectedBar.backgroundColor = .orangeColor()
35+
buttonBarView.selectedBar.backgroundColor = .orange
3636
buttonBarView.backgroundColor = UIColor(red: 7/255, green: 185/255, blue: 155/255, alpha: 1)
3737
}
3838

3939
// MARK: - PagerTabStripDataSource
4040

41-
override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
42-
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
41+
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
42+
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
4343
let child_2 = ChildExampleViewController(itemInfo: "View")
44-
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
44+
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
4545
let child_4 = ChildExampleViewController(itemInfo: "View 2")
46-
let child_5 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View 3")
46+
let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "Table View 3")
4747
let child_6 = ChildExampleViewController(itemInfo: "View 3")
48-
let child_7 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 4")
48+
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 4")
4949
let child_8 = ChildExampleViewController(itemInfo: "View 4")
5050

5151
guard isReload else {
@@ -54,24 +54,24 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
5454

5555
var childViewControllers = [child_1, child_2, child_3, child_4, child_6, child_7, child_8]
5656

57-
for (index, _) in childViewControllers.enumerate(){
57+
for (index, _) in childViewControllers.enumerated(){
5858
let nElements = childViewControllers.count - index
5959
let n = (Int(arc4random()) % nElements) + index
6060
if n != index{
6161
swap(&childViewControllers[index], &childViewControllers[n])
6262
}
6363
}
64-
let nItems = 1 + (rand() % 8)
64+
let nItems = 1 + (arc4random() % 8)
6565
return Array(childViewControllers.prefix(Int(nItems)))
6666
}
6767

6868
override func reloadPagerTabStripView() {
6969
isReload = true
70-
if rand() % 2 == 0 {
71-
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
70+
if arc4random() % 2 == 0 {
71+
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
7272
}
7373
else {
74-
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
74+
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
7575
}
7676
super.reloadPagerTabStripView()
7777
}

Example/Example/ChildControllers/ChildExampleViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class ChildExampleViewController: UIViewController, IndicatorInfoProvider {
4646
label.text = "XLPagerTabStrip"
4747

4848
view.addSubview(label)
49-
view.backgroundColor = .whiteColor()
49+
view.backgroundColor = .white
5050

51-
view.addConstraint(NSLayoutConstraint(item: label, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: 0))
52-
view.addConstraint(NSLayoutConstraint(item: label, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: -50))
51+
view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0))
52+
view.addConstraint(NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1, constant: -50))
5353
}
5454

5555
// MARK: - IndicatorInfoProvider
5656

57-
func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
57+
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
5858
return itemInfo
5959
}
6060
}

Example/Example/ChildControllers/TableChildExampleViewController.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
4242

4343
override func viewDidLoad() {
4444
super.viewDidLoad()
45-
tableView.registerNib(UINib(nibName: "PostCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: cellIdentifier)
45+
tableView.register(UINib(nibName: "PostCell", bundle: Bundle.main), forCellReuseIdentifier: cellIdentifier)
4646
tableView.estimatedRowHeight = 60.0;
4747
tableView.rowHeight = UITableViewAutomaticDimension
4848
tableView.allowsSelection = false
@@ -51,24 +51,24 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
5151
}
5252
}
5353

54-
override func viewWillAppear(animated: Bool) {
54+
override func viewWillAppear(_ animated: Bool) {
5555
super.viewWillAppear(animated)
5656
tableView.reloadData()
5757
}
5858

5959
// MARK: - UITableViewDataSource
6060

61-
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
61+
override func numberOfSections(in tableView: UITableView) -> Int {
6262
return 1
6363
}
6464

65-
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
65+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
6666
return DataProvider.sharedInstance.postsData.count
6767
}
68-
69-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
70-
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PostCell
71-
let data = DataProvider.sharedInstance.postsData.objectAtIndex(indexPath.row) as!
68+
69+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
70+
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! PostCell
71+
let data = DataProvider.sharedInstance.postsData.object(at: indexPath.row) as!
7272
NSDictionary
7373
cell.configureWithData(data)
7474
if blackTheme {
@@ -79,7 +79,7 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
7979

8080
// MARK: - IndicatorInfoProvider
8181

82-
func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
82+
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
8383
return itemInfo
8484
}
8585
}

0 commit comments

Comments
 (0)