diff --git a/Example/HorizontalFloatingHeaderLayout.xcodeproj/project.pbxproj b/Example/HorizontalFloatingHeaderLayout.xcodeproj/project.pbxproj index 8912185..e69e261 100644 --- a/Example/HorizontalFloatingHeaderLayout.xcodeproj/project.pbxproj +++ b/Example/HorizontalFloatingHeaderLayout.xcodeproj/project.pbxproj @@ -229,14 +229,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0630; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + LastSwiftMigration = 0800; }; 607FACE41AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + LastSwiftMigration = 0800; TestTargetID = 607FACCF1AFB9204008FA782; }; }; @@ -435,14 +437,17 @@ 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"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -479,8 +484,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"; @@ -499,6 +506,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -507,12 +515,15 @@ isa = XCBuildConfiguration; baseConfigurationReference = 58449959429EE3539208DF6B /* Pods-HorizontalFloatingHeaderLayout_Example.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; INFOPLIST_FILE = HorizontalFloatingHeaderLayout/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -520,12 +531,15 @@ isa = XCBuildConfiguration; baseConfigurationReference = 67F9EB524DB6328929E96233 /* Pods-HorizontalFloatingHeaderLayout_Example.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; INFOPLIST_FILE = HorizontalFloatingHeaderLayout/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -533,6 +547,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = E3C97DD00B43E0D478EC7B61 /* Pods-HorizontalFloatingHeaderLayout_Tests.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -544,7 +559,9 @@ ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HorizontalFloatingHeaderLayout_Example.app/HorizontalFloatingHeaderLayout_Example"; }; name = Debug; @@ -553,6 +570,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 412C2F88DECB4D9C931B2303 /* Pods-HorizontalFloatingHeaderLayout_Tests.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -560,7 +578,9 @@ ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HorizontalFloatingHeaderLayout_Example.app/HorizontalFloatingHeaderLayout_Example"; }; name = Release; diff --git a/Example/HorizontalFloatingHeaderLayout.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout-Example.xcscheme b/Example/HorizontalFloatingHeaderLayout.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout-Example.xcscheme index 5de231b..8282d8e 100644 --- a/Example/HorizontalFloatingHeaderLayout.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout-Example.xcscheme +++ b/Example/HorizontalFloatingHeaderLayout.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout-Example.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -62,15 +62,18 @@ ReferencedContainer = "container:HorizontalFloatingHeaderLayout.xcodeproj"> + + @@ -86,10 +89,10 @@ diff --git a/Example/HorizontalFloatingHeaderLayout/AppDelegate.swift b/Example/HorizontalFloatingHeaderLayout/AppDelegate.swift index da589b4..12506a9 100644 --- a/Example/HorizontalFloatingHeaderLayout/AppDelegate.swift +++ b/Example/HorizontalFloatingHeaderLayout/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/HorizontalFloatingHeaderLayout/CollectionViewController.swift b/Example/HorizontalFloatingHeaderLayout/CollectionViewController.swift index fac7cd4..a0a06c2 100644 --- a/Example/HorizontalFloatingHeaderLayout/CollectionViewController.swift +++ b/Example/HorizontalFloatingHeaderLayout/CollectionViewController.swift @@ -9,7 +9,7 @@ import UIKit import HorizontalFloatingHeaderLayout -class CollectionViewController: UICollectionViewController,HorizontalFloatingHeaderLayoutDelegate { +class CollectionViewController: UICollectionViewController, HorizontalFloatingHeaderLayoutDelegate { //MARK: - Configure methods override func viewDidLoad() { @@ -17,14 +17,14 @@ class CollectionViewController: UICollectionViewController,HorizontalFloatingHea configure() } - private func configure(){ + fileprivate func configure(){ func configureCollectionView(){ collectionView?.contentInset = UIEdgeInsetsMake(8, 8, 8, 8) } func configureHeaderCell(){ let headerNib = UINib(nibName: "HeaderView",bundle: nil) - collectionView?.registerNib(headerNib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerView") + collectionView?.register(headerNib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "headerView") } // @@ -35,50 +35,50 @@ class CollectionViewController: UICollectionViewController,HorizontalFloatingHea // MARK: - UICollectionView methods //MARK: Datasource //Number of Sections - override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + override func numberOfSections(in collectionView: UICollectionView) -> Int { return 6 } //Number of Items - override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 34 } //Cells - override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) return cell } //Headers - override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { - let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "headerView", forIndexPath: indexPath) + override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { + let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerView", for: indexPath) return header } //MARK: Delegate (HorizontalFloatingHeaderDelegate) //Item Size - func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderItemSizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { - return CGSizeMake(48, 48) + func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderItemSizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { + return CGSize(width: 48, height: 48) } //Header Size - func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderSizeForSectionAtIndex section: Int) -> CGSize { - return CGSizeMake(160, 30) + func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderSizeForSectionAtIndex section: Int) -> CGSize { + return CGSize(width: 160, height: 30) } //Item Spacing - func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderItemSpacingForSectionAtIndex section: Int) -> CGFloat { + func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderItemSpacingForSectionAtIndex section: Int) -> CGFloat { return 8.0 } //Line Spacing - func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderColumnSpacingForSectionAtIndex section: Int) -> CGFloat { + func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderColumnSpacingForSectionAtIndex section: Int) -> CGFloat { return 8.0 } //Section Insets - func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderSectionInsetForSectionAtIndex section: Int) -> UIEdgeInsets { + func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderSectionInsetForSectionAtIndex section: Int) -> UIEdgeInsets { switch section{ case 0: return UIEdgeInsetsMake(8, 0, 0, 0) diff --git a/Example/HorizontalFloatingHeaderLayout/Info.plist b/Example/HorizontalFloatingHeaderLayout/Info.plist index f926ce4..6905cc6 100644 --- a/Example/HorizontalFloatingHeaderLayout/Info.plist +++ b/Example/HorizontalFloatingHeaderLayout/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index bfa96f8..04ff188 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -356,6 +356,20 @@ attributes = { LastSwiftUpdateCheck = 0720; LastUpgradeCheck = 0700; + TargetAttributes = { + 388B9CA3C57E3DE86E22A74D6A73C9C6 = { + LastSwiftMigration = 0800; + }; + 4E6FBC8B4CEC38207C993D444596A966 = { + LastSwiftMigration = 0800; + }; + 533E1B0BC8CC3FF39B28D105D8182883 = { + LastSwiftMigration = 0800; + }; + 7C2B7E3B51D4172EFDC2A12AE17B9C04 = { + LastSwiftMigration = 0800; + }; + }; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -460,6 +474,7 @@ PRODUCT_NAME = HorizontalFloatingHeaderLayout; SDKROOT = iphoneos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; WRAPPER_EXTENSION = bundle; }; name = Release; @@ -522,6 +537,7 @@ PRODUCT_NAME = Pods_HorizontalFloatingHeaderLayout_Example; SDKROOT = iphoneos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -552,6 +568,7 @@ PRODUCT_NAME = Pods_HorizontalFloatingHeaderLayout_Tests; SDKROOT = iphoneos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -566,6 +583,7 @@ PRODUCT_NAME = HorizontalFloatingHeaderLayout; SDKROOT = iphoneos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; WRAPPER_EXTENSION = bundle; }; name = Debug; @@ -634,6 +652,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -663,6 +682,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -691,6 +711,7 @@ PRODUCT_NAME = HorizontalFloatingHeaderLayout; SDKROOT = iphoneos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -722,6 +743,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout.xcscheme b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout.xcscheme index 751db39..f01c86d 100644 --- a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout.xcscheme +++ b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/HorizontalFloatingHeaderLayout.xcscheme @@ -1,36 +1,39 @@ + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + BuildableIdentifier = "primary" + BlueprintIdentifier = "388B9CA3C57E3DE86E22A74D6A73C9C6" + BuildableName = "HorizontalFloatingHeaderLayout.framework" + BlueprintName = "HorizontalFloatingHeaderLayout" + ReferencedContainer = "container:Pods.xcodeproj"> + shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + debugDocumentVersioning = "YES"> diff --git a/Example/Tests/Info.plist b/Example/Tests/Info.plist index ee0a311..ba72822 100644 --- a/Example/Tests/Info.plist +++ b/Example/Tests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - org.cocoapods.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift index e4f8177..7903a09 100644 --- a/Example/Tests/Tests.swift +++ b/Example/Tests/Tests.swift @@ -21,7 +21,7 @@ class Tests: 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. } } diff --git a/Pod/Classes/HorizontalFloatingHeaderLayout.swift b/Pod/Classes/HorizontalFloatingHeaderLayout.swift index 6acb758..9fe7c19 100644 --- a/Pod/Classes/HorizontalFloatingHeaderLayout.swift +++ b/Pod/Classes/HorizontalFloatingHeaderLayout.swift @@ -10,45 +10,45 @@ import UIKit @objc public protocol HorizontalFloatingHeaderLayoutDelegate{ //Item size - func collectionView(collectionView: UICollectionView,horizontalFloatingHeaderItemSizeForItemAtIndexPath indexPath:NSIndexPath) -> CGSize + func collectionView(_ collectionView: UICollectionView,horizontalFloatingHeaderItemSizeForItemAtIndexPath indexPath:IndexPath) -> CGSize //Header size - func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderSizeForSectionAtIndex section: Int) -> CGSize + func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderSizeForSectionAtIndex section: Int) -> CGSize //Section Inset - optional func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderSectionInsetForSectionAtIndex section: Int) -> UIEdgeInsets + @objc optional func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderSectionInsetForSectionAtIndex section: Int) -> UIEdgeInsets //Item Spacing - optional func collectionView(collectionView: UICollectionView, horizontalFloatingHeaderItemSpacingForSectionAtIndex section: Int) -> CGFloat + @objc optional func collectionView(_ collectionView: UICollectionView, horizontalFloatingHeaderItemSpacingForSectionAtIndex section: Int) -> CGFloat //Line Spacing - optional func collectionView(collectionView: UICollectionView,horizontalFloatingHeaderColumnSpacingForSectionAtIndex section: Int) -> CGFloat + @objc optional func collectionView(_ collectionView: UICollectionView,horizontalFloatingHeaderColumnSpacingForSectionAtIndex section: Int) -> CGFloat } -public class HorizontalFloatingHeaderLayout: UICollectionViewLayout { +open class HorizontalFloatingHeaderLayout: UICollectionViewLayout { //MARK: - Properties //MARK: Headers properties //Variables - var sectionHeadersAttributes: [NSIndexPath:UICollectionViewLayoutAttributes]{ + var sectionHeadersAttributes: [IndexPath:UICollectionViewLayoutAttributes]{ get{ return getSectionHeadersAttributes() } } //MARK: Items properties //Variables - var itemsAttributes = [NSIndexPath:UICollectionViewLayoutAttributes]() + var itemsAttributes = [IndexPath:UICollectionViewLayoutAttributes]() //PrepareItemsAtributes only var currentMinX:CGFloat = 0 var currentMinY:CGFloat = 0 var currentMaxX:CGFloat = 0 //MARK: - PrepareForLayout methods - public override func prepareLayout() { + open override func prepare() { prepareItemsAttributes() } //Items - private func prepareItemsAttributes(){ + fileprivate func prepareItemsAttributes(){ func resetAttributes(){ itemsAttributes.removeAll() currentMinX = 0 @@ -64,17 +64,17 @@ public class HorizontalFloatingHeaderLayout: UICollectionViewLayout { currentMaxX = 0.0 } - func itemAttribute(atIndexPath indexPath:NSIndexPath)->UICollectionViewLayoutAttributes{ + func itemAttribute(atIndexPath indexPath:IndexPath)->UICollectionViewLayoutAttributes{ //Applying corrected layout - func newLineOrigin(size size:CGSize)->CGPoint{ - var origin = CGPointZero - origin.x = currentMaxX + columnSpacing(forSection: indexPath.section) - origin.y = inset(ForSection: indexPath.section).top + headerSize(forSection: indexPath.section).height + func newLineOrigin(size:CGSize)->CGPoint{ + var origin = CGPoint.zero + origin.x = currentMaxX + columnSpacing(forSection: (indexPath as NSIndexPath).section) + origin.y = inset(ForSection: (indexPath as NSIndexPath).section).top + headerSize(forSection: (indexPath as NSIndexPath).section).height return origin } - func sameLineOrigin(size size:CGSize)->CGPoint{ - var origin = CGPointZero + func sameLineOrigin(size:CGSize)->CGPoint{ + var origin = CGPoint.zero origin.x = currentMinX origin.y = currentMinY return origin @@ -83,20 +83,20 @@ public class HorizontalFloatingHeaderLayout: UICollectionViewLayout { func updateVariables(itemFrame frame:CGRect){ currentMaxX = max(currentMaxX,frame.maxX) currentMinX = frame.minX - currentMinY = frame.maxY + itemSpacing(forSection: indexPath.section) + currentMinY = frame.maxY + itemSpacing(forSection: (indexPath as NSIndexPath).section) } // let size = itemSize(ForIndexPath: indexPath) let newMaxY = currentMinY + size.height let origin:CGPoint - if newMaxY > availableHeight(atSection: indexPath.section){ + if newMaxY > availableHeight(atSection: (indexPath as NSIndexPath).section){ origin = newLineOrigin(size: size) }else{ origin = sameLineOrigin(size: size) } - let frame = CGRectMake(origin.x, origin.y, size.width, size.height) - let attribute = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath) + let frame = CGRect(x: origin.x, y: origin.y, width: size.width, height: size.height) + let attribute = UICollectionViewLayoutAttributes(forCellWith: indexPath) attribute.frame = frame updateVariables(itemFrame: frame) return attribute @@ -104,12 +104,12 @@ public class HorizontalFloatingHeaderLayout: UICollectionViewLayout { // resetAttributes() - let sectionCount = collectionView!.numberOfSections() - for var section=0;section [UICollectionViewLayoutAttributes]? { - func attributes(attributes:[NSIndexPath:UICollectionViewLayoutAttributes],containedIn rect:CGRect) -> [UICollectionViewLayoutAttributes]{ + override open func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + func attributes(_ attributes:[IndexPath:UICollectionViewLayoutAttributes],containedIn rect:CGRect) -> [UICollectionViewLayoutAttributes]{ var finalAttributes = [UICollectionViewLayoutAttributes]() for (_,attribute) in attributes{ if rect.intersects(attribute.frame){ @@ -136,33 +136,33 @@ public class HorizontalFloatingHeaderLayout: UICollectionViewLayout { } //MARK: - ContentSize methods - override public func collectionViewContentSize() -> CGSize { + override open var collectionViewContentSize : CGSize { func lastItemMaxX()->CGFloat{ - let lastSection = collectionView!.numberOfSections() - 1 - let lastIndexInSection = collectionView!.numberOfItemsInSection(lastSection) - 1 - if let lastItemAttributes = layoutAttributesForItemAtIndexPath(NSIndexPath(forRow: lastIndexInSection, inSection: lastSection)){ + let lastSection = collectionView!.numberOfSections - 1 + let lastIndexInSection = collectionView!.numberOfItems(inSection: lastSection) - 1 + if let lastItemAttributes = layoutAttributesForItem(at: IndexPath(row: lastIndexInSection, section: lastSection)){ return lastItemAttributes.frame.maxX }else{ return 0 } } // - let lastSection = collectionView!.numberOfSections() - 1 + let lastSection = collectionView!.numberOfSections - 1 let contentWidth = lastItemMaxX() + inset(ForSection: lastSection).right let contentHeight = collectionView!.bounds.height - collectionView!.contentInset.top - collectionView!.contentInset.bottom - return CGSizeMake(contentWidth, contentHeight) + return CGSize(width: contentWidth, height: contentHeight) } //MARK: - LayoutAttributes methods //MARK: For ItemAtIndexPath - override public func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { - let fromIndexPath = NSIndexPath(forRow: indexPath.row, inSection: indexPath.section) + override open func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + let fromIndexPath = IndexPath(row: (indexPath as NSIndexPath).row, section: (indexPath as NSIndexPath).section) return itemsAttributes[fromIndexPath] } //MARK: For SupplementaryViewOfKind - override public func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { + override open func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { if elementKind == UICollectionElementKindSectionHeader{ - let fromIndexPath = NSIndexPath(forRow: indexPath.row, inSection: indexPath.section) + let fromIndexPath = IndexPath(row: (indexPath as NSIndexPath).row, section: (indexPath as NSIndexPath).section) return sectionHeadersAttributes[fromIndexPath] }else{ return nil @@ -171,101 +171,101 @@ public class HorizontalFloatingHeaderLayout: UICollectionViewLayout { //MARK: - Utility methods //MARK: SectionHeaders Attributes methods - private func getSectionHeadersAttributes()->[NSIndexPath:UICollectionViewLayoutAttributes]{ - func attributeForSectionHeader(atIndexPath indexPath:NSIndexPath) -> UICollectionViewLayoutAttributes{ + fileprivate func getSectionHeadersAttributes()->[IndexPath:UICollectionViewLayoutAttributes]{ + func attributeForSectionHeader(atIndexPath indexPath:IndexPath) -> UICollectionViewLayoutAttributes{ func size()->CGSize{ - return headerSize(forSection: indexPath.section) + return headerSize(forSection: (indexPath as NSIndexPath).section) } // func position()->CGPoint{ - if let itemsCount = collectionView?.numberOfItemsInSection(indexPath.section), - let firstItemAttributes = layoutAttributesForItemAtIndexPath(indexPath), - let lastItemAttributes = layoutAttributesForItemAtIndexPath(NSIndexPath(forRow: itemsCount-1, inSection: indexPath.section)){ + if let itemsCount = collectionView?.numberOfItems(inSection: (indexPath as NSIndexPath).section), + let firstItemAttributes = layoutAttributesForItem(at: indexPath), + let lastItemAttributes = layoutAttributesForItem(at: IndexPath(row: itemsCount-1, section: (indexPath as NSIndexPath).section)){ let edgeX = collectionView!.contentOffset.x + collectionView!.contentInset.left let xByLeftBoundary = max(edgeX,firstItemAttributes.frame.minX) // let width = size().width let xByRightBoundary = lastItemAttributes.frame.maxX - width let x = min(xByLeftBoundary,xByRightBoundary) - return CGPointMake(x, 0) + return CGPoint(x: x, y: 0) }else{ - return CGPointMake(inset(ForSection: indexPath.section).left, 0) + return CGPoint(x: inset(ForSection: (indexPath as NSIndexPath).section).left, y: 0) } } // - let attribute = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withIndexPath: indexPath) + let attribute = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, with: indexPath) let myPosition = position() let mySize = size() - let frame = CGRectMake(myPosition.x, myPosition.y, mySize.width, mySize.height) + let frame = CGRect(x: myPosition.x, y: myPosition.y, width: mySize.width, height: mySize.height) attribute.frame = frame return attribute } // - let sectionCount = collectionView!.numberOfSections() - var attributes = [NSIndexPath:UICollectionViewLayoutAttributes]() - for var section=0; section Bool { + override open func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { return true } - public override func invalidationContextForBoundsChange(newBounds: CGRect) -> UICollectionViewLayoutInvalidationContext { + open override func invalidationContext(forBoundsChange newBounds: CGRect) -> UICollectionViewLayoutInvalidationContext { func isSizeChanged()->Bool{ let oldBounds = collectionView!.bounds return oldBounds.width != newBounds.width || oldBounds.height != newBounds.height } - func headersIndexPaths()->[NSIndexPath]{ + func headersIndexPaths()->[IndexPath]{ return Array(sectionHeadersAttributes.keys) } // - let context = super.invalidationContextForBoundsChange(newBounds) + let context = super.invalidationContext(forBoundsChange: newBounds) if !isSizeChanged(){ - context.invalidateSupplementaryElementsOfKind(UICollectionElementKindSectionHeader, atIndexPaths: headersIndexPaths()) + context.invalidateSupplementaryElements(ofKind: UICollectionElementKindSectionHeader, at: headersIndexPaths()) } return context } //MARK: - Utility methods - private func itemSize(ForIndexPath indexPath:NSIndexPath) -> CGSize{ - guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate else {return CGSizeZero} + fileprivate func itemSize(ForIndexPath indexPath:IndexPath) -> CGSize{ + guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate else {return CGSize.zero} return delegate.collectionView(collectionView!, horizontalFloatingHeaderItemSizeForItemAtIndexPath: indexPath) } - private func headerSize(forSection section:Int) -> CGSize{ - guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate where section >= 0 else {return CGSizeZero} + fileprivate func headerSize(forSection section:Int) -> CGSize{ + guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate , section >= 0 else {return CGSize.zero} return delegate.collectionView(collectionView!, horizontalFloatingHeaderSizeForSectionAtIndex: section) } - private func inset(ForSection section:Int) -> UIEdgeInsets{ - let defaultValue = UIEdgeInsetsZero - guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate where section >= 0 else {return defaultValue} + fileprivate func inset(ForSection section:Int) -> UIEdgeInsets{ + let defaultValue = UIEdgeInsets.zero + guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate , section >= 0 else {return defaultValue} return delegate.collectionView?(collectionView!, horizontalFloatingHeaderSectionInsetForSectionAtIndex: section) ?? defaultValue } - private func columnSpacing(forSection section:Int) -> CGFloat{ + fileprivate func columnSpacing(forSection section:Int) -> CGFloat{ let defaultValue:CGFloat = 0.0 - guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate where section >= 0 else {return defaultValue} + guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate , section >= 0 else {return defaultValue} return delegate.collectionView?(collectionView!, horizontalFloatingHeaderColumnSpacingForSectionAtIndex: section) ?? defaultValue } - private func itemSpacing(forSection section:Int) -> CGFloat{ + fileprivate func itemSpacing(forSection section:Int) -> CGFloat{ let defaultValue:CGFloat = 0.0 - guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate where section >= 0 else {return defaultValue} + guard let delegate = collectionView?.delegate as? HorizontalFloatingHeaderLayoutDelegate , section >= 0 else {return defaultValue} return delegate.collectionView?(collectionView!, horizontalFloatingHeaderItemSpacingForSectionAtIndex: section) ?? defaultValue } - private func availableHeight(atSection section:Int)->CGFloat{ + fileprivate func availableHeight(atSection section:Int)->CGFloat{ func totalInset()->CGFloat{ let sectionInset = inset(ForSection: section) let contentInset = collectionView!.contentInset