From 6a8975f9a8b5f76b37641bee6647cac3773bda1e Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Fri, 19 Aug 2016 21:17:02 -0700 Subject: [PATCH 1/4] updated to swift 3.0 --- ScrollPager.xcodeproj/project.pbxproj | 18 +++++- ScrollPager/AppDelegate.swift | 12 ++-- ScrollPager/Source/ScrollPager.swift | 80 +++++++++++++------------ ScrollPager/ViewController.swift | 20 +++---- ScrollPagerTests/ScrollPagerTests.swift | 2 +- 5 files changed, 75 insertions(+), 57 deletions(-) diff --git a/ScrollPager.xcodeproj/project.pbxproj b/ScrollPager.xcodeproj/project.pbxproj index 2478dda..384c7f3 100644 --- a/ScrollPager.xcodeproj/project.pbxproj +++ b/ScrollPager.xcodeproj/project.pbxproj @@ -169,14 +169,17 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Aryan Ghassemi"; TargetAttributes = { 15F9717A1A9A86E400169B7E = { CreatedOnToolsVersion = 6.1.1; + DevelopmentTeam = 24FGDP9KJW; + LastSwiftMigration = 0800; }; 15F9718F1A9A86E400169B7E = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 0800; TestTargetID = 15F9717A1A9A86E400169B7E; }; }; @@ -282,8 +285,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"; @@ -292,6 +297,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -326,8 +332,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"; @@ -335,6 +343,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -344,6 +353,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -353,10 +363,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 24FGDP9KJW; INFOPLIST_FILE = ScrollPager/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aryaxt.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -364,10 +376,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 24FGDP9KJW; INFOPLIST_FILE = ScrollPager/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aryaxt.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -387,6 +401,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aryaxt.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ScrollPager.app/ScrollPager"; }; name = Debug; @@ -403,6 +418,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aryaxt.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ScrollPager.app/ScrollPager"; }; name = Release; diff --git a/ScrollPager/AppDelegate.swift b/ScrollPager/AppDelegate.swift index 5582f8d..1dc14c3 100644 --- a/ScrollPager/AppDelegate.swift +++ b/ScrollPager/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + private 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) { + private 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) { + private 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) { + private 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) { + private func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/ScrollPager/Source/ScrollPager.swift b/ScrollPager/Source/ScrollPager.swift index 110f7d3..e011080 100644 --- a/ScrollPager/Source/ScrollPager.swift +++ b/ScrollPager/Source/ScrollPager.swift @@ -29,7 +29,7 @@ import UIKit @objc public protocol ScrollPagerDelegate: NSObjectProtocol { - optional func scrollPager(scrollPager: ScrollPager, changedIndex: Int) + @objc optional func scrollPager(scrollPager: ScrollPager, changedIndex: Int) } @IBDesignable public class ScrollPager: UIView, UIScrollViewDelegate{ @@ -44,28 +44,28 @@ import UIKit @IBOutlet public var scrollView: UIScrollView? { didSet { scrollView?.delegate = self - scrollView?.pagingEnabled = true + scrollView?.isPagingEnabled = true scrollView?.showsHorizontalScrollIndicator = false } } - @IBInspectable public var textColor: UIColor = UIColor.lightGrayColor() { + @IBInspectable public var textColor: UIColor = UIColor.lightGray { didSet { redrawComponents() } } - @IBInspectable public var selectedTextColor: UIColor = UIColor.darkGrayColor() { + @IBInspectable public var selectedTextColor: UIColor = UIColor.darkGray { didSet { redrawComponents() } } - @IBInspectable public var font: UIFont = UIFont.systemFontOfSize(13) { + @IBInspectable public var font: UIFont = UIFont.systemFont(ofSize: 13) { didSet { redrawComponents() } } - @IBInspectable public var selectedFont: UIFont = UIFont.boldSystemFontOfSize(13) { + @IBInspectable public var selectedFont: UIFont = UIFont.boldSystemFont(ofSize: 13) { didSet { redrawComponents() } } - @IBInspectable public var indicatorColor: UIColor = UIColor.blackColor() { + @IBInspectable public var indicatorColor: UIColor = UIColor.black { didSet { indicatorView.backgroundColor = indicatorColor } } @@ -78,7 +78,7 @@ import UIKit } @IBInspectable public var borderColor: UIColor? { - didSet { self.layer.borderColor = borderColor?.CGColor } + didSet { self.layer.borderColor = borderColor?.cgColor } } @IBInspectable public var borderWidth: CGFloat = 0 { @@ -118,32 +118,32 @@ import UIKit public func addSegmentsWithTitlesAndViews(segments: [(title: String, view: UIView)]) { - addButtons(segments.map { $0.title }) - addViews(segments.map { $0.view }) + addButtons(titleOrImages: segments.map { $0.title as AnyObject }) + addViews(segmentViews: segments.map { $0.view }) redrawComponents() } public func addSegmentsWithImagesAndViews(segments: [(image: UIImage, view: UIView)]) { - addButtons(segments.map { $0.image }) - addViews(segments.map { $0.view }) + addButtons(titleOrImages: segments.map { $0.image }) + addViews(segmentViews: segments.map { $0.view }) redrawComponents() } public func addSegmentsWithTitles(segmentTitles: [String]) { - addButtons(segmentTitles) + addButtons(titleOrImages: segmentTitles as [AnyObject]) redrawComponents() } public func addSegmentsWithImages(segmentImages: [UIImage]) { - addButtons(segmentImages) + addButtons(titleOrImages: segmentImages) redrawComponents() } public func setSelectedIndex(index: Int, animated: Bool) { - setSelectedIndex(index, animated: animated, moveScrollView: true) + setSelectedIndex(index: index, animated: animated, moveScrollView: true) } // MARK: - Private - @@ -151,7 +151,7 @@ import UIKit private func setSelectedIndex(index: Int, animated: Bool, moveScrollView: Bool) { selectedIndex = index - moveToIndex(index, animated: animated, moveScrollView: moveScrollView) + moveToIndex(index: index, animated: animated, moveScrollView: moveScrollView) } private func addViews(segmentViews: [UIView]) { @@ -173,19 +173,19 @@ import UIKit button.removeFromSuperview() } - buttons.removeAll(keepCapacity: true) + buttons.removeAll() for i in 0.. 0 { - moveToIndex(selectedIndex, animated: false, moveScrollView: false) + moveToIndex(index: selectedIndex, animated: false, moveScrollView: false) } if let scrollView = scrollView { - scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * CGFloat(buttons.count), scrollView.frame.size.height) + scrollView.contentSize = CGSize(width: scrollView.frame.size.width * CGFloat(buttons.count), height: scrollView.frame.size.height) for i in 0.. 0.5 { + if page.truncatingRemainder(dividingBy: 1) > 0.5 { page = page + CGFloat(1) } if Int(page) != selectedIndex { - setSelectedIndex(Int(page), animated: true, moveScrollView: false) - delegate?.scrollPager?(self, changedIndex: Int(page)) + setSelectedIndex(index: Int(page), animated: true, moveScrollView: false) + delegate?.scrollPager?(scrollPager: self, changedIndex: Int(page)) } } } diff --git a/ScrollPager/ViewController.swift b/ScrollPager/ViewController.swift index d3566f4..910c006 100644 --- a/ScrollPager/ViewController.swift +++ b/ScrollPager/ViewController.swift @@ -17,34 +17,34 @@ class ViewController: UIViewController, ScrollPagerDelegate { super.viewDidLoad() let firstView = UILabel() - firstView.backgroundColor = UIColor.whiteColor() + firstView.backgroundColor = UIColor.white firstView.text = "first View" - firstView.textAlignment = .Center + firstView.textAlignment = .center let secondView = UILabel() - secondView.backgroundColor = UIColor.whiteColor() + secondView.backgroundColor = UIColor.white secondView.text = "second view" - secondView.textAlignment = .Center + secondView.textAlignment = .center let thirdView = UILabel() - thirdView.backgroundColor = UIColor.whiteColor() + thirdView.backgroundColor = UIColor.white thirdView.text = "third view" - thirdView.textAlignment = .Center + thirdView.textAlignment = .center let fourthView = UILabel() - fourthView.backgroundColor = UIColor.whiteColor() + fourthView.backgroundColor = UIColor.white fourthView.text = "fourth view" - fourthView.textAlignment = .Center + fourthView.textAlignment = .center scrollPager.delegate = self - scrollPager.addSegmentsWithTitlesAndViews([ + scrollPager.addSegmentsWithTitlesAndViews(segments: [ ("Home", firstView), ("Public Feed", secondView), ("Profile", thirdView), ("One More", fourthView) ]) - secondScrollPager.addSegmentsWithImages([ + secondScrollPager.addSegmentsWithImages(segmentImages: [ UIImage(named: "envelope")!, UIImage(named: "home")!, UIImage(named: "like")!, diff --git a/ScrollPagerTests/ScrollPagerTests.swift b/ScrollPagerTests/ScrollPagerTests.swift index a81404f..09216a1 100644 --- a/ScrollPagerTests/ScrollPagerTests.swift +++ b/ScrollPagerTests/ScrollPagerTests.swift @@ -28,7 +28,7 @@ class ScrollPagerTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock() { + self.measure() { // Put the code you want to measure the time of here. } } From c6b45413d52f8a86f41b0ba90ef60f5c7159b3b7 Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Fri, 19 Aug 2016 21:18:53 -0700 Subject: [PATCH 2/4] updated pod file --- ScrollPager.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ScrollPager.podspec b/ScrollPager.podspec index 065d37f..d51e762 100644 --- a/ScrollPager.podspec +++ b/ScrollPager.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ScrollPager' - s.version = '0.7' + s.version = '0.8' s.summary = 'A fully featured scroll pager similar to the one in flipboard, fully configurable through storyboard' s.homepage = 'https://github.com/aryaxt/ScrollPager' s.license = { @@ -8,7 +8,7 @@ Pod::Spec.new do |s| :file => 'License.txt' } s.author = {'Aryan Ghassemi' => 'https://github.com/aryaxt/ScrollPager'} - s.source = {:git => 'https://github.com/aryaxt/ScrollPager.git', :tag => '0.7'} + s.source = {:git => 'https://github.com/aryaxt/ScrollPager.git', :tag => '0.8'} s.platform = :ios, '8.0' s.source_files = 'ScrollPager/Source/*.{swift}' s.framework = 'Foundation', 'UIKit' From bd222c04110ef165929b3a5e2990a07397706ab4 Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Fri, 19 Aug 2016 21:21:48 -0700 Subject: [PATCH 3/4] added travis file --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0baaec9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: objective-c +osx_image: xcode8 + +script: +- xcodebuild -project ScrollPager.xcodeproj -scheme ScrollPagerTests -destination 'platform=iOS Simulator,name=iPhone 6' test From 3e7332a088db05b255883f0abe063bb0488163aa Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Fri, 19 Aug 2016 21:24:36 -0700 Subject: [PATCH 4/4] added test scheme --- .../xcshareddata/ScrollPager.xccheckout | 41 +++++++ .../xcschemes/ScrollPager.xcscheme | 115 ++++++++++++++++++ .../xcschemes/ScrollPagerTests.xcscheme | 56 +++++++++ 3 files changed, 212 insertions(+) create mode 100644 ScrollPager.xcodeproj/project.xcworkspace/xcshareddata/ScrollPager.xccheckout create mode 100644 ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPager.xcscheme create mode 100644 ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPagerTests.xcscheme diff --git a/ScrollPager.xcodeproj/project.xcworkspace/xcshareddata/ScrollPager.xccheckout b/ScrollPager.xcodeproj/project.xcworkspace/xcshareddata/ScrollPager.xccheckout new file mode 100644 index 0000000..d6680cd --- /dev/null +++ b/ScrollPager.xcodeproj/project.xcworkspace/xcshareddata/ScrollPager.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + FE30291C-AA8B-4552-A6D0-DEA9E5E44351 + IDESourceControlProjectName + ScrollPager + IDESourceControlProjectOriginsDictionary + + 203B8E4269EA117004AE3A2A717AF64DE226A9BC + https://github.com/aryaxt/ScrollPager.git + + IDESourceControlProjectPath + ScrollPager.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + 203B8E4269EA117004AE3A2A717AF64DE226A9BC + ../.. + + IDESourceControlProjectURL + https://github.com/aryaxt/ScrollPager.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + 203B8E4269EA117004AE3A2A717AF64DE226A9BC + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + 203B8E4269EA117004AE3A2A717AF64DE226A9BC + IDESourceControlWCCName + ScrollPager + + + + diff --git a/ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPager.xcscheme b/ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPager.xcscheme new file mode 100644 index 0000000..19cd6ca --- /dev/null +++ b/ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPager.xcscheme @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPagerTests.xcscheme b/ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPagerTests.xcscheme new file mode 100644 index 0000000..9831c8d --- /dev/null +++ b/ScrollPager.xcodeproj/xcshareddata/xcschemes/ScrollPagerTests.xcscheme @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + +