Skip to content

Commit

Permalink
Merge pull request #226 from xmartlabs/Swift3
Browse files Browse the repository at this point in the history
Convert XLPagerTabStrip to Swift 3
  • Loading branch information
mats-claassen authored Sep 16, 2016
2 parents d6011fe + 9d80d20 commit 794f085
Show file tree
Hide file tree
Showing 34 changed files with 595 additions and 548 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: objective-c
osx_image: xcode7.3
osx_image: xcode8
env:
- DESTINATION="OS=9.3,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator9.3
- DESTINATION="OS=10.0,name=iPhone 6s" SCHEME="XLPagerTabStrip" SDK=iphonesimulator10.0
before_install:
- brew update
#- brew outdated carthage || brew upgrade carthage
Expand All @@ -10,7 +10,7 @@ before_install:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet

script:
- xctool clean build -project XLPagerTabStrip.xcodeproj -scheme XLPagerTabStrip -sdk iphonesimulator9.3
#- xctool test -project XLPagerTabStrip.xcodeproj -scheme XLPagerTabStrip -sdk iphonesimulator9.3
- xcodebuild clean build -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK"
#- xcodebuild test -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK"
- xcodebuild -project XLPagerTabStrip.xcodeproj -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION"
-configuration Debug ONLY_ACTIVE_ARCH=NO test | xcpretty -c
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Change Log
All notable changes to XLPagerTabStrip will be documented in this file.

### [6.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)

* Swift 3 support
* **Breaking change**: Swiftified names of functions (you can see more details about it [here](https://github.com/xmartlabs/XLPagerTabStrip/Migration.md))

### [5.1.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)

* Xcode 8 support. (Swift 2.3)

### [5.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/5.0.0)

* Xcode 7.3 support.
Expand Down
17 changes: 14 additions & 3 deletions Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,15 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
TargetAttributes = {
28F828CB1C4B714D00330CF4 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
28F828DF1C4B714D00330CF4 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 28F828CB1C4B714D00330CF4;
};
};
Expand Down Expand Up @@ -441,8 +443,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -485,8 +489,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -505,36 +511,39 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
28F828EA1C4B714D00330CF4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
28F828EB1C4B714D00330CF4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -547,6 +556,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.ExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = Example;
USES_XCTRUNNER = YES;
};
Expand All @@ -560,6 +570,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.ExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = Example;
USES_XCTRUNNER = YES;
};
Expand Down
14 changes: 7 additions & 7 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


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

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

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

return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// 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.
// 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.
}

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

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

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

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

Expand Down
18 changes: 9 additions & 9 deletions Example/Example/BarExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,44 @@ class BarExampleViewController: BarPagerTabStripViewController {
override func viewDidLoad() {

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

super.viewDidLoad()
}

// MARK: - PagerTabStripDataSource

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

let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
let child_2 = ChildExampleViewController(itemInfo: "View")
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
let child_4 = ChildExampleViewController(itemInfo: "View 2")

guard isReload else {
return [child_1, child_2, child_3, child_4]
}

var childViewControllers = [child_1, child_2, child_3, child_4]
for (index, _) in childViewControllers.enumerate(){
for (index, _) in childViewControllers.enumerated(){
let nElements = childViewControllers.count - index
let n = (Int(arc4random()) % nElements) + index
if n != index{
swap(&childViewControllers[index], &childViewControllers[n])
}
}
let nItems = 1 + (rand() % 4)
let nItems = 1 + (arc4random() % 4)
return Array(childViewControllers.prefix(Int(nItems)))
}

override func reloadPagerTabStripView() {
isReload = true
if rand() % 2 == 0 {
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
if arc4random() % 2 == 0 {
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
}
else {
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
}
super.reloadPagerTabStripView()
}
Expand Down
22 changes: 11 additions & 11 deletions Example/Example/ButtonBarExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {
override func viewDidLoad() {
super.viewDidLoad()

buttonBarView.selectedBar.backgroundColor = .orangeColor()
buttonBarView.selectedBar.backgroundColor = .orange
buttonBarView.backgroundColor = UIColor(red: 7/255, green: 185/255, blue: 155/255, alpha: 1)
}

// MARK: - PagerTabStripDataSource

override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child_1 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View")
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "Table View")
let child_2 = ChildExampleViewController(itemInfo: "View")
let child_3 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 2")
let child_3 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 2")
let child_4 = ChildExampleViewController(itemInfo: "View 2")
let child_5 = TableChildExampleViewController(style: .Plain, itemInfo: "Table View 3")
let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "Table View 3")
let child_6 = ChildExampleViewController(itemInfo: "View 3")
let child_7 = TableChildExampleViewController(style: .Grouped, itemInfo: "Table View 4")
let child_7 = TableChildExampleViewController(style: .grouped, itemInfo: "Table View 4")
let child_8 = ChildExampleViewController(itemInfo: "View 4")

guard isReload else {
Expand All @@ -54,24 +54,24 @@ class ButtonBarExampleViewController: ButtonBarPagerTabStripViewController {

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

for (index, _) in childViewControllers.enumerate(){
for (index, _) in childViewControllers.enumerated(){
let nElements = childViewControllers.count - index
let n = (Int(arc4random()) % nElements) + index
if n != index{
swap(&childViewControllers[index], &childViewControllers[n])
}
}
let nItems = 1 + (rand() % 8)
let nItems = 1 + (arc4random() % 8)
return Array(childViewControllers.prefix(Int(nItems)))
}

override func reloadPagerTabStripView() {
isReload = true
if rand() % 2 == 0 {
pagerBehaviour = .Progressive(skipIntermediateViewControllers: rand() % 2 == 0 , elasticIndicatorLimit: rand() % 2 == 0 )
if arc4random() % 2 == 0 {
pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
}
else {
pagerBehaviour = .Common(skipIntermediateViewControllers: rand() % 2 == 0)
pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
}
super.reloadPagerTabStripView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class ChildExampleViewController: UIViewController, IndicatorInfoProvider {
label.text = "XLPagerTabStrip"

view.addSubview(label)
view.backgroundColor = .whiteColor()
view.backgroundColor = .white

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

// MARK: - IndicatorInfoProvider

func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return itemInfo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi

override func viewDidLoad() {
super.viewDidLoad()
tableView.registerNib(UINib(nibName: "PostCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: cellIdentifier)
tableView.register(UINib(nibName: "PostCell", bundle: Bundle.main), forCellReuseIdentifier: cellIdentifier)
tableView.estimatedRowHeight = 60.0;
tableView.rowHeight = UITableViewAutomaticDimension
tableView.allowsSelection = false
Expand All @@ -51,24 +51,24 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi
}
}

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
}

// MARK: - UITableViewDataSource

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return DataProvider.sharedInstance.postsData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PostCell
let data = DataProvider.sharedInstance.postsData.objectAtIndex(indexPath.row) as!

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! PostCell
let data = DataProvider.sharedInstance.postsData.object(at: indexPath.row) as!
NSDictionary
cell.configureWithData(data)
if blackTheme {
Expand All @@ -79,7 +79,7 @@ class TableChildExampleViewController: UITableViewController, IndicatorInfoProvi

// MARK: - IndicatorInfoProvider

func indicatorInfoForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return itemInfo
}
}
Loading

0 comments on commit 794f085

Please sign in to comment.