├── .github └── workflows │ └── test.yml ├── .gitignore ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── Example.xcscheme ├── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── FirstViewController.swift │ ├── Info.plist │ ├── MainViewController.swift │ ├── SecondViewController.swift │ ├── TextCollectionViewCell.swift │ ├── ThirdViewController.swift │ └── WaterfallCollectionViewLayout.swift └── ExampleTests │ ├── ExampleTests.swift │ └── Info.plist ├── LICENSE └── README.md /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | 12 | runs-on: macOS-latest 13 | strategy: 14 | matrix: 15 | xcode: 16 | - 11.5 17 | - 11.6 18 | - 12.4 19 | 20 | steps: 21 | - uses: actions/checkout@master 22 | - name: Select Xcode ${{ matrix.xcode }} 23 | run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app 24 | - name: Run unit tests with iPhone 11 25 | run: xcodebuild clean test -project Example/Example.xcodeproj -scheme Example -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty && exit ${PIPESTATUS[0]} 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | 29 | # Carthage 30 | # 31 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 32 | # Carthage/Checkouts 33 | 34 | Carthage/Build 35 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2EE3B1C21B559DC600E1DF11 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1C11B559DC600E1DF11 /* AppDelegate.swift */; }; 11 | 2EE3B1C41B559DC600E1DF11 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1C31B559DC600E1DF11 /* MainViewController.swift */; }; 12 | 2EE3B1C71B559DC600E1DF11 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2EE3B1C51B559DC600E1DF11 /* Main.storyboard */; }; 13 | 2EE3B1C91B559DC600E1DF11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2EE3B1C81B559DC600E1DF11 /* Assets.xcassets */; }; 14 | 2EE3B1CC1B559DC600E1DF11 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2EE3B1CA1B559DC600E1DF11 /* LaunchScreen.storyboard */; }; 15 | 2EE3B1D61B55A1EC00E1DF11 /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1D51B55A1EC00E1DF11 /* FirstViewController.swift */; }; 16 | 2EE3B1D81B55A20700E1DF11 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1D71B55A20700E1DF11 /* SecondViewController.swift */; }; 17 | 2EE3B1DA1B55A21500E1DF11 /* ThirdViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1D91B55A21500E1DF11 /* ThirdViewController.swift */; }; 18 | 2EE3B1DD1B55A78C00E1DF11 /* TextCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1DC1B55A78C00E1DF11 /* TextCollectionViewCell.swift */; }; 19 | 2EE3B1E01B55B78D00E1DF11 /* WaterfallCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE3B1DF1B55B78D00E1DF11 /* WaterfallCollectionViewLayout.swift */; }; 20 | D8B8A85924C9A7F10076A275 /* ExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B8A85824C9A7F10076A275 /* ExampleTests.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | D8B8A85B24C9A7F10076A275 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 2EE3B1B61B559DC600E1DF11 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 2EE3B1BD1B559DC600E1DF11; 29 | remoteInfo = Example; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 2EE3B1BE1B559DC600E1DF11 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 2EE3B1C11B559DC600E1DF11 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | 2EE3B1C31B559DC600E1DF11 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 37 | 2EE3B1C61B559DC600E1DF11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | 2EE3B1C81B559DC600E1DF11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 39 | 2EE3B1CB1B559DC600E1DF11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | 2EE3B1CD1B559DC600E1DF11 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 2EE3B1D51B55A1EC00E1DF11 /* FirstViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = ""; }; 42 | 2EE3B1D71B55A20700E1DF11 /* SecondViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; 43 | 2EE3B1D91B55A21500E1DF11 /* ThirdViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThirdViewController.swift; sourceTree = ""; }; 44 | 2EE3B1DC1B55A78C00E1DF11 /* TextCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextCollectionViewCell.swift; sourceTree = ""; }; 45 | 2EE3B1DF1B55B78D00E1DF11 /* WaterfallCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WaterfallCollectionViewLayout.swift; sourceTree = ""; }; 46 | D8B8A85624C9A7F10076A275 /* ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | D8B8A85824C9A7F10076A275 /* ExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleTests.swift; sourceTree = ""; }; 48 | D8B8A85A24C9A7F10076A275 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | 2EE3B1BB1B559DC600E1DF11 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | D8B8A85324C9A7F10076A275 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 2EE3B1B51B559DC600E1DF11 = { 70 | isa = PBXGroup; 71 | children = ( 72 | 2EE3B1C01B559DC600E1DF11 /* Example */, 73 | D8B8A85724C9A7F10076A275 /* ExampleTests */, 74 | 2EE3B1BF1B559DC600E1DF11 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 2EE3B1BF1B559DC600E1DF11 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 2EE3B1BE1B559DC600E1DF11 /* Example.app */, 82 | D8B8A85624C9A7F10076A275 /* ExampleTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | 2EE3B1C01B559DC600E1DF11 /* Example */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 2EE3B1C11B559DC600E1DF11 /* AppDelegate.swift */, 91 | 2EE3B1DE1B55B76100E1DF11 /* Layouts */, 92 | 2EE3B1D31B55A15300E1DF11 /* ViewControllers */, 93 | 2EE3B1DB1B55A75600E1DF11 /* Views */, 94 | 2EE3B1D41B55A16600E1DF11 /* Resources */, 95 | ); 96 | path = Example; 97 | sourceTree = ""; 98 | }; 99 | 2EE3B1D31B55A15300E1DF11 /* ViewControllers */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 2EE3B1C31B559DC600E1DF11 /* MainViewController.swift */, 103 | 2EE3B1D51B55A1EC00E1DF11 /* FirstViewController.swift */, 104 | 2EE3B1D71B55A20700E1DF11 /* SecondViewController.swift */, 105 | 2EE3B1D91B55A21500E1DF11 /* ThirdViewController.swift */, 106 | ); 107 | name = ViewControllers; 108 | sourceTree = ""; 109 | }; 110 | 2EE3B1D41B55A16600E1DF11 /* Resources */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 2EE3B1C81B559DC600E1DF11 /* Assets.xcassets */, 114 | 2EE3B1C51B559DC600E1DF11 /* Main.storyboard */, 115 | 2EE3B1CA1B559DC600E1DF11 /* LaunchScreen.storyboard */, 116 | 2EE3B1CD1B559DC600E1DF11 /* Info.plist */, 117 | ); 118 | name = Resources; 119 | sourceTree = ""; 120 | }; 121 | 2EE3B1DB1B55A75600E1DF11 /* Views */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 2EE3B1DC1B55A78C00E1DF11 /* TextCollectionViewCell.swift */, 125 | ); 126 | name = Views; 127 | sourceTree = ""; 128 | }; 129 | 2EE3B1DE1B55B76100E1DF11 /* Layouts */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 2EE3B1DF1B55B78D00E1DF11 /* WaterfallCollectionViewLayout.swift */, 133 | ); 134 | name = Layouts; 135 | sourceTree = ""; 136 | }; 137 | D8B8A85724C9A7F10076A275 /* ExampleTests */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | D8B8A85824C9A7F10076A275 /* ExampleTests.swift */, 141 | D8B8A85A24C9A7F10076A275 /* Info.plist */, 142 | ); 143 | path = ExampleTests; 144 | sourceTree = ""; 145 | }; 146 | /* End PBXGroup section */ 147 | 148 | /* Begin PBXNativeTarget section */ 149 | 2EE3B1BD1B559DC600E1DF11 /* Example */ = { 150 | isa = PBXNativeTarget; 151 | buildConfigurationList = 2EE3B1D01B559DC600E1DF11 /* Build configuration list for PBXNativeTarget "Example" */; 152 | buildPhases = ( 153 | 2EE3B1BA1B559DC600E1DF11 /* Sources */, 154 | 2EE3B1BB1B559DC600E1DF11 /* Frameworks */, 155 | 2EE3B1BC1B559DC600E1DF11 /* Resources */, 156 | ); 157 | buildRules = ( 158 | ); 159 | dependencies = ( 160 | ); 161 | name = Example; 162 | productName = Example; 163 | productReference = 2EE3B1BE1B559DC600E1DF11 /* Example.app */; 164 | productType = "com.apple.product-type.application"; 165 | }; 166 | D8B8A85524C9A7F10076A275 /* ExampleTests */ = { 167 | isa = PBXNativeTarget; 168 | buildConfigurationList = D8B8A85F24C9A7F10076A275 /* Build configuration list for PBXNativeTarget "ExampleTests" */; 169 | buildPhases = ( 170 | D8B8A85224C9A7F10076A275 /* Sources */, 171 | D8B8A85324C9A7F10076A275 /* Frameworks */, 172 | D8B8A85424C9A7F10076A275 /* Resources */, 173 | ); 174 | buildRules = ( 175 | ); 176 | dependencies = ( 177 | D8B8A85C24C9A7F10076A275 /* PBXTargetDependency */, 178 | ); 179 | name = ExampleTests; 180 | productName = ExampleTests; 181 | productReference = D8B8A85624C9A7F10076A275 /* ExampleTests.xctest */; 182 | productType = "com.apple.product-type.bundle.unit-test"; 183 | }; 184 | /* End PBXNativeTarget section */ 185 | 186 | /* Begin PBXProject section */ 187 | 2EE3B1B61B559DC600E1DF11 /* Project object */ = { 188 | isa = PBXProject; 189 | attributes = { 190 | LastSwiftUpdateCheck = 1160; 191 | LastUpgradeCheck = 1160; 192 | ORGANIZATIONNAME = NSHint; 193 | TargetAttributes = { 194 | 2EE3B1BD1B559DC600E1DF11 = { 195 | CreatedOnToolsVersion = 7.0; 196 | LastSwiftMigration = 1160; 197 | ProvisioningStyle = Automatic; 198 | }; 199 | D8B8A85524C9A7F10076A275 = { 200 | CreatedOnToolsVersion = 11.6; 201 | ProvisioningStyle = Automatic; 202 | TestTargetID = 2EE3B1BD1B559DC600E1DF11; 203 | }; 204 | }; 205 | }; 206 | buildConfigurationList = 2EE3B1B91B559DC600E1DF11 /* Build configuration list for PBXProject "Example" */; 207 | compatibilityVersion = "Xcode 3.2"; 208 | developmentRegion = en; 209 | hasScannedForEncodings = 0; 210 | knownRegions = ( 211 | en, 212 | Base, 213 | ); 214 | mainGroup = 2EE3B1B51B559DC600E1DF11; 215 | productRefGroup = 2EE3B1BF1B559DC600E1DF11 /* Products */; 216 | projectDirPath = ""; 217 | projectRoot = ""; 218 | targets = ( 219 | 2EE3B1BD1B559DC600E1DF11 /* Example */, 220 | D8B8A85524C9A7F10076A275 /* ExampleTests */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXResourcesBuildPhase section */ 226 | 2EE3B1BC1B559DC600E1DF11 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | 2EE3B1CC1B559DC600E1DF11 /* LaunchScreen.storyboard in Resources */, 231 | 2EE3B1C91B559DC600E1DF11 /* Assets.xcassets in Resources */, 232 | 2EE3B1C71B559DC600E1DF11 /* Main.storyboard in Resources */, 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | D8B8A85424C9A7F10076A275 /* Resources */ = { 237 | isa = PBXResourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXResourcesBuildPhase section */ 244 | 245 | /* Begin PBXSourcesBuildPhase section */ 246 | 2EE3B1BA1B559DC600E1DF11 /* Sources */ = { 247 | isa = PBXSourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 2EE3B1D81B55A20700E1DF11 /* SecondViewController.swift in Sources */, 251 | 2EE3B1DD1B55A78C00E1DF11 /* TextCollectionViewCell.swift in Sources */, 252 | 2EE3B1E01B55B78D00E1DF11 /* WaterfallCollectionViewLayout.swift in Sources */, 253 | 2EE3B1D61B55A1EC00E1DF11 /* FirstViewController.swift in Sources */, 254 | 2EE3B1DA1B55A21500E1DF11 /* ThirdViewController.swift in Sources */, 255 | 2EE3B1C41B559DC600E1DF11 /* MainViewController.swift in Sources */, 256 | 2EE3B1C21B559DC600E1DF11 /* AppDelegate.swift in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | D8B8A85224C9A7F10076A275 /* Sources */ = { 261 | isa = PBXSourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | D8B8A85924C9A7F10076A275 /* ExampleTests.swift in Sources */, 265 | ); 266 | runOnlyForDeploymentPostprocessing = 0; 267 | }; 268 | /* End PBXSourcesBuildPhase section */ 269 | 270 | /* Begin PBXTargetDependency section */ 271 | D8B8A85C24C9A7F10076A275 /* PBXTargetDependency */ = { 272 | isa = PBXTargetDependency; 273 | target = 2EE3B1BD1B559DC600E1DF11 /* Example */; 274 | targetProxy = D8B8A85B24C9A7F10076A275 /* PBXContainerItemProxy */; 275 | }; 276 | /* End PBXTargetDependency section */ 277 | 278 | /* Begin PBXVariantGroup section */ 279 | 2EE3B1C51B559DC600E1DF11 /* Main.storyboard */ = { 280 | isa = PBXVariantGroup; 281 | children = ( 282 | 2EE3B1C61B559DC600E1DF11 /* Base */, 283 | ); 284 | name = Main.storyboard; 285 | sourceTree = ""; 286 | }; 287 | 2EE3B1CA1B559DC600E1DF11 /* LaunchScreen.storyboard */ = { 288 | isa = PBXVariantGroup; 289 | children = ( 290 | 2EE3B1CB1B559DC600E1DF11 /* Base */, 291 | ); 292 | name = LaunchScreen.storyboard; 293 | sourceTree = ""; 294 | }; 295 | /* End PBXVariantGroup section */ 296 | 297 | /* Begin XCBuildConfiguration section */ 298 | 2EE3B1CE1B559DC600E1DF11 /* Debug */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ALWAYS_SEARCH_USER_PATHS = NO; 302 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 303 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 304 | CLANG_CXX_LIBRARY = "libc++"; 305 | CLANG_ENABLE_MODULES = YES; 306 | CLANG_ENABLE_OBJC_ARC = YES; 307 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 308 | CLANG_WARN_BOOL_CONVERSION = YES; 309 | CLANG_WARN_COMMA = YES; 310 | CLANG_WARN_CONSTANT_CONVERSION = YES; 311 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 312 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 313 | CLANG_WARN_EMPTY_BODY = YES; 314 | CLANG_WARN_ENUM_CONVERSION = YES; 315 | CLANG_WARN_INFINITE_RECURSION = YES; 316 | CLANG_WARN_INT_CONVERSION = YES; 317 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 318 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 319 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 320 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 321 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 322 | CLANG_WARN_STRICT_PROTOTYPES = YES; 323 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 324 | CLANG_WARN_UNREACHABLE_CODE = YES; 325 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 326 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 327 | COPY_PHASE_STRIP = NO; 328 | DEBUG_INFORMATION_FORMAT = dwarf; 329 | ENABLE_STRICT_OBJC_MSGSEND = YES; 330 | ENABLE_TESTABILITY = YES; 331 | GCC_C_LANGUAGE_STANDARD = gnu99; 332 | GCC_DYNAMIC_NO_PIC = NO; 333 | GCC_NO_COMMON_BLOCKS = YES; 334 | GCC_OPTIMIZATION_LEVEL = 0; 335 | GCC_PREPROCESSOR_DEFINITIONS = ( 336 | "DEBUG=1", 337 | "$(inherited)", 338 | ); 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 346 | MTL_ENABLE_DEBUG_INFO = YES; 347 | ONLY_ACTIVE_ARCH = YES; 348 | SDKROOT = iphoneos; 349 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 350 | TARGETED_DEVICE_FAMILY = "1,2"; 351 | }; 352 | name = Debug; 353 | }; 354 | 2EE3B1CF1B559DC600E1DF11 /* Release */ = { 355 | isa = XCBuildConfiguration; 356 | buildSettings = { 357 | ALWAYS_SEARCH_USER_PATHS = NO; 358 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 359 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 360 | CLANG_CXX_LIBRARY = "libc++"; 361 | CLANG_ENABLE_MODULES = YES; 362 | CLANG_ENABLE_OBJC_ARC = YES; 363 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 364 | CLANG_WARN_BOOL_CONVERSION = YES; 365 | CLANG_WARN_COMMA = YES; 366 | CLANG_WARN_CONSTANT_CONVERSION = YES; 367 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 368 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 369 | CLANG_WARN_EMPTY_BODY = YES; 370 | CLANG_WARN_ENUM_CONVERSION = YES; 371 | CLANG_WARN_INFINITE_RECURSION = YES; 372 | CLANG_WARN_INT_CONVERSION = YES; 373 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 374 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 375 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 376 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 377 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 378 | CLANG_WARN_STRICT_PROTOTYPES = YES; 379 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 380 | CLANG_WARN_UNREACHABLE_CODE = YES; 381 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 382 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 383 | COPY_PHASE_STRIP = NO; 384 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 385 | ENABLE_NS_ASSERTIONS = NO; 386 | ENABLE_STRICT_OBJC_MSGSEND = YES; 387 | GCC_C_LANGUAGE_STANDARD = gnu99; 388 | GCC_NO_COMMON_BLOCKS = YES; 389 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 390 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 391 | GCC_WARN_UNDECLARED_SELECTOR = YES; 392 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 393 | GCC_WARN_UNUSED_FUNCTION = YES; 394 | GCC_WARN_UNUSED_VARIABLE = YES; 395 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 396 | MTL_ENABLE_DEBUG_INFO = NO; 397 | SDKROOT = iphoneos; 398 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 399 | TARGETED_DEVICE_FAMILY = "1,2"; 400 | VALIDATE_PRODUCT = YES; 401 | }; 402 | name = Release; 403 | }; 404 | 2EE3B1D11B559DC600E1DF11 /* Debug */ = { 405 | isa = XCBuildConfiguration; 406 | buildSettings = { 407 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 408 | CODE_SIGN_IDENTITY = "Apple Development"; 409 | CODE_SIGN_STYLE = Automatic; 410 | DEVELOPMENT_TEAM = ""; 411 | INFOPLIST_FILE = Example/Info.plist; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 413 | PRODUCT_BUNDLE_IDENTIFIER = com.nshint.Example; 414 | PRODUCT_NAME = "$(TARGET_NAME)"; 415 | PROVISIONING_PROFILE_SPECIFIER = ""; 416 | SWIFT_VERSION = 4.2; 417 | }; 418 | name = Debug; 419 | }; 420 | 2EE3B1D21B559DC600E1DF11 /* Release */ = { 421 | isa = XCBuildConfiguration; 422 | buildSettings = { 423 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 424 | CODE_SIGN_IDENTITY = "Apple Development"; 425 | CODE_SIGN_STYLE = Automatic; 426 | DEVELOPMENT_TEAM = ""; 427 | INFOPLIST_FILE = Example/Info.plist; 428 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 429 | PRODUCT_BUNDLE_IDENTIFIER = com.nshint.Example; 430 | PRODUCT_NAME = "$(TARGET_NAME)"; 431 | PROVISIONING_PROFILE_SPECIFIER = ""; 432 | SWIFT_VERSION = 4.2; 433 | }; 434 | name = Release; 435 | }; 436 | D8B8A85D24C9A7F10076A275 /* Debug */ = { 437 | isa = XCBuildConfiguration; 438 | buildSettings = { 439 | BUNDLE_LOADER = "$(TEST_HOST)"; 440 | CLANG_ANALYZER_NONNULL = YES; 441 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 442 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 443 | CLANG_ENABLE_OBJC_WEAK = YES; 444 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 445 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 446 | CODE_SIGN_IDENTITY = "Apple Development"; 447 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 448 | CODE_SIGN_STYLE = Automatic; 449 | DEVELOPMENT_TEAM = ""; 450 | GCC_C_LANGUAGE_STANDARD = gnu11; 451 | INFOPLIST_FILE = ExampleTests/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 453 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 454 | MTL_FAST_MATH = YES; 455 | PRODUCT_BUNDLE_IDENTIFIER = com.nshint.ExampleTests; 456 | PRODUCT_NAME = "$(TARGET_NAME)"; 457 | PROVISIONING_PROFILE_SPECIFIER = ""; 458 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 459 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 460 | SWIFT_VERSION = 4.2; 461 | TARGETED_DEVICE_FAMILY = "1,2"; 462 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; 463 | }; 464 | name = Debug; 465 | }; 466 | D8B8A85E24C9A7F10076A275 /* Release */ = { 467 | isa = XCBuildConfiguration; 468 | buildSettings = { 469 | BUNDLE_LOADER = "$(TEST_HOST)"; 470 | CLANG_ANALYZER_NONNULL = YES; 471 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 472 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 473 | CLANG_ENABLE_OBJC_WEAK = YES; 474 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 475 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 476 | CODE_SIGN_IDENTITY = "Apple Development"; 477 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 478 | CODE_SIGN_STYLE = Automatic; 479 | DEVELOPMENT_TEAM = ""; 480 | GCC_C_LANGUAGE_STANDARD = gnu11; 481 | INFOPLIST_FILE = ExampleTests/Info.plist; 482 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 483 | MTL_FAST_MATH = YES; 484 | PRODUCT_BUNDLE_IDENTIFIER = com.nshint.ExampleTests; 485 | PRODUCT_NAME = "$(TARGET_NAME)"; 486 | PROVISIONING_PROFILE_SPECIFIER = ""; 487 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 488 | SWIFT_VERSION = 4.2; 489 | TARGETED_DEVICE_FAMILY = "1,2"; 490 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; 491 | }; 492 | name = Release; 493 | }; 494 | /* End XCBuildConfiguration section */ 495 | 496 | /* Begin XCConfigurationList section */ 497 | 2EE3B1B91B559DC600E1DF11 /* Build configuration list for PBXProject "Example" */ = { 498 | isa = XCConfigurationList; 499 | buildConfigurations = ( 500 | 2EE3B1CE1B559DC600E1DF11 /* Debug */, 501 | 2EE3B1CF1B559DC600E1DF11 /* Release */, 502 | ); 503 | defaultConfigurationIsVisible = 0; 504 | defaultConfigurationName = Release; 505 | }; 506 | 2EE3B1D01B559DC600E1DF11 /* Build configuration list for PBXNativeTarget "Example" */ = { 507 | isa = XCConfigurationList; 508 | buildConfigurations = ( 509 | 2EE3B1D11B559DC600E1DF11 /* Debug */, 510 | 2EE3B1D21B559DC600E1DF11 /* Release */, 511 | ); 512 | defaultConfigurationIsVisible = 0; 513 | defaultConfigurationName = Release; 514 | }; 515 | D8B8A85F24C9A7F10076A275 /* Build configuration list for PBXNativeTarget "ExampleTests" */ = { 516 | isa = XCConfigurationList; 517 | buildConfigurations = ( 518 | D8B8A85D24C9A7F10076A275 /* Debug */, 519 | D8B8A85E24C9A7F10076A275 /* Release */, 520 | ); 521 | defaultConfigurationIsVisible = 0; 522 | defaultConfigurationName = Release; 523 | }; 524 | /* End XCConfigurationList section */ 525 | }; 526 | rootObject = 2EE3B1B61B559DC600E1DF11 /* Project object */; 527 | } 528 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by Wojtek on 14/07/2015. 6 | // Copyright © 2015 NSHint. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | return true 18 | } 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /Example/Example/FirstViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.swift 3 | // Example 4 | // 5 | // Created by Wojtek on 14/07/2015. 6 | // Copyright © 2015 NSHint. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | class FirstViewController: UICollectionViewController { 13 | 14 | var numbers = [Int](0...100) 15 | 16 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 17 | return numbers.count 18 | } 19 | 20 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 21 | 22 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! TextCollectionViewCell 23 | cell.textLabel.text = "\(numbers[indexPath.item])" 24 | 25 | return cell 26 | } 27 | 28 | override func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { 29 | 30 | let temp = numbers.remove(at: sourceIndexPath.item) 31 | numbers.insert(temp, at: destinationIndexPath.item) 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/Example/MainViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by Wojtek on 14/07/2015. 6 | // Copyright © 2015 NSHint. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum Example: String { 12 | case CollectionViewController 13 | case CollectionView 14 | case CollectionViewWithCustomLayout 15 | 16 | func segueIdentifier() -> String { 17 | switch(self) { 18 | case .CollectionViewController: 19 | return "FirstSegueIdentifier" 20 | case .CollectionView: 21 | return "SecondSegueIdentifier" 22 | case .CollectionViewWithCustomLayout: 23 | return "ThirdSegueIdentifier" 24 | } 25 | } 26 | 27 | } 28 | 29 | class MainViewController: UIViewController { 30 | var examples: [Example] = [.CollectionViewController, .CollectionView, .CollectionViewWithCustomLayout] 31 | } 32 | 33 | extension MainViewController: UITableViewDataSource { 34 | 35 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 36 | return examples.count 37 | } 38 | 39 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 40 | let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 41 | cell.textLabel!.text = examples[indexPath.item].rawValue 42 | 43 | return cell 44 | } 45 | } 46 | 47 | extension MainViewController: UITableViewDelegate { 48 | 49 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 50 | self.performSegue(withIdentifier: examples[indexPath.item].segueIdentifier(), sender: self) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Example/Example/SecondViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.swift 3 | // Example 4 | // 5 | // Created by Wojtek on 14/07/2015. 6 | // Copyright © 2015 NSHint. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondViewController: UIViewController { 12 | 13 | @IBOutlet weak var collectionView: UICollectionView! 14 | var numbers = [Int](0...100) 15 | 16 | fileprivate var longPressGesture: UILongPressGestureRecognizer! 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(SecondViewController.handleLongGesture(_:))) 22 | self.collectionView.addGestureRecognizer(longPressGesture) 23 | } 24 | 25 | @objc func handleLongGesture(_ gesture: UILongPressGestureRecognizer) { 26 | 27 | switch(gesture.state) { 28 | 29 | case UIGestureRecognizerState.began: 30 | guard let selectedIndexPath = self.collectionView.indexPathForItem(at: gesture.location(in: self.collectionView)) else { 31 | break 32 | } 33 | collectionView.beginInteractiveMovementForItem(at: selectedIndexPath) 34 | case UIGestureRecognizerState.changed: 35 | collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!)) 36 | case UIGestureRecognizerState.ended: 37 | collectionView.endInteractiveMovement() 38 | default: 39 | collectionView.cancelInteractiveMovement() 40 | } 41 | } 42 | 43 | } 44 | 45 | extension SecondViewController: UICollectionViewDataSource { 46 | 47 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 48 | return numbers.count 49 | } 50 | 51 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 52 | 53 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! TextCollectionViewCell 54 | cell.textLabel.text = "\(numbers[indexPath.item])" 55 | 56 | return cell 57 | } 58 | 59 | func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { 60 | 61 | let temp = numbers.remove(at: sourceIndexPath.item) 62 | numbers.insert(temp, at: destinationIndexPath.item) 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Example/Example/TextCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextCollectionViewCell.swift 3 | // Example 4 | // 5 | // Created by Wojtek on 14/07/2015. 6 | // Copyright © 2015 NSHint. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TextCollectionViewCell: UICollectionViewCell { 12 | @IBOutlet weak var textLabel: UILabel! 13 | } 14 | -------------------------------------------------------------------------------- /Example/Example/ThirdViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ThirdViewController.swift 3 | // Example 4 | // 5 | // Created by Wojtek on 14/07/2015. 6 | // Copyright © 2015 NSHint. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ThirdViewController: UIViewController { 12 | 13 | @IBOutlet weak var collectionView: UICollectionView! 14 | fileprivate var numbers: [Int] = [] 15 | 16 | fileprivate var longPressGesture: UILongPressGestureRecognizer! 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | for _ in 0...100 { 22 | let height = Int(arc4random_uniform((UInt32(100)))) + 40 23 | numbers.append(height) 24 | } 25 | 26 | longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(ThirdViewController.handleLongGesture(_:))) 27 | self.collectionView.addGestureRecognizer(longPressGesture) 28 | } 29 | 30 | @objc func handleLongGesture(_ gesture: UILongPressGestureRecognizer) { 31 | 32 | switch(gesture.state) { 33 | 34 | case UIGestureRecognizerState.began: 35 | guard let selectedIndexPath = self.collectionView.indexPathForItem(at: gesture.location(in: self.collectionView)) else { 36 | break 37 | } 38 | collectionView.beginInteractiveMovementForItem(at: selectedIndexPath) 39 | case UIGestureRecognizerState.changed: 40 | collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!)) 41 | case UIGestureRecognizerState.ended: 42 | collectionView.endInteractiveMovement() 43 | default: 44 | collectionView.cancelInteractiveMovement() 45 | } 46 | } 47 | 48 | } 49 | 50 | extension ThirdViewController: CHTCollectionViewDelegateWaterfallLayout { 51 | 52 | func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, 53 | sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { 54 | return CGSize(width: Int((view.bounds.width - 40)/3), height: numbers[indexPath.item]) 55 | } 56 | } 57 | 58 | extension ThirdViewController: UICollectionViewDataSource { 59 | 60 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 61 | return numbers.count 62 | } 63 | 64 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 65 | 66 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! TextCollectionViewCell 67 | cell.textLabel.text = "\(numbers[indexPath.item])" 68 | 69 | return cell 70 | } 71 | 72 | func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { 73 | 74 | let temp = numbers.remove(at: sourceIndexPath.item) 75 | numbers.insert(temp, at: destinationIndexPath.item) 76 | } 77 | 78 | } 79 | 80 | //MARK: one little trick 81 | extension CHTCollectionViewWaterfallLayout { 82 | 83 | internal override func invalidationContext(forInteractivelyMovingItems targetIndexPaths: [IndexPath], withTargetPosition targetPosition: CGPoint, previousIndexPaths: [IndexPath], previousPosition: CGPoint) -> UICollectionViewLayoutInvalidationContext { 84 | 85 | let context = super.invalidationContext(forInteractivelyMovingItems: targetIndexPaths, withTargetPosition: targetPosition, previousIndexPaths: previousIndexPaths, previousPosition: previousPosition) 86 | 87 | self.delegate?.collectionView!(self.collectionView!, moveItemAt: previousIndexPaths[0], to: targetIndexPaths[0]) 88 | 89 | return context 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Example/Example/WaterfallCollectionViewLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CHTCollectionViewWaterfallLayout.swift 3 | // PinterestSwift 4 | // 5 | // Created by Nicholas Tau on 6/30/14. 6 | // Copyright (c) 2014 Nicholas Tau. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | @objc protocol CHTCollectionViewDelegateWaterfallLayout: UICollectionViewDelegate, UICollectionViewDataSource { 13 | 14 | func collectionView (_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout, 15 | sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize 16 | 17 | @objc optional func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, 18 | heightForHeaderInSection section: NSInteger) -> CGFloat 19 | 20 | @objc optional func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, 21 | heightForFooterInSection section: NSInteger) -> CGFloat 22 | 23 | @objc optional func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, 24 | insetForSectionAtIndex section: NSInteger) -> UIEdgeInsets 25 | 26 | @objc optional func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, 27 | minimumInteritemSpacingForSectionAtIndex section: NSInteger) -> CGFloat 28 | } 29 | 30 | enum CHTCollectionViewWaterfallLayoutItemRenderDirection : NSInteger{ 31 | case shortestFirst, leftToRight, rightToLeft 32 | } 33 | 34 | class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{ 35 | let CHTCollectionElementKindSectionHeader = "CHTCollectionElementKindSectionHeader" 36 | let CHTCollectionElementKindSectionFooter = "CHTCollectionElementKindSectionFooter" 37 | 38 | var columnCount : NSInteger = 2 { 39 | didSet{ 40 | invalidateLayout() 41 | }} 42 | 43 | var minimumColumnSpacing : CGFloat = 10.0 { 44 | didSet{ 45 | invalidateLayout() 46 | }} 47 | 48 | var minimumInteritemSpacing : CGFloat = 10.0 { 49 | didSet{ 50 | invalidateLayout() 51 | }} 52 | 53 | var headerHeight : CGFloat = 0.0 { 54 | didSet{ 55 | invalidateLayout() 56 | }} 57 | 58 | var footerHeight : CGFloat = 0.0 { 59 | didSet{ 60 | invalidateLayout() 61 | }} 62 | 63 | var sectionInset : UIEdgeInsets = UIEdgeInsets.zero { 64 | didSet{ 65 | invalidateLayout() 66 | }} 67 | 68 | var itemRenderDirection : CHTCollectionViewWaterfallLayoutItemRenderDirection = .shortestFirst { 69 | didSet{ 70 | invalidateLayout() 71 | }} 72 | 73 | // private property and method above. 74 | weak var delegate : CHTCollectionViewDelegateWaterfallLayout?{ 75 | get{ 76 | return self.collectionView!.delegate as? CHTCollectionViewDelegateWaterfallLayout 77 | } 78 | } 79 | var columnHeights = [CGFloat]() 80 | var sectionItemAttributes = [[UICollectionViewLayoutAttributes]]() 81 | var allItemAttributes = [UICollectionViewLayoutAttributes]() 82 | var headersAttributes = [UICollectionViewLayoutAttributes]() 83 | var footersAttributes = [UICollectionViewLayoutAttributes]() 84 | var unionRects = [CGRect]() 85 | let unionSize = 20 86 | 87 | override init(){ 88 | super.init() 89 | } 90 | 91 | required init?(coder aDecoder: NSCoder) { 92 | super.init(coder: aDecoder) 93 | } 94 | 95 | func itemWidthInSectionAtIndex (_ section : NSInteger) -> CGFloat { 96 | let width:CGFloat = self.collectionView!.bounds.size.width - sectionInset.left-sectionInset.right 97 | let spaceColumCount:CGFloat = CGFloat(self.columnCount-1) 98 | return floor((width - (spaceColumCount*self.minimumColumnSpacing)) / CGFloat(self.columnCount)) 99 | } 100 | 101 | override func prepare(){ 102 | super.prepare() 103 | 104 | let numberOfSections = self.collectionView!.numberOfSections 105 | if numberOfSections == 0 { 106 | return 107 | } 108 | 109 | self.headersAttributes.removeAll() 110 | self.footersAttributes.removeAll() 111 | self.unionRects.removeAll() 112 | self.allItemAttributes.removeAll() 113 | self.sectionItemAttributes.removeAll() 114 | 115 | var top : CGFloat = 0.0 116 | var attributes = UICollectionViewLayoutAttributes() 117 | 118 | for section in 0 ..< numberOfSections { 119 | /* 120 | * 1. Get section-specific metrics (minimumInteritemSpacing, sectionInset) 121 | */ 122 | var minimumInteritemSpacing : CGFloat 123 | if let miniumSpaceing = self.delegate?.collectionView?(self.collectionView!, layout: self, minimumInteritemSpacingForSectionAtIndex: section){ 124 | minimumInteritemSpacing = miniumSpaceing 125 | }else{ 126 | minimumInteritemSpacing = self.minimumColumnSpacing 127 | } 128 | 129 | let width = self.collectionView!.bounds.size.width - sectionInset.left - sectionInset.right 130 | let spaceColumCount = CGFloat(self.columnCount-1) 131 | let itemWidth = floor((width - (spaceColumCount*self.minimumColumnSpacing)) / CGFloat(self.columnCount)) 132 | 133 | /* 134 | * 2. Section header 135 | */ 136 | var heightHeader : CGFloat 137 | if let height = self.delegate?.collectionView?(self.collectionView!, layout: self, heightForHeaderInSection: section){ 138 | heightHeader = height 139 | }else{ 140 | heightHeader = self.headerHeight 141 | } 142 | 143 | if heightHeader > 0 { 144 | attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: CHTCollectionElementKindSectionHeader, with: IndexPath(row: 0, section: section)) 145 | attributes.frame = CGRect(x: 0, y: top, width: self.collectionView!.bounds.size.width, height: heightHeader) 146 | self.headersAttributes[section] = attributes 147 | self.allItemAttributes.append(attributes) 148 | 149 | top = attributes.frame.maxY 150 | } 151 | top += sectionInset.top 152 | 153 | self.columnHeights = [CGFloat](repeating: top, count: self.columnCount) 154 | 155 | /* 156 | * 3. Section items 157 | */ 158 | let itemCount = self.collectionView!.numberOfItems(inSection: section) 159 | var itemAttributes = [UICollectionViewLayoutAttributes]() 160 | itemAttributes.reserveCapacity(itemCount) 161 | 162 | // Item will be put into shortest column. 163 | for idx in 0 ..< itemCount { 164 | let indexPath = IndexPath(item: idx, section: section) 165 | 166 | let columnIndex = self.nextColumnIndexForItem(idx) 167 | let xOffset = sectionInset.left + (itemWidth + self.minimumColumnSpacing) * CGFloat(columnIndex) 168 | let yOffset = self.columnHeights[columnIndex] 169 | let itemSize = self.delegate?.collectionView(self.collectionView!, layout: self, sizeForItemAtIndexPath: indexPath) ?? CGSize.zero 170 | var itemHeight : CGFloat = 0.0 171 | 172 | if itemSize.height > 0 && itemSize.width > 0 { 173 | itemHeight = floor(itemSize.height * itemWidth / itemSize.width) 174 | } 175 | 176 | attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath) 177 | attributes.frame = CGRect(x: xOffset, y: CGFloat(yOffset), width: itemWidth, height: itemHeight) 178 | itemAttributes.append(attributes) 179 | self.allItemAttributes.append(attributes) 180 | self.columnHeights[columnIndex]=attributes.frame.maxY + minimumInteritemSpacing; 181 | } 182 | self.sectionItemAttributes.append(itemAttributes) 183 | 184 | /* 185 | * 4. Section footer 186 | */ 187 | var footerHeight : CGFloat = 0.0 188 | let columnIndex = self.longestColumnIndex() 189 | top = self.columnHeights[columnIndex] - minimumInteritemSpacing + sectionInset.bottom 190 | 191 | if let height = self.delegate?.collectionView?(self.collectionView!, layout: self, heightForFooterInSection: section){ 192 | footerHeight = height 193 | }else{ 194 | footerHeight = self.footerHeight 195 | } 196 | 197 | if footerHeight > 0 { 198 | attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: CHTCollectionElementKindSectionFooter, with: IndexPath(item: 0, section: section)) 199 | attributes.frame = CGRect(x: 0, y: top, width: self.collectionView!.bounds.size.width, height: footerHeight) 200 | self.footersAttributes.append(attributes) 201 | self.allItemAttributes.append(attributes) 202 | top = attributes.frame.maxY 203 | } 204 | 205 | self.columnHeights = [CGFloat](repeating:top, count: self.columnCount) 206 | } 207 | var idx = 0; 208 | let itemCounts = self.allItemAttributes.count 209 | while(idx < itemCounts){ 210 | let rect1 = self.allItemAttributes[idx].frame 211 | idx = min(idx + unionSize, itemCounts) - 1 212 | let rect2 = self.allItemAttributes[idx].frame 213 | self.unionRects.append(rect1.union(rect2)) 214 | idx += 1 215 | } 216 | } 217 | 218 | override var collectionViewContentSize : CGSize{ 219 | let numberOfSections = self.collectionView!.numberOfSections 220 | if numberOfSections == 0{ 221 | return CGSize.zero 222 | } 223 | 224 | var contentSize = self.collectionView!.bounds.size as CGSize 225 | contentSize.height = self.columnHeights[0] 226 | return contentSize 227 | } 228 | 229 | override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 230 | if indexPath.section >= self.sectionItemAttributes.count{ 231 | return nil 232 | } 233 | if indexPath.item >= self.sectionItemAttributes[indexPath.section].count { 234 | return nil; 235 | } 236 | let list = self.sectionItemAttributes[indexPath.section] 237 | return list[indexPath.item] 238 | } 239 | 240 | override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes{ 241 | var attribute = UICollectionViewLayoutAttributes() 242 | if elementKind == CHTCollectionElementKindSectionHeader{ 243 | attribute = self.headersAttributes[indexPath.section] 244 | }else if elementKind == CHTCollectionElementKindSectionFooter{ 245 | attribute = self.footersAttributes[indexPath.section] 246 | } 247 | return attribute 248 | } 249 | 250 | override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 251 | var begin = 0, end = self.unionRects.count 252 | let attrs = NSMutableArray() 253 | 254 | for i in 0 ..< end { 255 | if rect.intersects(self.unionRects[i]) { 256 | begin = i * unionSize; 257 | break 258 | } 259 | } 260 | for i in (0 ..< self.unionRects.count).reversed() { 261 | if rect.intersects(self.unionRects[i]) { 262 | end = min((i+1)*unionSize,self.allItemAttributes.count) 263 | break 264 | } 265 | } 266 | for i in begin ..< end { 267 | let attr = self.allItemAttributes[i] 268 | if rect.intersects(attr.frame) { 269 | attrs.add(attr) 270 | } 271 | } 272 | 273 | return NSArray(array: attrs) as? [UICollectionViewLayoutAttributes] 274 | } 275 | 276 | override func shouldInvalidateLayout (forBoundsChange newBounds : CGRect) -> Bool { 277 | let oldBounds = self.collectionView!.bounds 278 | if newBounds.width != oldBounds.width{ 279 | return true 280 | } 281 | return false 282 | } 283 | 284 | 285 | /** 286 | * Find the shortest column. 287 | * 288 | * @return index for the shortest column 289 | */ 290 | func shortestColumnIndex () -> NSInteger { 291 | var index = 0 292 | var shortestHeigth = CGFloat.greatestFiniteMagnitude 293 | 294 | for (idx, heigth) in self.columnHeights.enumerated() { 295 | if (heigth < shortestHeigth) { 296 | shortestHeigth = heigth 297 | index = idx 298 | } 299 | } 300 | return index 301 | } 302 | 303 | /** 304 | * Find the longest column. 305 | * 306 | * @return index for the longest column 307 | */ 308 | func longestColumnIndex() -> NSInteger { 309 | var index = 0 310 | var longestHeigth:CGFloat = 0.0 311 | 312 | for (idx, heigth) in self.columnHeights.enumerated() { 313 | if (heigth > longestHeigth) { 314 | longestHeigth = heigth 315 | index = idx 316 | } 317 | } 318 | return index 319 | } 320 | 321 | /** 322 | * Find the index for the next column. 323 | * 324 | * @return index for the next column 325 | */ 326 | func nextColumnIndexForItem (_ item : NSInteger) -> Int { 327 | var index = 0 328 | switch (self.itemRenderDirection){ 329 | case .shortestFirst: 330 | index = self.shortestColumnIndex() 331 | case .leftToRight: 332 | index = (item%self.columnCount) 333 | case .rightToLeft: 334 | index = (self.columnCount - 1) - (item % self.columnCount); 335 | } 336 | 337 | return index 338 | } 339 | } 340 | -------------------------------------------------------------------------------- /Example/ExampleTests/ExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleTests.swift 3 | // ExampleTests 4 | // 5 | // Created by Mateusz Matoszko on 23/07/2020. 6 | // Copyright © 2020 NSHint. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class ExampleTests: XCTestCase { 12 | 13 | override func setUpWithError() throws { 14 | // Put setup code here. This method is called before the invocation of each test method in the class. 15 | } 16 | 17 | override func tearDownWithError() throws { 18 | // Put teardown code here. This method is called after the invocation of each test method in the class. 19 | } 20 | 21 | func testExample() throws { 22 | // This is an example of a functional test case. 23 | // Use XCTAssert and related functions to verify your tests produce the correct results. 24 | } 25 | 26 | func testPerformanceExample() throws { 27 | // This is an example of a performance test case. 28 | measure { 29 | // Put the code you want to measure the time of here. 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Example/ExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 NSHint 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UICollectionViews reordering 2 | ====================== 3 | 4 | Built for the [UICollectionViews Now Have Easy Reordering](https://nshint.github.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/) post on [NSHint](https://nshint.github.io). 5 | 6 | ![UICollectionViews Now Have Easy Reordering](https://nshint.github.io/images/uicollectionview-reordering/4.gif) 7 | 8 | --------------------------------------------------------------------------------