From a5535d0d8693654d92797f41a61250df0c46009e Mon Sep 17 00:00:00 2001 From: hryk224 Date: Wed, 21 Sep 2016 19:34:59 +0900 Subject: [PATCH] Support swift3 --- Example/Example.xcodeproj/project.pbxproj | 53 ++++++++++------ Example/Example/AppDelegate.swift | 12 ++-- .../Base.lproj/LaunchScreen.storyboard | 11 ++-- Example/Example/Base.lproj/Main.storyboard | 12 ++-- Example/Example/ImageCollectionViewCell.swift | 2 +- Example/Example/ImageCollectionViewCell.xib | 14 ++--- Example/Example/MainViewController.swift | 16 ++--- Example/Example/Pattern1.storyboard | 22 ++++--- Example/Example/Pattern1ViewController.swift | 20 +++---- Example/Example/Pattern2.storyboard | 48 +++++++-------- Example/Example/Pattern2ViewController.swift | 52 +++++++--------- InfiniteCollectionView.podspec | 4 +- .../project.pbxproj | 16 ++++- .../InfiniteCollectionView.swift | 60 +++++++++---------- InfiniteCollectionView/Info.plist | 2 +- README.md | 10 ++-- 16 files changed, 179 insertions(+), 175 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index eaf2caf..34c577b 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -18,21 +18,21 @@ 935BD6E51CE26F0B00E5FDF7 /* Pattern1ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935BD6DE1CE26F0B00E5FDF7 /* Pattern1ViewController.swift */; }; 935BD6E61CE26F0B00E5FDF7 /* Pattern2.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 935BD6DF1CE26F0B00E5FDF7 /* Pattern2.storyboard */; }; 935BD6E71CE26F0B00E5FDF7 /* Pattern2ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935BD6E01CE26F0B00E5FDF7 /* Pattern2ViewController.swift */; }; - 935BD71D1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */; }; - 935BD71E1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + EDA05AD81D92901C00F7C2C5 /* InfiniteCollectionView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */; }; + EDA05AD91D92901C00F7C2C5 /* InfiniteCollectionView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 935BD71B1CE26FB600E5FDF7 /* PBXContainerItemProxy */ = { + EDA05AD61D92901900F7C2C5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */; + containerPortal = EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */; proxyType = 2; remoteGlobalIDString = 935BD70D1CE26F8E00E5FDF7; remoteInfo = InfiniteCollectionView; }; - 935BD71F1CE26FBF00E5FDF7 /* PBXContainerItemProxy */ = { + EDA05ADA1D92901C00F7C2C5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */; + containerPortal = EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */; proxyType = 1; remoteGlobalIDString = 935BD70C1CE26F8E00E5FDF7; remoteInfo = InfiniteCollectionView; @@ -46,7 +46,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 935BD71E1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Embed Frameworks */, + EDA05AD91D92901C00F7C2C5 /* InfiniteCollectionView.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -67,7 +67,7 @@ 935BD6DE1CE26F0B00E5FDF7 /* Pattern1ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pattern1ViewController.swift; sourceTree = ""; }; 935BD6DF1CE26F0B00E5FDF7 /* Pattern2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Pattern2.storyboard; sourceTree = ""; }; 935BD6E01CE26F0B00E5FDF7 /* Pattern2ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pattern2ViewController.swift; sourceTree = ""; }; - 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = InfiniteCollectionView.xcodeproj; path = ../InfiniteCollectionView.xcodeproj; sourceTree = ""; }; + EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = InfiniteCollectionView.xcodeproj; path = ../InfiniteCollectionView.xcodeproj; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -75,7 +75,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 935BD71D1CE26FBF00E5FDF7 /* InfiniteCollectionView.framework in Frameworks */, + EDA05AD81D92901C00F7C2C5 /* InfiniteCollectionView.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -85,9 +85,9 @@ 935BD6BC1CE26EB600E5FDF7 = { isa = PBXGroup; children = ( - 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */, 935BD6C71CE26EB600E5FDF7 /* Example */, 935BD6C61CE26EB600E5FDF7 /* Products */, + EDA05AD11D92901900F7C2C5 /* Frameworks */, ); sourceTree = ""; }; @@ -118,10 +118,18 @@ path = Example; sourceTree = ""; }; - 935BD7181CE26FB600E5FDF7 /* Products */ = { + EDA05AD11D92901900F7C2C5 /* Frameworks */ = { isa = PBXGroup; children = ( - 935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */, + EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */, + ); + name = Frameworks; + sourceTree = ""; + }; + EDA05AD31D92901900F7C2C5 /* Products */ = { + isa = PBXGroup; + children = ( + EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */, ); name = Products; sourceTree = ""; @@ -141,7 +149,7 @@ buildRules = ( ); dependencies = ( - 935BD7201CE26FBF00E5FDF7 /* PBXTargetDependency */, + EDA05ADB1D92901C00F7C2C5 /* PBXTargetDependency */, ); name = Example; productName = Example; @@ -160,6 +168,7 @@ TargetAttributes = { 935BD6C41CE26EB600E5FDF7 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; }; }; @@ -176,8 +185,8 @@ projectDirPath = ""; projectReferences = ( { - ProductGroup = 935BD7181CE26FB600E5FDF7 /* Products */; - ProjectRef = 935BD7171CE26FB600E5FDF7 /* InfiniteCollectionView.xcodeproj */; + ProductGroup = EDA05AD31D92901900F7C2C5 /* Products */; + ProjectRef = EDA05AD21D92901900F7C2C5 /* InfiniteCollectionView.xcodeproj */; }, ); projectRoot = ""; @@ -188,11 +197,11 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 935BD71C1CE26FB600E5FDF7 /* InfiniteCollectionView.framework */ = { + EDA05AD71D92901900F7C2C5 /* InfiniteCollectionView.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = InfiniteCollectionView.framework; - remoteRef = 935BD71B1CE26FB600E5FDF7 /* PBXContainerItemProxy */; + remoteRef = EDA05AD61D92901900F7C2C5 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -229,10 +238,10 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 935BD7201CE26FBF00E5FDF7 /* PBXTargetDependency */ = { + EDA05ADB1D92901C00F7C2C5 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = InfiniteCollectionView; - targetProxy = 935BD71F1CE26FBF00E5FDF7 /* PBXContainerItemProxy */; + targetProxy = EDA05ADA1D92901C00F7C2C5 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -342,22 +351,28 @@ 935BD6D81CE26EB600E5FDF7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Example/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.Example; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; 935BD6D91CE26EB600E5FDF7 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Example/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.Example; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 6a9d9dc..b017236 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -14,30 +14,30 @@ 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. 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:. } diff --git a/Example/Example/Base.lproj/LaunchScreen.storyboard b/Example/Example/Base.lproj/LaunchScreen.storyboard index 2e721e1..2e4cb45 100644 --- a/Example/Example/Base.lproj/LaunchScreen.storyboard +++ b/Example/Example/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,9 @@ - + - + + + @@ -13,10 +15,9 @@ - + - - + diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index ab53cef..064b822 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -30,15 +31,14 @@ - + - - + - + diff --git a/Example/Example/ImageCollectionViewCell.swift b/Example/Example/ImageCollectionViewCell.swift index fb3a10d..966464a 100644 --- a/Example/Example/ImageCollectionViewCell.swift +++ b/Example/Example/ImageCollectionViewCell.swift @@ -12,7 +12,7 @@ final class ImageCollectionViewCell: UICollectionViewCell { @IBOutlet weak var imageView: UIImageView! static let identifier = "ImageCollectionViewCell" static let nib = UINib(nibName: "ImageCollectionViewCell", bundle: nil) - func configure(dequeueIndexPath dequeueIndexPath: NSIndexPath) { + func configure(dequeueIndexPath: IndexPath) { let image = UIImage(named: String(dequeueIndexPath.item)) imageView.image = image setNeedsLayout() diff --git a/Example/Example/ImageCollectionViewCell.xib b/Example/Example/ImageCollectionViewCell.xib index d178cd4..13b109f 100644 --- a/Example/Example/ImageCollectionViewCell.xib +++ b/Example/Example/ImageCollectionViewCell.xib @@ -1,7 +1,9 @@ - + - + + + @@ -11,12 +13,10 @@ + - - - + - @@ -27,7 +27,7 @@ - + diff --git a/Example/Example/MainViewController.swift b/Example/Example/MainViewController.swift index d735715..24d55af 100644 --- a/Example/Example/MainViewController.swift +++ b/Example/Example/MainViewController.swift @@ -16,29 +16,29 @@ final class MainViewController: UIViewController { didSet { tableView.delegate = self tableView.dataSource = self - tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: identifier) + tableView.register(UITableViewCell.self, forCellReuseIdentifier: identifier) tableView.rowHeight = 100 tableView.estimatedRowHeight = 100 } } - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if let selectedIndexPath = tableView.indexPathForSelectedRow { - tableView.deselectRowAtIndexPath(selectedIndexPath, animated: true) + tableView.deselectRow(at: selectedIndexPath, animated: true) } } } extension MainViewController: UITableViewDelegate, UITableViewDataSource { - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return patterns.count } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier(identifier)! + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: identifier)! cell.textLabel?.text = patterns[indexPath.row] return cell } - func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row == 0 { let controller = Pattern1ViewController.createFromStoryboard() navigationController?.pushViewController(controller, animated: true) @@ -47,4 +47,4 @@ extension MainViewController: UITableViewDelegate, UITableViewDataSource { navigationController?.pushViewController(controller, animated: true) } } -} \ No newline at end of file +} diff --git a/Example/Example/Pattern1.storyboard b/Example/Example/Pattern1.storyboard index 6728e65..e748ad1 100644 --- a/Example/Example/Pattern1.storyboard +++ b/Example/Example/Pattern1.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -14,12 +15,11 @@ - + - - + @@ -29,22 +29,20 @@ - - + - - - + + - + @@ -66,7 +64,7 @@ - + diff --git a/Example/Example/Pattern1ViewController.swift b/Example/Example/Pattern1ViewController.swift index 05863b2..e0384b8 100644 --- a/Example/Example/Pattern1ViewController.swift +++ b/Example/Example/Pattern1ViewController.swift @@ -15,13 +15,13 @@ final class Pattern1ViewController: UIViewController { didSet { collectionView.infiniteDataSource = self collectionView.infiniteDelegate = self - collectionView.cellWidth = UIScreen.mainScreen().bounds.width - collectionView.registerNib(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier) + collectionView.cellWidth = UIScreen.main.bounds.width + collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier) } } @IBOutlet weak var layout: UICollectionViewFlowLayout! { didSet { - layout.itemSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height) + layout.itemSize = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) } } @IBOutlet weak var pageControl: UIPageControl! { @@ -37,17 +37,15 @@ final class Pattern1ViewController: UIViewController { // MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate extension Pattern1ViewController: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate { - func numberOfItems(collectionView: UICollectionView) -> Int { + public func number(ofItems collectionView: UICollectionView) -> Int { return items.count } - func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ImageCollectionViewCell.identifier, forIndexPath: dequeueIndexPath) as! ImageCollectionViewCell - cell.configure(dequeueIndexPath: indexPath) + func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell + cell.configure(dequeueIndexPath: usableIndexPath) return cell } - func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath) { - } - func didUpdatePageIndex(index: Int) { - pageControl.currentPage = index + func scrollView(_ scrollView: UIScrollView, pageIndex: Int) { + pageControl.currentPage = pageIndex } } diff --git a/Example/Example/Pattern2.storyboard b/Example/Example/Pattern2.storyboard index a1ea910..3ccbdf7 100644 --- a/Example/Example/Pattern2.storyboard +++ b/Example/Example/Pattern2.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -14,23 +15,21 @@ - + - - + - + - + - - + @@ -39,17 +38,14 @@ - + - + - - - + - @@ -57,7 +53,7 @@ - + @@ -65,19 +61,17 @@ - - + - - - + + @@ -100,15 +94,14 @@ - + - + - - + @@ -122,7 +115,6 @@ - @@ -142,7 +134,7 @@ - + @@ -156,7 +148,7 @@ - + diff --git a/Example/Example/Pattern2ViewController.swift b/Example/Example/Pattern2ViewController.swift index d6177ad..0715d8c 100644 --- a/Example/Example/Pattern2ViewController.swift +++ b/Example/Example/Pattern2ViewController.swift @@ -20,7 +20,7 @@ final class Pattern2ViewController: UIViewController { didSet { tableView.delegate = self tableView.dataSource = self - tableView.separatorStyle = .None + tableView.separatorStyle = .none } } } @@ -28,10 +28,10 @@ final class Pattern2ViewController: UIViewController { // MARK: - UITableViewDataSource, UITableViewDelegate extension Pattern2ViewController: UITableViewDataSource, UITableViewDelegate { - func numberOfSectionsInTableView(tableView: UITableView) -> Int { + func numberOfSections(in tableView: UITableView) -> Int { return 2 } - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { return 1 } else if section == 1 { @@ -39,18 +39,18 @@ extension Pattern2ViewController: UITableViewDataSource, UITableViewDelegate { } return 0 } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.section == 0 { - let cell = tableView.dequeueReusableCellWithIdentifier(InfiniteTableViewCell.identifier) as! InfiniteTableViewCell + let cell = tableView.dequeueReusableCell(withIdentifier: InfiniteTableViewCell.identifier) as! InfiniteTableViewCell return cell } else if indexPath.section == 1 { - let cell = tableView.dequeueReusableCellWithIdentifier(Infinite2TableViewCell.identifier) as! Infinite2TableViewCell + let cell = tableView.dequeueReusableCell(withIdentifier: Infinite2TableViewCell.identifier) as! Infinite2TableViewCell return cell } else { return UITableViewCell() } } - func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if indexPath.section == 0 { return 240 } else if indexPath.section == 1 { @@ -66,13 +66,13 @@ final class InfiniteTableViewCell: UITableViewCell { didSet { collectionView.infiniteDataSource = self collectionView.infiniteDelegate = self - collectionView.cellWidth = UIScreen.mainScreen().bounds.width - collectionView.registerNib(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier) + collectionView.cellWidth = UIScreen.main.bounds.width + collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier) } } @IBOutlet weak var layout: UICollectionViewFlowLayout! { didSet { - layout.itemSize = CGSize(width: UIScreen.mainScreen().bounds.width, height: 239) + layout.itemSize = CGSize(width: UIScreen.main.bounds.width, height: 239) } } @IBOutlet weak var pageControl: UIPageControl! { @@ -84,18 +84,16 @@ final class InfiniteTableViewCell: UITableViewCell { // MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate extension InfiniteTableViewCell: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate { - func numberOfItems(collectionView: UICollectionView) -> Int { + func number(ofItems collectionView: UICollectionView) -> Int { return 4 } - func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ImageCollectionViewCell.identifier, forIndexPath: dequeueIndexPath) as! ImageCollectionViewCell - cell.configure(dequeueIndexPath: indexPath) + func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell + cell.configure(dequeueIndexPath: usableIndexPath) return cell } - func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath) { - } - func didUpdatePageIndex(index: Int) { - pageControl.currentPage = index + func scrollView(_ scrollView: UIScrollView, pageIndex: Int) { + pageControl.currentPage = pageIndex } } @@ -106,27 +104,19 @@ final class Infinite2TableViewCell: UITableViewCell { collectionView.infiniteDataSource = self collectionView.infiniteDelegate = self collectionView.cellWidth = 100 - collectionView.registerNib(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier) + collectionView.register(ImageCollectionViewCell.nib, forCellWithReuseIdentifier: ImageCollectionViewCell.identifier) } } } // MARK: - InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate extension Infinite2TableViewCell: InfiniteCollectionViewDataSource, InfiniteCollectionViewDelegate { - func numberOfItems(collectionView: UICollectionView) -> Int { + func number(ofItems collectionView: UICollectionView) -> Int { return 10 } - func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ImageCollectionViewCell.identifier, forIndexPath: dequeueIndexPath) as! ImageCollectionViewCell - cell.configure(dequeueIndexPath: indexPath) + func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCollectionViewCell.identifier, for: dequeueIndexPath) as! ImageCollectionViewCell + cell.configure(dequeueIndexPath: usableIndexPath) return cell } } - - - - - - - - diff --git a/InfiniteCollectionView.podspec b/InfiniteCollectionView.podspec index 265c77a..afed61b 100644 --- a/InfiniteCollectionView.podspec +++ b/InfiniteCollectionView.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "InfiniteCollectionView" - s.version = "1.0.4" + s.version = "1.1.0" s.summary = "Infinite Scrolling Using UICollectionView." s.homepage = "https://github.com/hryk224/InfiniteCollectionView" s.screenshots = "https://github.com/hryk224/InfiniteCollectionView/wiki/images/sample1.gif" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "hyyk224" => "hryk224@gmail.com" } - s.platform = :ios, "8.0" + s.platform = :ios, "9.0" s.source = { :git => "https://github.com/hryk224/InfiniteCollectionView.git", :tag => "#{s.version}" } s.source_files = "InfiniteCollectionView/*.{h,swift}" s.frameworks = "UIKit" diff --git a/InfiniteCollectionView.xcodeproj/project.pbxproj b/InfiniteCollectionView.xcodeproj/project.pbxproj index 77cc4b6..f4c2fdb 100644 --- a/InfiniteCollectionView.xcodeproj/project.pbxproj +++ b/InfiniteCollectionView.xcodeproj/project.pbxproj @@ -94,11 +94,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "hiroyuki yoshida"; TargetAttributes = { 935BD70C1CE26F8E00E5FDF7 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; }; }; @@ -156,8 +157,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"; @@ -179,7 +182,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -201,8 +204,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"; @@ -218,9 +223,10 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -229,6 +235,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -241,6 +248,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -251,6 +259,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -262,6 +271,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.github.hryk224.InfiniteCollectionView; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/InfiniteCollectionView/InfiniteCollectionView.swift b/InfiniteCollectionView/InfiniteCollectionView.swift index 2b71cd1..41069f8 100644 --- a/InfiniteCollectionView/InfiniteCollectionView.swift +++ b/InfiniteCollectionView/InfiniteCollectionView.swift @@ -9,24 +9,24 @@ import UIKit public protocol InfiniteCollectionViewDataSource: class { - func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell - func numberOfItems(collectionView: UICollectionView) -> Int + func number(ofItems collectionView: UICollectionView) -> Int + func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell } @objc public protocol InfiniteCollectionViewDelegate: class { - optional func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath) - optional func didUpdatePageIndex(index: Int) + @objc optional func collectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath) + @objc optional func scrollView(_ scrollView: UIScrollView, pageIndex: Int) } -public class InfiniteCollectionView: UICollectionView { - private typealias Me = InfiniteCollectionView - private static let dummyCount: Int = 3 - private static let defaultIdentifier = "Cell" - public weak var infiniteDataSource: InfiniteCollectionViewDataSource? - public weak var infiniteDelegate: InfiniteCollectionViewDelegate? - public var cellWidth: CGFloat = UIScreen.mainScreen().bounds.width - private var indexOffset: Int = 0 - private var currentIndex: Int = 0 +open class InfiniteCollectionView: UICollectionView { + fileprivate typealias Me = InfiniteCollectionView + fileprivate static let dummyCount: Int = 3 + fileprivate static let defaultIdentifier = "Cell" + open weak var infiniteDataSource: InfiniteCollectionViewDataSource? + open weak var infiniteDelegate: InfiniteCollectionViewDelegate? + open var cellWidth: CGFloat = UIScreen.main.bounds.width + fileprivate var indexOffset: Int = 0 + fileprivate var currentIndex: Int = 0 required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) configure() @@ -42,10 +42,10 @@ private extension InfiniteCollectionView { func configure() { delegate = self dataSource = self - registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: Me.defaultIdentifier) + register(UICollectionViewCell.self, forCellWithReuseIdentifier: Me.defaultIdentifier) } - func centerIfNeeded(scrollView: UIScrollView) { + func centerIfNeeded(_ scrollView: UIScrollView) { let currentOffset = contentOffset let contentWidth = totalContentWidth() // Calculate the centre of content X position offset and the current distance from that centre point @@ -57,7 +57,7 @@ private extension InfiniteCollectionView { // Amount of cells to shift (whole number) - conditional statement due to nature of +ve or -ve cellcount let shiftCells = Int((cellcount > 0) ? floor(cellcount) : ceil(cellcount)) // Amount left over to correct for - let offsetCorrection = (abs(cellcount) % 1) * cellWidth + let offsetCorrection = (abs(cellcount).truncatingRemainder(dividingBy: 1)) * cellWidth // Scroll back to the centre of the view, offset by the correction to ensure it's not noticable if centerOffsetX > contentOffset.x { //left scrolling @@ -71,18 +71,18 @@ private extension InfiniteCollectionView { reloadData() } let centerPoint = CGPoint(x: scrollView.frame.size.width / 2 + scrollView.contentOffset.x, y: scrollView.frame.size.height / 2 + scrollView.contentOffset.y) - guard let indexPath = indexPathForItemAtPoint(centerPoint) else { return } - infiniteDelegate?.didUpdatePageIndex?(correctedIndex(indexPath.item - indexOffset)) + guard let indexPath = indexPathForItem(at: centerPoint) else { return } + infiniteDelegate?.scrollView?(scrollView, pageIndex: correctedIndex(indexPath.item - indexOffset)) } - func shiftContentArray(offset: Int) { + func shiftContentArray(_ offset: Int) { indexOffset += offset } func totalContentWidth() -> CGFloat { - let numberOfCells = infiniteDataSource?.numberOfItems(self) ?? 0 + let numberOfCells = infiniteDataSource?.number(ofItems: self) ?? 0 return CGFloat(numberOfCells) * cellWidth } - func correctedIndex(indexToCorrect: Int) -> Int { - if let numberOfItems = infiniteDataSource?.numberOfItems(self) { + func correctedIndex(_ indexToCorrect: Int) -> Int { + if let numberOfItems = infiniteDataSource?.number(ofItems: self) { if numberOfItems > indexToCorrect && indexToCorrect >= 0 { return indexToCorrect } else { @@ -99,15 +99,15 @@ private extension InfiniteCollectionView { // MARK: - UICollectionViewDataSource extension InfiniteCollectionView: UICollectionViewDataSource { - public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - let numberOfItems = infiniteDataSource?.numberOfItems(self) ?? 0 + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + let numberOfItems = infiniteDataSource?.number(ofItems: collectionView) ?? 0 return Me.dummyCount * numberOfItems } - public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { var maybeCell: UICollectionViewCell! - maybeCell = infiniteDataSource?.cellForItemAtIndexPath(self, dequeueIndexPath: indexPath, indexPath: NSIndexPath(forRow: correctedIndex(indexPath.item - indexOffset), inSection: 0)) + maybeCell = infiniteDataSource?.collectionView(collectionView, dequeueForItemAt: indexPath, cellForItemAt: IndexPath(row: correctedIndex(indexPath.item - indexOffset), section: 0)) if maybeCell == nil { - maybeCell = collectionView.dequeueReusableCellWithReuseIdentifier(Me.defaultIdentifier, forIndexPath: indexPath) + maybeCell = collectionView.dequeueReusableCell(withReuseIdentifier: Me.defaultIdentifier, for: indexPath) } return maybeCell } @@ -115,10 +115,10 @@ extension InfiniteCollectionView: UICollectionViewDataSource { // MARK: - UICollectionViewDelegate extension InfiniteCollectionView: UICollectionViewDelegate { - public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { - infiniteDelegate?.didSelectCellAtIndexPath?(self, indexPath: NSIndexPath(forRow: correctedIndex(indexPath.item - indexOffset), inSection: 0)) + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + infiniteDelegate?.collectionView?(collectionView, didSelectItemAt: IndexPath(row: correctedIndex(indexPath.item - indexOffset), section: 0)) } - public func scrollViewDidScroll(scrollView: UIScrollView) { + public func scrollViewDidScroll(_ scrollView: UIScrollView) { centerIfNeeded(scrollView) } } diff --git a/InfiniteCollectionView/Info.plist b/InfiniteCollectionView/Info.plist index e52b996..09bc972 100644 --- a/InfiniteCollectionView/Info.plist +++ b/InfiniteCollectionView/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.4 + 1.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/README.md b/README.md index d700d77..f495e44 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Infinite horizontal scrolling using `UICollectionView` [![CocoaPods Compatible](http://img.shields.io/cocoapods/v/InfiniteCollectionView.svg?style=flat)](http://cocoadocs.org/docsets/InfiniteCollectionView) -[![Swift 2.2](https://img.shields.io/badge/Swift-2.2-orange.svg?style=flat)](https://developer.apple.com/swift/) +[![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/) @@ -48,12 +48,12 @@ collectionView.cellWidth = XXX ```Swift // protocol -func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, indexPath: NSIndexPath) -> UICollectionViewCell -func numberOfItems(collectionView: UICollectionView) -> Int +func number(ofItems collectionView: UICollectionView) -> Int +func collectionView(_ collectionView: UICollectionView, dequeueForItemAt dequeueIndexPath: IndexPath, cellForItemAt usableIndexPath: IndexPath) -> UICollectionViewCell // optional -func didSelectCellAtIndexPath(collectionView: UICollectionView, indexPath: NSIndexPath) -func didUpdatePageIndex(index: Int) +func collectionView(_ collectionView: UICollectionView, didSelectItemAt usableIndexPath: IndexPath) +func scrollView(_ scrollView: UIScrollView, pageIndex: Int) ``` ## Photos from