├── .gitignore ├── .travis.yml ├── ClosuresKit.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── ClosuresKit.xcscmblueprint ├── xcshareddata │ └── xcschemes │ │ └── ClosuresKit.xcscheme └── xcuserdata │ └── zz.xcuserdatad │ └── xcschemes │ ├── ClosuresTest.xcscheme │ └── xcschememanagement.plist ├── ClosuresKit ├── CSGesturePromise.swift ├── ClosuresKit.h ├── GestureUIViewExtension.swift ├── Info.plist ├── NSObjectAssociatedExtension.swift ├── NSTimerExtension.swift ├── ObserverNotificationExtension.swift ├── SequenceTypeExtension.swift ├── UIControlExtension.swift └── UIGesturePromiseExntension.swift ├── ClosuresKitTests ├── AssocaitedObjectTests.swift ├── Info.plist ├── ObserverNotificationTests.swift ├── SequenceExtensionTests.swift └── TimerTests.swift ├── ClosuresTest ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── UIControlViewController.swift └── UIGestureViewController.swift ├── ClosuresTestUITests ├── ClosuresTestUITests.swift └── Info.plist ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Breakpoints_v2.xcbkptlist 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | osx_image: xcode7.3 2 | language: objective-c 3 | xcode_project: ClosuresKit.xcodeproj 4 | script: xcodebuild -project ClosuresKit.xcodeproj -scheme "ClosuresKit" 5 | -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' -------------------------------------------------------------------------------- /ClosuresKit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3A22A1AD1CCA205000AC78DF /* ClosuresKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A22A1AC1CCA205000AC78DF /* ClosuresKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 3A22A1B41CCA205000AC78DF /* ClosuresKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A22A1A91CCA205000AC78DF /* ClosuresKit.framework */; }; 12 | 3A22A1C41CCA226800AC78DF /* SequenceTypeExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1C31CCA226800AC78DF /* SequenceTypeExtension.swift */; }; 13 | 3A22A1C71CCA28D200AC78DF /* SequenceExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1C61CCA28D200AC78DF /* SequenceExtensionTests.swift */; }; 14 | 3A22A1C91CCCFB3800AC78DF /* NSObjectAssociatedExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1C81CCCFB3800AC78DF /* NSObjectAssociatedExtension.swift */; }; 15 | 3A22A1CB1CCD038500AC78DF /* AssocaitedObjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1CA1CCD038500AC78DF /* AssocaitedObjectTests.swift */; }; 16 | 3A22A1CD1CCDEF1500AC78DF /* ObserverNotificationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1CC1CCDEF1500AC78DF /* ObserverNotificationExtension.swift */; }; 17 | 3A22A1CF1CCDFDC600AC78DF /* ObserverNotificationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1CE1CCDFDC600AC78DF /* ObserverNotificationTests.swift */; }; 18 | 3A22A1D11CCE035100AC78DF /* NSTimerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1D01CCE035100AC78DF /* NSTimerExtension.swift */; }; 19 | 3A22A1D31CCE0F4800AC78DF /* TimerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1D21CCE0F4800AC78DF /* TimerTests.swift */; }; 20 | 3A22A1DB1CCE1B4F00AC78DF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1DA1CCE1B4F00AC78DF /* AppDelegate.swift */; }; 21 | 3A22A1E01CCE1B4F00AC78DF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3A22A1DE1CCE1B4F00AC78DF /* Main.storyboard */; }; 22 | 3A22A1E21CCE1B4F00AC78DF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3A22A1E11CCE1B4F00AC78DF /* Assets.xcassets */; }; 23 | 3A22A1E51CCE1B4F00AC78DF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3A22A1E31CCE1B4F00AC78DF /* LaunchScreen.storyboard */; }; 24 | 3A22A1F01CCE1B4F00AC78DF /* ClosuresTestUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A1EF1CCE1B4F00AC78DF /* ClosuresTestUITests.swift */; }; 25 | 3A22A1F81CCE1B6000AC78DF /* ClosuresKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A22A1A91CCA205000AC78DF /* ClosuresKit.framework */; }; 26 | 3A22A1F91CCE1B6000AC78DF /* ClosuresKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3A22A1A91CCA205000AC78DF /* ClosuresKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 27 | 3A22A2021CCE5B6600AC78DF /* UIControlExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A2011CCE5B6600AC78DF /* UIControlExtension.swift */; }; 28 | 3A22A2041CCE753F00AC78DF /* UIControlViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A22A2031CCE753F00AC78DF /* UIControlViewController.swift */; }; 29 | 3A42CF4E1CDF92FA0048C58F /* CSGesturePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A42CF4D1CDF92FA0048C58F /* CSGesturePromise.swift */; }; 30 | 3A42CF521CDF95810048C58F /* UIGesturePromiseExntension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A42CF511CDF95810048C58F /* UIGesturePromiseExntension.swift */; }; 31 | 3A42CF541CDFA5BD0048C58F /* UIGestureViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A42CF531CDFA5BD0048C58F /* UIGestureViewController.swift */; }; 32 | 3A42CF561CDFA7620048C58F /* GestureUIViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A42CF551CDFA7620048C58F /* GestureUIViewExtension.swift */; }; 33 | /* End PBXBuildFile section */ 34 | 35 | /* Begin PBXContainerItemProxy section */ 36 | 3A22A1B51CCA205000AC78DF /* PBXContainerItemProxy */ = { 37 | isa = PBXContainerItemProxy; 38 | containerPortal = 3A22A1A01CCA205000AC78DF /* Project object */; 39 | proxyType = 1; 40 | remoteGlobalIDString = 3A22A1A81CCA205000AC78DF; 41 | remoteInfo = ClosuresKit; 42 | }; 43 | 3A22A1EC1CCE1B4F00AC78DF /* PBXContainerItemProxy */ = { 44 | isa = PBXContainerItemProxy; 45 | containerPortal = 3A22A1A01CCA205000AC78DF /* Project object */; 46 | proxyType = 1; 47 | remoteGlobalIDString = 3A22A1D71CCE1B4F00AC78DF; 48 | remoteInfo = ClosuresTest; 49 | }; 50 | 3A22A1FA1CCE1B6000AC78DF /* PBXContainerItemProxy */ = { 51 | isa = PBXContainerItemProxy; 52 | containerPortal = 3A22A1A01CCA205000AC78DF /* Project object */; 53 | proxyType = 1; 54 | remoteGlobalIDString = 3A22A1A81CCA205000AC78DF; 55 | remoteInfo = ClosuresKit; 56 | }; 57 | /* End PBXContainerItemProxy section */ 58 | 59 | /* Begin PBXCopyFilesBuildPhase section */ 60 | 3A22A1FC1CCE1B6000AC78DF /* Embed Frameworks */ = { 61 | isa = PBXCopyFilesBuildPhase; 62 | buildActionMask = 2147483647; 63 | dstPath = ""; 64 | dstSubfolderSpec = 10; 65 | files = ( 66 | 3A22A1F91CCE1B6000AC78DF /* ClosuresKit.framework in Embed Frameworks */, 67 | ); 68 | name = "Embed Frameworks"; 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | /* End PBXCopyFilesBuildPhase section */ 72 | 73 | /* Begin PBXFileReference section */ 74 | 3A22A1A91CCA205000AC78DF /* ClosuresKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ClosuresKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 75 | 3A22A1AC1CCA205000AC78DF /* ClosuresKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ClosuresKit.h; sourceTree = ""; }; 76 | 3A22A1AE1CCA205000AC78DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 77 | 3A22A1B31CCA205000AC78DF /* ClosuresKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ClosuresKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 78 | 3A22A1BA1CCA205000AC78DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 79 | 3A22A1C31CCA226800AC78DF /* SequenceTypeExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeExtension.swift; sourceTree = ""; }; 80 | 3A22A1C61CCA28D200AC78DF /* SequenceExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceExtensionTests.swift; sourceTree = ""; }; 81 | 3A22A1C81CCCFB3800AC78DF /* NSObjectAssociatedExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSObjectAssociatedExtension.swift; sourceTree = ""; }; 82 | 3A22A1CA1CCD038500AC78DF /* AssocaitedObjectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssocaitedObjectTests.swift; sourceTree = ""; }; 83 | 3A22A1CC1CCDEF1500AC78DF /* ObserverNotificationExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObserverNotificationExtension.swift; sourceTree = ""; }; 84 | 3A22A1CE1CCDFDC600AC78DF /* ObserverNotificationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObserverNotificationTests.swift; sourceTree = ""; }; 85 | 3A22A1D01CCE035100AC78DF /* NSTimerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSTimerExtension.swift; sourceTree = ""; }; 86 | 3A22A1D21CCE0F4800AC78DF /* TimerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimerTests.swift; sourceTree = ""; }; 87 | 3A22A1D81CCE1B4F00AC78DF /* ClosuresTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ClosuresTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 88 | 3A22A1DA1CCE1B4F00AC78DF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 89 | 3A22A1DF1CCE1B4F00AC78DF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 90 | 3A22A1E11CCE1B4F00AC78DF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 91 | 3A22A1E41CCE1B4F00AC78DF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 92 | 3A22A1E61CCE1B4F00AC78DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 93 | 3A22A1EB1CCE1B4F00AC78DF /* ClosuresTestUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ClosuresTestUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 94 | 3A22A1EF1CCE1B4F00AC78DF /* ClosuresTestUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClosuresTestUITests.swift; sourceTree = ""; }; 95 | 3A22A1F11CCE1B4F00AC78DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 96 | 3A22A2011CCE5B6600AC78DF /* UIControlExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControlExtension.swift; sourceTree = ""; }; 97 | 3A22A2031CCE753F00AC78DF /* UIControlViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControlViewController.swift; sourceTree = ""; }; 98 | 3A42CF4D1CDF92FA0048C58F /* CSGesturePromise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSGesturePromise.swift; sourceTree = ""; }; 99 | 3A42CF511CDF95810048C58F /* UIGesturePromiseExntension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIGesturePromiseExntension.swift; sourceTree = ""; }; 100 | 3A42CF531CDFA5BD0048C58F /* UIGestureViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIGestureViewController.swift; sourceTree = ""; }; 101 | 3A42CF551CDFA7620048C58F /* GestureUIViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GestureUIViewExtension.swift; sourceTree = ""; }; 102 | /* End PBXFileReference section */ 103 | 104 | /* Begin PBXFrameworksBuildPhase section */ 105 | 3A22A1A51CCA205000AC78DF /* Frameworks */ = { 106 | isa = PBXFrameworksBuildPhase; 107 | buildActionMask = 2147483647; 108 | files = ( 109 | ); 110 | runOnlyForDeploymentPostprocessing = 0; 111 | }; 112 | 3A22A1B01CCA205000AC78DF /* Frameworks */ = { 113 | isa = PBXFrameworksBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | 3A22A1B41CCA205000AC78DF /* ClosuresKit.framework in Frameworks */, 117 | ); 118 | runOnlyForDeploymentPostprocessing = 0; 119 | }; 120 | 3A22A1D51CCE1B4F00AC78DF /* Frameworks */ = { 121 | isa = PBXFrameworksBuildPhase; 122 | buildActionMask = 2147483647; 123 | files = ( 124 | 3A22A1F81CCE1B6000AC78DF /* ClosuresKit.framework in Frameworks */, 125 | ); 126 | runOnlyForDeploymentPostprocessing = 0; 127 | }; 128 | 3A22A1E81CCE1B4F00AC78DF /* Frameworks */ = { 129 | isa = PBXFrameworksBuildPhase; 130 | buildActionMask = 2147483647; 131 | files = ( 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | /* End PBXFrameworksBuildPhase section */ 136 | 137 | /* Begin PBXGroup section */ 138 | 3A22A19F1CCA205000AC78DF = { 139 | isa = PBXGroup; 140 | children = ( 141 | 3A22A1AB1CCA205000AC78DF /* ClosuresKit */, 142 | 3A22A1B71CCA205000AC78DF /* ClosuresKitTests */, 143 | 3A22A1D91CCE1B4F00AC78DF /* ClosuresTest */, 144 | 3A22A1EE1CCE1B4F00AC78DF /* ClosuresTestUITests */, 145 | 3A22A1AA1CCA205000AC78DF /* Products */, 146 | ); 147 | sourceTree = ""; 148 | }; 149 | 3A22A1AA1CCA205000AC78DF /* Products */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | 3A22A1A91CCA205000AC78DF /* ClosuresKit.framework */, 153 | 3A22A1B31CCA205000AC78DF /* ClosuresKitTests.xctest */, 154 | 3A22A1D81CCE1B4F00AC78DF /* ClosuresTest.app */, 155 | 3A22A1EB1CCE1B4F00AC78DF /* ClosuresTestUITests.xctest */, 156 | ); 157 | name = Products; 158 | sourceTree = ""; 159 | }; 160 | 3A22A1AB1CCA205000AC78DF /* ClosuresKit */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | 3A42CF4A1CDF8DFF0048C58F /* UIGesture */, 164 | 3A22A1FD1CCE2F0000AC78DF /* Foundation */, 165 | 3A22A1FE1CCE2F0C00AC78DF /* UIKit */, 166 | 3A22A1AC1CCA205000AC78DF /* ClosuresKit.h */, 167 | 3A22A1AE1CCA205000AC78DF /* Info.plist */, 168 | ); 169 | path = ClosuresKit; 170 | sourceTree = ""; 171 | }; 172 | 3A22A1B71CCA205000AC78DF /* ClosuresKitTests */ = { 173 | isa = PBXGroup; 174 | children = ( 175 | 3A22A1BA1CCA205000AC78DF /* Info.plist */, 176 | 3A22A1C61CCA28D200AC78DF /* SequenceExtensionTests.swift */, 177 | 3A22A1CA1CCD038500AC78DF /* AssocaitedObjectTests.swift */, 178 | 3A22A1CE1CCDFDC600AC78DF /* ObserverNotificationTests.swift */, 179 | 3A22A1D21CCE0F4800AC78DF /* TimerTests.swift */, 180 | ); 181 | path = ClosuresKitTests; 182 | sourceTree = ""; 183 | }; 184 | 3A22A1D91CCE1B4F00AC78DF /* ClosuresTest */ = { 185 | isa = PBXGroup; 186 | children = ( 187 | 3A22A1DE1CCE1B4F00AC78DF /* Main.storyboard */, 188 | 3A22A2031CCE753F00AC78DF /* UIControlViewController.swift */, 189 | 3A42CF531CDFA5BD0048C58F /* UIGestureViewController.swift */, 190 | 3A22A2051CCE754500AC78DF /* Others */, 191 | ); 192 | path = ClosuresTest; 193 | sourceTree = ""; 194 | }; 195 | 3A22A1EE1CCE1B4F00AC78DF /* ClosuresTestUITests */ = { 196 | isa = PBXGroup; 197 | children = ( 198 | 3A22A1EF1CCE1B4F00AC78DF /* ClosuresTestUITests.swift */, 199 | 3A22A1F11CCE1B4F00AC78DF /* Info.plist */, 200 | ); 201 | path = ClosuresTestUITests; 202 | sourceTree = ""; 203 | }; 204 | 3A22A1FD1CCE2F0000AC78DF /* Foundation */ = { 205 | isa = PBXGroup; 206 | children = ( 207 | 3A22A1C31CCA226800AC78DF /* SequenceTypeExtension.swift */, 208 | 3A22A1C81CCCFB3800AC78DF /* NSObjectAssociatedExtension.swift */, 209 | 3A22A1CC1CCDEF1500AC78DF /* ObserverNotificationExtension.swift */, 210 | 3A22A1D01CCE035100AC78DF /* NSTimerExtension.swift */, 211 | ); 212 | name = Foundation; 213 | sourceTree = ""; 214 | }; 215 | 3A22A1FE1CCE2F0C00AC78DF /* UIKit */ = { 216 | isa = PBXGroup; 217 | children = ( 218 | 3A22A2011CCE5B6600AC78DF /* UIControlExtension.swift */, 219 | ); 220 | name = UIKit; 221 | sourceTree = ""; 222 | }; 223 | 3A22A2051CCE754500AC78DF /* Others */ = { 224 | isa = PBXGroup; 225 | children = ( 226 | 3A22A1DA1CCE1B4F00AC78DF /* AppDelegate.swift */, 227 | 3A22A1E11CCE1B4F00AC78DF /* Assets.xcassets */, 228 | 3A22A1E31CCE1B4F00AC78DF /* LaunchScreen.storyboard */, 229 | 3A22A1E61CCE1B4F00AC78DF /* Info.plist */, 230 | ); 231 | name = Others; 232 | sourceTree = ""; 233 | }; 234 | 3A42CF4A1CDF8DFF0048C58F /* UIGesture */ = { 235 | isa = PBXGroup; 236 | children = ( 237 | 3A42CF4D1CDF92FA0048C58F /* CSGesturePromise.swift */, 238 | 3A42CF511CDF95810048C58F /* UIGesturePromiseExntension.swift */, 239 | 3A42CF551CDFA7620048C58F /* GestureUIViewExtension.swift */, 240 | ); 241 | name = UIGesture; 242 | sourceTree = ""; 243 | }; 244 | /* End PBXGroup section */ 245 | 246 | /* Begin PBXHeadersBuildPhase section */ 247 | 3A22A1A61CCA205000AC78DF /* Headers */ = { 248 | isa = PBXHeadersBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | 3A22A1AD1CCA205000AC78DF /* ClosuresKit.h in Headers */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | /* End PBXHeadersBuildPhase section */ 256 | 257 | /* Begin PBXNativeTarget section */ 258 | 3A22A1A81CCA205000AC78DF /* ClosuresKit */ = { 259 | isa = PBXNativeTarget; 260 | buildConfigurationList = 3A22A1BD1CCA205000AC78DF /* Build configuration list for PBXNativeTarget "ClosuresKit" */; 261 | buildPhases = ( 262 | 3A22A1A41CCA205000AC78DF /* Sources */, 263 | 3A22A1A51CCA205000AC78DF /* Frameworks */, 264 | 3A22A1A61CCA205000AC78DF /* Headers */, 265 | 3A22A1A71CCA205000AC78DF /* Resources */, 266 | ); 267 | buildRules = ( 268 | ); 269 | dependencies = ( 270 | ); 271 | name = ClosuresKit; 272 | productName = ClosuresKit; 273 | productReference = 3A22A1A91CCA205000AC78DF /* ClosuresKit.framework */; 274 | productType = "com.apple.product-type.framework"; 275 | }; 276 | 3A22A1B21CCA205000AC78DF /* ClosuresKitTests */ = { 277 | isa = PBXNativeTarget; 278 | buildConfigurationList = 3A22A1C01CCA205000AC78DF /* Build configuration list for PBXNativeTarget "ClosuresKitTests" */; 279 | buildPhases = ( 280 | 3A22A1AF1CCA205000AC78DF /* Sources */, 281 | 3A22A1B01CCA205000AC78DF /* Frameworks */, 282 | 3A22A1B11CCA205000AC78DF /* Resources */, 283 | ); 284 | buildRules = ( 285 | ); 286 | dependencies = ( 287 | 3A22A1B61CCA205000AC78DF /* PBXTargetDependency */, 288 | ); 289 | name = ClosuresKitTests; 290 | productName = ClosuresKitTests; 291 | productReference = 3A22A1B31CCA205000AC78DF /* ClosuresKitTests.xctest */; 292 | productType = "com.apple.product-type.bundle.unit-test"; 293 | }; 294 | 3A22A1D71CCE1B4F00AC78DF /* ClosuresTest */ = { 295 | isa = PBXNativeTarget; 296 | buildConfigurationList = 3A22A1F21CCE1B4F00AC78DF /* Build configuration list for PBXNativeTarget "ClosuresTest" */; 297 | buildPhases = ( 298 | 3A22A1D41CCE1B4F00AC78DF /* Sources */, 299 | 3A22A1D51CCE1B4F00AC78DF /* Frameworks */, 300 | 3A22A1D61CCE1B4F00AC78DF /* Resources */, 301 | 3A22A1FC1CCE1B6000AC78DF /* Embed Frameworks */, 302 | ); 303 | buildRules = ( 304 | ); 305 | dependencies = ( 306 | 3A22A1FB1CCE1B6000AC78DF /* PBXTargetDependency */, 307 | ); 308 | name = ClosuresTest; 309 | productName = ClosuresTest; 310 | productReference = 3A22A1D81CCE1B4F00AC78DF /* ClosuresTest.app */; 311 | productType = "com.apple.product-type.application"; 312 | }; 313 | 3A22A1EA1CCE1B4F00AC78DF /* ClosuresTestUITests */ = { 314 | isa = PBXNativeTarget; 315 | buildConfigurationList = 3A22A1F51CCE1B4F00AC78DF /* Build configuration list for PBXNativeTarget "ClosuresTestUITests" */; 316 | buildPhases = ( 317 | 3A22A1E71CCE1B4F00AC78DF /* Sources */, 318 | 3A22A1E81CCE1B4F00AC78DF /* Frameworks */, 319 | 3A22A1E91CCE1B4F00AC78DF /* Resources */, 320 | ); 321 | buildRules = ( 322 | ); 323 | dependencies = ( 324 | 3A22A1ED1CCE1B4F00AC78DF /* PBXTargetDependency */, 325 | ); 326 | name = ClosuresTestUITests; 327 | productName = ClosuresTestUITests; 328 | productReference = 3A22A1EB1CCE1B4F00AC78DF /* ClosuresTestUITests.xctest */; 329 | productType = "com.apple.product-type.bundle.ui-testing"; 330 | }; 331 | /* End PBXNativeTarget section */ 332 | 333 | /* Begin PBXProject section */ 334 | 3A22A1A01CCA205000AC78DF /* Project object */ = { 335 | isa = PBXProject; 336 | attributes = { 337 | LastSwiftUpdateCheck = 0730; 338 | LastUpgradeCheck = 0730; 339 | ORGANIZATIONNAME = zhuo; 340 | TargetAttributes = { 341 | 3A22A1A81CCA205000AC78DF = { 342 | CreatedOnToolsVersion = 7.3; 343 | LastSwiftMigration = 0800; 344 | }; 345 | 3A22A1B21CCA205000AC78DF = { 346 | CreatedOnToolsVersion = 7.3; 347 | LastSwiftMigration = 0800; 348 | }; 349 | 3A22A1D71CCE1B4F00AC78DF = { 350 | CreatedOnToolsVersion = 7.3; 351 | }; 352 | 3A22A1EA1CCE1B4F00AC78DF = { 353 | CreatedOnToolsVersion = 7.3; 354 | TestTargetID = 3A22A1D71CCE1B4F00AC78DF; 355 | }; 356 | }; 357 | }; 358 | buildConfigurationList = 3A22A1A31CCA205000AC78DF /* Build configuration list for PBXProject "ClosuresKit" */; 359 | compatibilityVersion = "Xcode 3.2"; 360 | developmentRegion = English; 361 | hasScannedForEncodings = 0; 362 | knownRegions = ( 363 | en, 364 | Base, 365 | ); 366 | mainGroup = 3A22A19F1CCA205000AC78DF; 367 | productRefGroup = 3A22A1AA1CCA205000AC78DF /* Products */; 368 | projectDirPath = ""; 369 | projectRoot = ""; 370 | targets = ( 371 | 3A22A1A81CCA205000AC78DF /* ClosuresKit */, 372 | 3A22A1B21CCA205000AC78DF /* ClosuresKitTests */, 373 | 3A22A1D71CCE1B4F00AC78DF /* ClosuresTest */, 374 | 3A22A1EA1CCE1B4F00AC78DF /* ClosuresTestUITests */, 375 | ); 376 | }; 377 | /* End PBXProject section */ 378 | 379 | /* Begin PBXResourcesBuildPhase section */ 380 | 3A22A1A71CCA205000AC78DF /* Resources */ = { 381 | isa = PBXResourcesBuildPhase; 382 | buildActionMask = 2147483647; 383 | files = ( 384 | ); 385 | runOnlyForDeploymentPostprocessing = 0; 386 | }; 387 | 3A22A1B11CCA205000AC78DF /* Resources */ = { 388 | isa = PBXResourcesBuildPhase; 389 | buildActionMask = 2147483647; 390 | files = ( 391 | ); 392 | runOnlyForDeploymentPostprocessing = 0; 393 | }; 394 | 3A22A1D61CCE1B4F00AC78DF /* Resources */ = { 395 | isa = PBXResourcesBuildPhase; 396 | buildActionMask = 2147483647; 397 | files = ( 398 | 3A22A1E51CCE1B4F00AC78DF /* LaunchScreen.storyboard in Resources */, 399 | 3A22A1E21CCE1B4F00AC78DF /* Assets.xcassets in Resources */, 400 | 3A22A1E01CCE1B4F00AC78DF /* Main.storyboard in Resources */, 401 | ); 402 | runOnlyForDeploymentPostprocessing = 0; 403 | }; 404 | 3A22A1E91CCE1B4F00AC78DF /* Resources */ = { 405 | isa = PBXResourcesBuildPhase; 406 | buildActionMask = 2147483647; 407 | files = ( 408 | ); 409 | runOnlyForDeploymentPostprocessing = 0; 410 | }; 411 | /* End PBXResourcesBuildPhase section */ 412 | 413 | /* Begin PBXSourcesBuildPhase section */ 414 | 3A22A1A41CCA205000AC78DF /* Sources */ = { 415 | isa = PBXSourcesBuildPhase; 416 | buildActionMask = 2147483647; 417 | files = ( 418 | 3A22A1D11CCE035100AC78DF /* NSTimerExtension.swift in Sources */, 419 | 3A22A1CD1CCDEF1500AC78DF /* ObserverNotificationExtension.swift in Sources */, 420 | 3A22A1C41CCA226800AC78DF /* SequenceTypeExtension.swift in Sources */, 421 | 3A22A1C91CCCFB3800AC78DF /* NSObjectAssociatedExtension.swift in Sources */, 422 | 3A42CF561CDFA7620048C58F /* GestureUIViewExtension.swift in Sources */, 423 | 3A42CF521CDF95810048C58F /* UIGesturePromiseExntension.swift in Sources */, 424 | 3A22A2021CCE5B6600AC78DF /* UIControlExtension.swift in Sources */, 425 | 3A42CF4E1CDF92FA0048C58F /* CSGesturePromise.swift in Sources */, 426 | ); 427 | runOnlyForDeploymentPostprocessing = 0; 428 | }; 429 | 3A22A1AF1CCA205000AC78DF /* Sources */ = { 430 | isa = PBXSourcesBuildPhase; 431 | buildActionMask = 2147483647; 432 | files = ( 433 | 3A22A1CB1CCD038500AC78DF /* AssocaitedObjectTests.swift in Sources */, 434 | 3A22A1CF1CCDFDC600AC78DF /* ObserverNotificationTests.swift in Sources */, 435 | 3A22A1C71CCA28D200AC78DF /* SequenceExtensionTests.swift in Sources */, 436 | 3A22A1D31CCE0F4800AC78DF /* TimerTests.swift in Sources */, 437 | ); 438 | runOnlyForDeploymentPostprocessing = 0; 439 | }; 440 | 3A22A1D41CCE1B4F00AC78DF /* Sources */ = { 441 | isa = PBXSourcesBuildPhase; 442 | buildActionMask = 2147483647; 443 | files = ( 444 | 3A22A2041CCE753F00AC78DF /* UIControlViewController.swift in Sources */, 445 | 3A22A1DB1CCE1B4F00AC78DF /* AppDelegate.swift in Sources */, 446 | 3A42CF541CDFA5BD0048C58F /* UIGestureViewController.swift in Sources */, 447 | ); 448 | runOnlyForDeploymentPostprocessing = 0; 449 | }; 450 | 3A22A1E71CCE1B4F00AC78DF /* Sources */ = { 451 | isa = PBXSourcesBuildPhase; 452 | buildActionMask = 2147483647; 453 | files = ( 454 | 3A22A1F01CCE1B4F00AC78DF /* ClosuresTestUITests.swift in Sources */, 455 | ); 456 | runOnlyForDeploymentPostprocessing = 0; 457 | }; 458 | /* End PBXSourcesBuildPhase section */ 459 | 460 | /* Begin PBXTargetDependency section */ 461 | 3A22A1B61CCA205000AC78DF /* PBXTargetDependency */ = { 462 | isa = PBXTargetDependency; 463 | target = 3A22A1A81CCA205000AC78DF /* ClosuresKit */; 464 | targetProxy = 3A22A1B51CCA205000AC78DF /* PBXContainerItemProxy */; 465 | }; 466 | 3A22A1ED1CCE1B4F00AC78DF /* PBXTargetDependency */ = { 467 | isa = PBXTargetDependency; 468 | target = 3A22A1D71CCE1B4F00AC78DF /* ClosuresTest */; 469 | targetProxy = 3A22A1EC1CCE1B4F00AC78DF /* PBXContainerItemProxy */; 470 | }; 471 | 3A22A1FB1CCE1B6000AC78DF /* PBXTargetDependency */ = { 472 | isa = PBXTargetDependency; 473 | target = 3A22A1A81CCA205000AC78DF /* ClosuresKit */; 474 | targetProxy = 3A22A1FA1CCE1B6000AC78DF /* PBXContainerItemProxy */; 475 | }; 476 | /* End PBXTargetDependency section */ 477 | 478 | /* Begin PBXVariantGroup section */ 479 | 3A22A1DE1CCE1B4F00AC78DF /* Main.storyboard */ = { 480 | isa = PBXVariantGroup; 481 | children = ( 482 | 3A22A1DF1CCE1B4F00AC78DF /* Base */, 483 | ); 484 | name = Main.storyboard; 485 | sourceTree = ""; 486 | }; 487 | 3A22A1E31CCE1B4F00AC78DF /* LaunchScreen.storyboard */ = { 488 | isa = PBXVariantGroup; 489 | children = ( 490 | 3A22A1E41CCE1B4F00AC78DF /* Base */, 491 | ); 492 | name = LaunchScreen.storyboard; 493 | sourceTree = ""; 494 | }; 495 | /* End PBXVariantGroup section */ 496 | 497 | /* Begin XCBuildConfiguration section */ 498 | 3A22A1BB1CCA205000AC78DF /* Debug */ = { 499 | isa = XCBuildConfiguration; 500 | buildSettings = { 501 | ALWAYS_SEARCH_USER_PATHS = NO; 502 | CLANG_ANALYZER_NONNULL = YES; 503 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 504 | CLANG_CXX_LIBRARY = "libc++"; 505 | CLANG_ENABLE_MODULES = YES; 506 | CLANG_ENABLE_OBJC_ARC = YES; 507 | CLANG_WARN_BOOL_CONVERSION = YES; 508 | CLANG_WARN_CONSTANT_CONVERSION = YES; 509 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 510 | CLANG_WARN_EMPTY_BODY = YES; 511 | CLANG_WARN_ENUM_CONVERSION = YES; 512 | CLANG_WARN_INT_CONVERSION = YES; 513 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 514 | CLANG_WARN_UNREACHABLE_CODE = YES; 515 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 516 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 517 | COPY_PHASE_STRIP = NO; 518 | CURRENT_PROJECT_VERSION = 1; 519 | DEBUG_INFORMATION_FORMAT = dwarf; 520 | ENABLE_STRICT_OBJC_MSGSEND = YES; 521 | ENABLE_TESTABILITY = YES; 522 | GCC_C_LANGUAGE_STANDARD = gnu99; 523 | GCC_DYNAMIC_NO_PIC = NO; 524 | GCC_NO_COMMON_BLOCKS = YES; 525 | GCC_OPTIMIZATION_LEVEL = 0; 526 | GCC_PREPROCESSOR_DEFINITIONS = ( 527 | "DEBUG=1", 528 | "$(inherited)", 529 | ); 530 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 531 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 532 | GCC_WARN_UNDECLARED_SELECTOR = YES; 533 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 534 | GCC_WARN_UNUSED_FUNCTION = YES; 535 | GCC_WARN_UNUSED_VARIABLE = YES; 536 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 537 | MTL_ENABLE_DEBUG_INFO = YES; 538 | ONLY_ACTIVE_ARCH = YES; 539 | SDKROOT = iphoneos; 540 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 541 | TARGETED_DEVICE_FAMILY = "1,2"; 542 | VERSIONING_SYSTEM = "apple-generic"; 543 | VERSION_INFO_PREFIX = ""; 544 | }; 545 | name = Debug; 546 | }; 547 | 3A22A1BC1CCA205000AC78DF /* Release */ = { 548 | isa = XCBuildConfiguration; 549 | buildSettings = { 550 | ALWAYS_SEARCH_USER_PATHS = NO; 551 | CLANG_ANALYZER_NONNULL = YES; 552 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 553 | CLANG_CXX_LIBRARY = "libc++"; 554 | CLANG_ENABLE_MODULES = YES; 555 | CLANG_ENABLE_OBJC_ARC = YES; 556 | CLANG_WARN_BOOL_CONVERSION = YES; 557 | CLANG_WARN_CONSTANT_CONVERSION = YES; 558 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 559 | CLANG_WARN_EMPTY_BODY = YES; 560 | CLANG_WARN_ENUM_CONVERSION = YES; 561 | CLANG_WARN_INT_CONVERSION = YES; 562 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 563 | CLANG_WARN_UNREACHABLE_CODE = YES; 564 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 565 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 566 | COPY_PHASE_STRIP = NO; 567 | CURRENT_PROJECT_VERSION = 1; 568 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 569 | ENABLE_NS_ASSERTIONS = NO; 570 | ENABLE_STRICT_OBJC_MSGSEND = YES; 571 | GCC_C_LANGUAGE_STANDARD = gnu99; 572 | GCC_NO_COMMON_BLOCKS = YES; 573 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 574 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 575 | GCC_WARN_UNDECLARED_SELECTOR = YES; 576 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 577 | GCC_WARN_UNUSED_FUNCTION = YES; 578 | GCC_WARN_UNUSED_VARIABLE = YES; 579 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 580 | MTL_ENABLE_DEBUG_INFO = NO; 581 | SDKROOT = iphoneos; 582 | TARGETED_DEVICE_FAMILY = "1,2"; 583 | VALIDATE_PRODUCT = YES; 584 | VERSIONING_SYSTEM = "apple-generic"; 585 | VERSION_INFO_PREFIX = ""; 586 | }; 587 | name = Release; 588 | }; 589 | 3A22A1BE1CCA205000AC78DF /* Debug */ = { 590 | isa = XCBuildConfiguration; 591 | buildSettings = { 592 | CLANG_ENABLE_MODULES = YES; 593 | DEFINES_MODULE = YES; 594 | DYLIB_COMPATIBILITY_VERSION = 1; 595 | DYLIB_CURRENT_VERSION = 1; 596 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 597 | INFOPLIST_FILE = ClosuresKit/Info.plist; 598 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 599 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 600 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 601 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresKit; 602 | PRODUCT_NAME = "$(TARGET_NAME)"; 603 | SKIP_INSTALL = YES; 604 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 605 | SWIFT_VERSION = 2.3; 606 | }; 607 | name = Debug; 608 | }; 609 | 3A22A1BF1CCA205000AC78DF /* Release */ = { 610 | isa = XCBuildConfiguration; 611 | buildSettings = { 612 | CLANG_ENABLE_MODULES = YES; 613 | DEFINES_MODULE = YES; 614 | DYLIB_COMPATIBILITY_VERSION = 1; 615 | DYLIB_CURRENT_VERSION = 1; 616 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 617 | INFOPLIST_FILE = ClosuresKit/Info.plist; 618 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 619 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 620 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 621 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresKit; 622 | PRODUCT_NAME = "$(TARGET_NAME)"; 623 | SKIP_INSTALL = YES; 624 | SWIFT_VERSION = 2.3; 625 | }; 626 | name = Release; 627 | }; 628 | 3A22A1C11CCA205000AC78DF /* Debug */ = { 629 | isa = XCBuildConfiguration; 630 | buildSettings = { 631 | INFOPLIST_FILE = ClosuresKitTests/Info.plist; 632 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 633 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresKitTests; 634 | PRODUCT_NAME = "$(TARGET_NAME)"; 635 | SWIFT_VERSION = 2.3; 636 | }; 637 | name = Debug; 638 | }; 639 | 3A22A1C21CCA205000AC78DF /* Release */ = { 640 | isa = XCBuildConfiguration; 641 | buildSettings = { 642 | INFOPLIST_FILE = ClosuresKitTests/Info.plist; 643 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 644 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresKitTests; 645 | PRODUCT_NAME = "$(TARGET_NAME)"; 646 | SWIFT_VERSION = 2.3; 647 | }; 648 | name = Release; 649 | }; 650 | 3A22A1F31CCE1B4F00AC78DF /* Debug */ = { 651 | isa = XCBuildConfiguration; 652 | buildSettings = { 653 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 654 | EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; 655 | INFOPLIST_FILE = ClosuresTest/Info.plist; 656 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 657 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 658 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresTest; 659 | PRODUCT_NAME = "$(TARGET_NAME)"; 660 | }; 661 | name = Debug; 662 | }; 663 | 3A22A1F41CCE1B4F00AC78DF /* Release */ = { 664 | isa = XCBuildConfiguration; 665 | buildSettings = { 666 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 667 | EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; 668 | INFOPLIST_FILE = ClosuresTest/Info.plist; 669 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 670 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 671 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresTest; 672 | PRODUCT_NAME = "$(TARGET_NAME)"; 673 | }; 674 | name = Release; 675 | }; 676 | 3A22A1F61CCE1B4F00AC78DF /* Debug */ = { 677 | isa = XCBuildConfiguration; 678 | buildSettings = { 679 | INFOPLIST_FILE = ClosuresTestUITests/Info.plist; 680 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 681 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresTestUITests; 682 | PRODUCT_NAME = "$(TARGET_NAME)"; 683 | TEST_TARGET_NAME = ClosuresTest; 684 | }; 685 | name = Debug; 686 | }; 687 | 3A22A1F71CCE1B4F00AC78DF /* Release */ = { 688 | isa = XCBuildConfiguration; 689 | buildSettings = { 690 | INFOPLIST_FILE = ClosuresTestUITests/Info.plist; 691 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 692 | PRODUCT_BUNDLE_IDENTIFIER = nice.ClosuresTestUITests; 693 | PRODUCT_NAME = "$(TARGET_NAME)"; 694 | TEST_TARGET_NAME = ClosuresTest; 695 | }; 696 | name = Release; 697 | }; 698 | /* End XCBuildConfiguration section */ 699 | 700 | /* Begin XCConfigurationList section */ 701 | 3A22A1A31CCA205000AC78DF /* Build configuration list for PBXProject "ClosuresKit" */ = { 702 | isa = XCConfigurationList; 703 | buildConfigurations = ( 704 | 3A22A1BB1CCA205000AC78DF /* Debug */, 705 | 3A22A1BC1CCA205000AC78DF /* Release */, 706 | ); 707 | defaultConfigurationIsVisible = 0; 708 | defaultConfigurationName = Release; 709 | }; 710 | 3A22A1BD1CCA205000AC78DF /* Build configuration list for PBXNativeTarget "ClosuresKit" */ = { 711 | isa = XCConfigurationList; 712 | buildConfigurations = ( 713 | 3A22A1BE1CCA205000AC78DF /* Debug */, 714 | 3A22A1BF1CCA205000AC78DF /* Release */, 715 | ); 716 | defaultConfigurationIsVisible = 0; 717 | defaultConfigurationName = Release; 718 | }; 719 | 3A22A1C01CCA205000AC78DF /* Build configuration list for PBXNativeTarget "ClosuresKitTests" */ = { 720 | isa = XCConfigurationList; 721 | buildConfigurations = ( 722 | 3A22A1C11CCA205000AC78DF /* Debug */, 723 | 3A22A1C21CCA205000AC78DF /* Release */, 724 | ); 725 | defaultConfigurationIsVisible = 0; 726 | defaultConfigurationName = Release; 727 | }; 728 | 3A22A1F21CCE1B4F00AC78DF /* Build configuration list for PBXNativeTarget "ClosuresTest" */ = { 729 | isa = XCConfigurationList; 730 | buildConfigurations = ( 731 | 3A22A1F31CCE1B4F00AC78DF /* Debug */, 732 | 3A22A1F41CCE1B4F00AC78DF /* Release */, 733 | ); 734 | defaultConfigurationIsVisible = 0; 735 | defaultConfigurationName = Release; 736 | }; 737 | 3A22A1F51CCE1B4F00AC78DF /* Build configuration list for PBXNativeTarget "ClosuresTestUITests" */ = { 738 | isa = XCConfigurationList; 739 | buildConfigurations = ( 740 | 3A22A1F61CCE1B4F00AC78DF /* Debug */, 741 | 3A22A1F71CCE1B4F00AC78DF /* Release */, 742 | ); 743 | defaultConfigurationIsVisible = 0; 744 | defaultConfigurationName = Release; 745 | }; 746 | /* End XCConfigurationList section */ 747 | }; 748 | rootObject = 3A22A1A01CCA205000AC78DF /* Project object */; 749 | } 750 | -------------------------------------------------------------------------------- /ClosuresKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ClosuresKit.xcodeproj/project.xcworkspace/xcshareddata/ClosuresKit.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "161CA4A1124386E7D6265D9FD62450BEF35EB0B6", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "161CA4A1124386E7D6265D9FD62450BEF35EB0B6" : 0, 8 | "07254622BEE060C7EAAC3369009E9ED24D387F35" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "368B091F-DCD6-4D00-AE48-67BEC991249B", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "161CA4A1124386E7D6265D9FD62450BEF35EB0B6" : "ClosuresKit\/", 13 | "07254622BEE060C7EAAC3369009E9ED24D387F35" : "" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "ClosuresKit", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "ClosuresKit.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/trawor\/XToDo.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "07254622BEE060C7EAAC3369009E9ED24D387F35" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/lacklock\/ClosuresKit.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "161CA4A1124386E7D6265D9FD62450BEF35EB0B6" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /ClosuresKit.xcodeproj/xcshareddata/xcschemes/ClosuresKit.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /ClosuresKit.xcodeproj/xcuserdata/zz.xcuserdatad/xcschemes/ClosuresTest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /ClosuresKit.xcodeproj/xcuserdata/zz.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ClosuresKit.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | ClosuresTest.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 3A22A1A81CCA205000AC78DF 21 | 22 | primary 23 | 24 | 25 | 3A22A1B21CCA205000AC78DF 26 | 27 | primary 28 | 29 | 30 | 3A22A1D71CCE1B4F00AC78DF 31 | 32 | primary 33 | 34 | 35 | 3A22A1EA1CCE1B4F00AC78DF 36 | 37 | primary 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ClosuresKit/CSGesturePromise.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NCGesturePromise.swift 3 | // NiceGesture 4 | // 5 | // Created by 卓同学 on 16/4/3. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | public class CSGesturePromise: NSObject { 13 | 14 | public typealias csGestureHandler = (gestureRecognizer:T)->Void 15 | 16 | var beganHandler:csGestureHandler = { _ in } 17 | var cancelledHandler:csGestureHandler = { _ in } 18 | var changedHandler:csGestureHandler = { _ in } 19 | var endedHandler:csGestureHandler = { _ in } 20 | var failedHandler:csGestureHandler = { _ in } 21 | 22 | 23 | override init(){ 24 | super.init() 25 | } 26 | 27 | func gesureRecognizerHandler(gestureRecognizer:UIGestureRecognizer){ 28 | switch gestureRecognizer.state { 29 | case .Began: 30 | beganHandler(gestureRecognizer: gestureRecognizer as! T) 31 | case .Cancelled: 32 | cancelledHandler(gestureRecognizer: gestureRecognizer as! T) 33 | case .Changed: 34 | changedHandler(gestureRecognizer: gestureRecognizer as! T) 35 | case .Ended: 36 | endedHandler(gestureRecognizer: gestureRecognizer as! T) 37 | case .Failed: 38 | failedHandler(gestureRecognizer: gestureRecognizer as! T) 39 | case .Possible: 40 | break 41 | } 42 | } 43 | 44 | /** 45 | one handler for many states 46 | 47 | - parameter states: UIGestureRecognizerStates 48 | 49 | */ 50 | public func whenStatesHappend(states:[UIGestureRecognizerState],handler:csGestureHandler)->CSGesturePromise{ 51 | for state in states{ 52 | switch state { 53 | case .Began: 54 | beganHandler=handler 55 | case .Cancelled: 56 | cancelledHandler=handler 57 | case .Changed: 58 | changedHandler=handler 59 | case .Ended: 60 | endedHandler=handler 61 | case .Failed: 62 | failedHandler=handler 63 | case .Possible: 64 | break 65 | } 66 | } 67 | return self 68 | } 69 | 70 | public func whenBegan(handler:csGestureHandler)->CSGesturePromise{ 71 | beganHandler=handler 72 | return self 73 | } 74 | 75 | public func whenCancelled(handler:csGestureHandler)->CSGesturePromise{ 76 | cancelledHandler=handler 77 | return self 78 | } 79 | 80 | public func whenChanged(handler:csGestureHandler)->CSGesturePromise{ 81 | changedHandler=handler 82 | return self 83 | } 84 | 85 | public func whenEnded(handler:csGestureHandler)->CSGesturePromise{ 86 | endedHandler=handler 87 | return self 88 | } 89 | 90 | public func whenFailed(handler:csGestureHandler)->CSGesturePromise{ 91 | failedHandler=handler 92 | return self 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /ClosuresKit/ClosuresKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // ClosuresKit.h 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/22. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ClosuresKit. 12 | FOUNDATION_EXPORT double ClosuresKitVersionNumber; 13 | 14 | //! Project version string for ClosuresKit. 15 | FOUNDATION_EXPORT const unsigned char ClosuresKitVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ClosuresKit/GestureUIViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GestureUIViewExtension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/5/9. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public extension UIView{ 12 | 13 | public func cs_addTapGesture(@noescape config:(gestureRecognizer:UITapGestureRecognizer)->()={ _ in })->CSGesturePromise{ 14 | let recognizer = UITapGestureRecognizer(config: config) 15 | addGestureRecognizer(recognizer) 16 | return recognizer.promise 17 | } 18 | 19 | public func cs_whenTapped(handler:(tapGestureRecognizer:UITapGestureRecognizer)->()){ 20 | cs_addTapGesture().whenEnded(handler) 21 | } 22 | 23 | public func cs_addLongPressGesture(@noescape config:(gestureRecognizer:UILongPressGestureRecognizer)->()={ _ in })->CSGesturePromise{ 24 | let recognizer = UILongPressGestureRecognizer(config: config) 25 | addGestureRecognizer(recognizer) 26 | return recognizer.promise 27 | } 28 | 29 | public func cs_addPanGesture(@noescape config:(gestureRecognizer:UIPanGestureRecognizer)->()={ _ in })->CSGesturePromise{ 30 | let recognizer = UIPanGestureRecognizer(config: config) 31 | addGestureRecognizer(recognizer) 32 | return recognizer.promise 33 | } 34 | 35 | public func cs_addSwipeGesture(@noescape config:(gestureRecognizer:UISwipeGestureRecognizer)->()={ _ in })->CSGesturePromise{ 36 | let recognizer = UISwipeGestureRecognizer(config: config) 37 | addGestureRecognizer(recognizer) 38 | return recognizer.promise 39 | } 40 | 41 | public func cs_whenSwipedInDirection(direction:UISwipeGestureRecognizerDirection,gestureRecognizer:(gestureRecognizer:UISwipeGestureRecognizer)->()){ 42 | cs_addSwipeGesture { (swipeGestureRecognizer) in 43 | swipeGestureRecognizer.direction=direction 44 | }.whenEnded(gestureRecognizer) 45 | } 46 | 47 | public func cs_addPinchGesture(@noescape config:(gestureRecognizer:UIPinchGestureRecognizer)->()={ _ in })->CSGesturePromise{ 48 | let recognizer = UIPinchGestureRecognizer(config: config) 49 | addGestureRecognizer(recognizer) 50 | return recognizer.promise 51 | } 52 | 53 | public func cs_addRotationGesture(@noescape config:(gestureRecognizer:UIRotationGestureRecognizer)->()={ _ in })->CSGesturePromise{ 54 | let recognizer = UIRotationGestureRecognizer(config: config) 55 | addGestureRecognizer(recognizer) 56 | return recognizer.promise 57 | } 58 | 59 | public func cs_addScreenEdgePanGesture(@noescape config:(gestureRecognizer:UIScreenEdgePanGestureRecognizer)->()={ _ in })->CSGesturePromise{ 60 | let recognizer = UIScreenEdgePanGestureRecognizer(config: config) 61 | addGestureRecognizer(recognizer) 62 | return recognizer.promise 63 | } 64 | } -------------------------------------------------------------------------------- /ClosuresKit/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.1 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ClosuresKit/NSObjectAssociatedExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSObjectAssociatedExtension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/24. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension NSObject{ 12 | 13 | // MARK: - retain 14 | /** 15 | Strongly associates an object with the reciever. 16 | 17 | */ 18 | public func cs_associateValue(value:AnyObject!,key:UnsafePointer){ 19 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 20 | } 21 | 22 | /** 23 | Strongly associates an object with the reciever. 24 | 25 | */ 26 | public class func cs_associateValue(value:AnyObject!,key:UnsafePointer){ 27 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 28 | } 29 | 30 | /** 31 | Strongly, thread-safely associates an object with the reciever. 32 | 33 | */ 34 | public func cs_atomicallyAssociateValue(value:AnyObject!,key:UnsafePointer){ 35 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_RETAIN) 36 | } 37 | 38 | /** 39 | Strongly, thread-safely associates an object with the reciever. 40 | 41 | */ 42 | public class func cs_atomicallyAssociateValue(value:AnyObject!,key:UnsafePointer){ 43 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_RETAIN) 44 | } 45 | 46 | // MARK: - copy 47 | /** 48 | Associates a copy of an object with the reciever. 49 | 50 | */ 51 | public func cs_associateCopyOfValue(value:AnyObject!,key:UnsafePointer){ 52 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_COPY_NONATOMIC) 53 | } 54 | 55 | /** 56 | Associates a copy of an object with the reciever. 57 | 58 | */ 59 | public class func cs_associateCopyOfValue(value:AnyObject!,key:UnsafePointer){ 60 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_COPY_NONATOMIC) 61 | } 62 | 63 | /** 64 | Thread-safely associates a copy of an object with the reciever. 65 | 66 | */ 67 | public func cs_atomicallyAassociateCopyOfValue(value:AnyObject!,key:UnsafePointer){ 68 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_COPY) 69 | } 70 | 71 | /** 72 | Thread-safely associates a copy of an object with the reciever. 73 | 74 | */ 75 | public class func cs_atomicallyAssociateCopyOfValue(value:AnyObject!,key:UnsafePointer){ 76 | objc_setAssociatedObject(self, key, value, .OBJC_ASSOCIATION_COPY) 77 | } 78 | 79 | // MARK: - weak 80 | 81 | /** 82 | Weakly associates an object with the reciever. 83 | 84 | */ 85 | public func cs_weaklyAssociateValue(value:AnyObject!,key:UnsafePointer){ 86 | var assocObject = objc_getAssociatedObject(self, key) as? _CSWeakAssociatedObject 87 | if assocObject == nil { 88 | assocObject=_CSWeakAssociatedObject() 89 | cs_associateValue(assocObject, key: key) 90 | } 91 | assocObject!.value=value 92 | } 93 | 94 | /** 95 | Weakly associates an object with the reciever. 96 | 97 | */ 98 | public class func cs_weaklyAssociateValue(value:AnyObject!,key:UnsafePointer){ 99 | var assocObject = objc_getAssociatedObject(self, key) as? _CSWeakAssociatedObject 100 | if assocObject == nil { 101 | assocObject=_CSWeakAssociatedObject() 102 | cs_associateValue(assocObject, key: key) 103 | } 104 | assocObject!.value=value 105 | } 106 | 107 | 108 | // MARK: - get associate Value 109 | public func cs_associateValueForKey(key:UnsafePointer)->AnyObject?{ 110 | let value = objc_getAssociatedObject(self, key) 111 | if value != nil && value is _CSWeakAssociatedObject{ 112 | if let _value = (value as! _CSWeakAssociatedObject).value{ 113 | return _value 114 | }else{ 115 | preconditionFailure("value is nil") 116 | } 117 | } 118 | return value 119 | } 120 | 121 | public class func cs_associateValueForKey(key:UnsafePointer)->AnyObject{ 122 | let value = objc_getAssociatedObject(self, key) 123 | if value != nil && value is _CSWeakAssociatedObject{ 124 | if let _value = (value as! _CSWeakAssociatedObject).value{ 125 | return _value 126 | }else{ 127 | preconditionFailure("value is nil") 128 | } 129 | } 130 | return value 131 | } 132 | // MARK: - remove 133 | public func cs_removeAllAssociatedObjects(){ 134 | objc_removeAssociatedObjects(self) 135 | } 136 | 137 | public class func cs_removeAllAssociatedObjects(){ 138 | objc_removeAssociatedObjects(self) 139 | } 140 | } 141 | 142 | class _CSWeakAssociatedObject:NSObject{ 143 | weak var value:AnyObject? 144 | } 145 | -------------------------------------------------------------------------------- /ClosuresKit/NSTimerExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSTimerExtension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | private var CSTimerHandlerKey = "CSTimerHandlerKey" 12 | 13 | extension NSTimer{ 14 | 15 | public class func cs_scheduledTimerWithTimeInterval(timeInterval:NSTimeInterval,repeats:Bool,userInfo:NSDictionary?,mode:String=NSDefaultRunLoopMode,handler:(timer:NSTimer)->Void)-> NSTimer { 16 | let timer = NSTimer(timeInterval: timeInterval, target: self, selector: #selector(NSTimer.timerHandler(_:)), userInfo: userInfo, repeats: repeats) 17 | timer.handler=handler 18 | NSRunLoop.currentRunLoop().addTimer(timer, forMode: mode) 19 | return timer 20 | } 21 | 22 | class func timerHandler(timer:NSTimer){ 23 | timer.handler(timer: timer) 24 | } 25 | 26 | // MARK: - computed propery 27 | private var handler:(timer:NSTimer)->Void{ 28 | get{ 29 | return timeHandlerContainer.handler 30 | } 31 | set{ 32 | timeHandlerContainer.handler=newValue 33 | } 34 | } 35 | 36 | private var timeHandlerContainer:NSTimerHandlerContainer{ 37 | get{ 38 | if let container = cs_associateValueForKey(&CSTimerHandlerKey) as? NSTimerHandlerContainer { 39 | return container 40 | }else{ 41 | let container = NSTimerHandlerContainer() 42 | cs_associateValue(container, key: &CSTimerHandlerKey) 43 | return container 44 | } 45 | } 46 | } 47 | } 48 | 49 | class NSTimerHandlerContainer:NSObject{ 50 | var handler:(timer:NSTimer)->Void = { _ in } 51 | } -------------------------------------------------------------------------------- /ClosuresKit/ObserverNotificationExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ObserverNotificationExtension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | private var CSNotificationHandlersKey = "CSNotificationHandlers" 12 | 13 | extension NSObject{ 14 | 15 | public typealias csNotificationHandler = (notification:NSNotification)->Void 16 | 17 | public func cs_addNotificationObserverForName(name aName: String, object anObject: AnyObject?,handler:csNotificationHandler){ 18 | NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(NSObject.notificationHandler(_:)), name: aName, object: anObject) 19 | csNotificationHandlers[aName]=handler 20 | } 21 | 22 | public func cs_removeNotificationObserverForName(name aName:String){ 23 | NSNotificationCenter.defaultCenter().removeObserver(self, name: aName, object: nil) 24 | } 25 | 26 | func notificationHandler(notification:NSNotification){ 27 | if let handler = csNotificationHandlers[notification.name]{ 28 | handler(notification: notification) 29 | } 30 | } 31 | 32 | // MARK: - computed propery 33 | private var csNotificationHandlers:[String:csNotificationHandler]{ 34 | get{ 35 | return handlerContainer.handlers 36 | } 37 | set{ 38 | handlerContainer.handlers=newValue 39 | } 40 | } 41 | 42 | private var handlerContainer:NotificationHandlerContainer{ 43 | get{ 44 | if let container = cs_associateValueForKey(&CSNotificationHandlersKey) as? NotificationHandlerContainer { 45 | return container 46 | }else{ 47 | let container = NotificationHandlerContainer() 48 | cs_associateValue(container, key: &CSNotificationHandlersKey) 49 | return container 50 | } 51 | } 52 | } 53 | 54 | } 55 | 56 | class NotificationHandlerContainer:NSObject{ 57 | var handlers=[String:csNotificationHandler]() 58 | } -------------------------------------------------------------------------------- /ClosuresKit/SequenceTypeExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SequenceTypeExtension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/22. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension SequenceType{ 12 | 13 | /** 14 | loops through the sequeence to find the match element 15 | it's will stop and return on the first match 16 | if thers isn't any element match, return nil 17 | */ 18 | public func cs_match(@noescape condition:(Self.Generator.Element) throws -> Bool) rethrows -> Self.Generator.Element?{ 19 | for element in self { 20 | if try condition(element) { 21 | return element 22 | } 23 | } 24 | return nil 25 | } 26 | 27 | /** 28 | Loops through the sequeence to find whether any object matches the closure. 29 | 30 | */ 31 | public func cs_any(@noescape condition:(Self.Generator.Element) throws -> Bool) rethrows -> Bool{ 32 | for element in self { 33 | if try condition(element) { 34 | return true 35 | } 36 | } 37 | return false 38 | } 39 | 40 | 41 | /** 42 | Loops through an sequeence to find whether all element match the closure 43 | 44 | */ 45 | public func cs_all(@noescape condition:(Self.Generator.Element) throws -> Bool) rethrows -> Bool{ 46 | for element in self { 47 | if try !condition(element) { 48 | return false 49 | } 50 | } 51 | return true 52 | } 53 | 54 | /** 55 | Loops through an sequeence to find whether no element match the closure 56 | 57 | */ 58 | public func cs_none(@noescape condition:(Self.Generator.Element) throws -> Bool) rethrows -> Bool{ 59 | for element in self { 60 | if try condition(element) { 61 | return false 62 | } 63 | } 64 | return true 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /ClosuresKit/UIControlExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIControlExtension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | private var CSControlEventsHandlerKey = "CSControlEventsHandlerKey" 12 | 13 | extension UIControl{ 14 | 15 | typealias CSEventContainerDict = [String:CSControlHandlerContainer] 16 | 17 | public func cs_addEventHandlerForEvents(event:UIControlEvents,handler:(sender:UIControl)->Void){ 18 | let container = CSControlHandlerContainer(handler: handler) 19 | handlers[event.cs_hashValue]=container 20 | addTarget(container, action: #selector(CSControlHandlerContainer.invoke(_:)),forControlEvents: event) 21 | } 22 | 23 | var handlers:CSEventContainerDict{ 24 | get{ 25 | if let container = cs_associateValueForKey(&CSControlEventsHandlerKey) as? CSEventContainerDict { 26 | return container 27 | }else{ 28 | let container = [String:CSControlHandlerContainer]() 29 | cs_associateValue(container, key: &CSControlEventsHandlerKey) 30 | return container 31 | } 32 | } 33 | set{ 34 | cs_associateValue(newValue, key: &CSControlEventsHandlerKey) 35 | } 36 | } 37 | 38 | } 39 | 40 | class CSControlHandlerContainer:NSObject{ 41 | var handler:(UIControl)->Void = { _ in } 42 | 43 | init(handler:(sender:UIControl)->Void) { 44 | self.handler = handler 45 | super.init() 46 | } 47 | 48 | func invoke(sender:UIControl){ 49 | handler(sender) 50 | } 51 | 52 | } 53 | 54 | extension UIControlEvents{ 55 | var cs_hashValue:String{ 56 | get { 57 | return String(self) 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /ClosuresKit/UIGesturePromiseExntension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIGesturePromiseExntension.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/5/8. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public protocol CSGesturePromisable:class { 12 | init(target: AnyObject?, action: Selector) 13 | } 14 | 15 | private var CSGesturePromisableKey = "CSGesturePromisableKey" 16 | 17 | extension CSGesturePromisable where Self:UIGestureRecognizer{ 18 | 19 | var promise:CSGesturePromise{ 20 | get{ 21 | return cs_associateValueForKey(&CSGesturePromisableKey) as! CSGesturePromise 22 | } 23 | set{ 24 | cs_associateValue(newValue, key: &CSGesturePromisableKey) 25 | } 26 | } 27 | 28 | init(@noescape config:(gestureRecognizer:Self)->()={ _ in }){ 29 | typealias Gesture = Self 30 | let promise=CSGesturePromise() 31 | self.init(target: promise, action: #selector(CSGesturePromise.gesureRecognizerHandler(_:))) 32 | self.promise=promise 33 | config(gestureRecognizer: self) 34 | } 35 | } 36 | 37 | extension UITapGestureRecognizer:CSGesturePromisable{ 38 | 39 | } 40 | 41 | extension UILongPressGestureRecognizer:CSGesturePromisable{ 42 | 43 | } 44 | 45 | extension UIPanGestureRecognizer:CSGesturePromisable{ 46 | 47 | } 48 | 49 | extension UISwipeGestureRecognizer:CSGesturePromisable{ 50 | 51 | } 52 | 53 | extension UIRotationGestureRecognizer:CSGesturePromisable{ 54 | 55 | } 56 | 57 | extension UIPinchGestureRecognizer:CSGesturePromisable{ 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /ClosuresKitTests/AssocaitedObjectTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AssocaitedObjectTests.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/24. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ClosuresKit 11 | 12 | class AssocaitedObjectTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | static var identifier = "identifier" 20 | static var identifierCompare = "identifierCompare" 21 | let testString = "test" 22 | 23 | func testAssociateValue() { 24 | let view = UIView() 25 | view.cs_associateValue(testString, key: &AssocaitedObjectTests.identifier) 26 | view.cs_associateValue(testString, key: &AssocaitedObjectTests.identifierCompare) 27 | let result = view.cs_associateValueForKey(&AssocaitedObjectTests.identifier) as! String 28 | assert(result==testString,"associateValue failed") 29 | } 30 | 31 | func testClassAssociateValue() { 32 | UIView.cs_associateValue(testString, key: &AssocaitedObjectTests.identifier) 33 | let result = UIView.cs_associateValueForKey(&AssocaitedObjectTests.identifier) as! String 34 | assert(result==testString,"class associateValue failed") 35 | } 36 | 37 | func testCopyAssociateValue(){ 38 | let test:NSMutableString="first" 39 | let view = UIView() 40 | view.cs_associateCopyOfValue(test, key: &AssocaitedObjectTests.identifier) 41 | test.appendString("t") 42 | let result = view.cs_associateValueForKey(&AssocaitedObjectTests.identifier) as! NSString 43 | assert(result=="first","CopyAssociateValue failed") 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ClosuresKitTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ClosuresKitTests/ObserverNotificationTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ObserverNotificationTests.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ClosuresKit 11 | 12 | class ObserverNotificationTests: XCTestCase { 13 | 14 | func testObserverNotification() { 15 | let notificationName = "Test" 16 | cs_addNotificationObserverForName(name: "Test", object: nil) { (notification) in 17 | assert(notification.userInfo!["value"] as! String == "param",#function) 18 | } 19 | NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: self,userInfo:["value":"param"]) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ClosuresKitTests/SequenceExtensionTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SequenceExtensionTests.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/22. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ClosuresKit 11 | 12 | class SequenceExtensionTests: XCTestCase { 13 | 14 | let testSequence = [2,5,6,9] 15 | 16 | func testMatch() { 17 | let result = testSequence.cs_match { (value) -> Bool in 18 | return value == 5 19 | } 20 | assert(result==5,"match failed") 21 | } 22 | 23 | func testAny() { 24 | let result = testSequence.cs_any { (value) -> Bool in 25 | return value > 10 26 | } 27 | assert(result == false, "any failed") 28 | } 29 | 30 | func testNone() { 31 | let result = testSequence.cs_none { (value) -> Bool in 32 | return value > 10 33 | } 34 | assert(result, "none failed") 35 | } 36 | 37 | func testAll() { 38 | var result = testSequence.cs_all { (value) -> Bool in 39 | return value > 10 40 | } 41 | assert(result == false, "all failed") 42 | 43 | result = testSequence.cs_all({$0 > 0}) 44 | assert(result, "all failed") 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ClosuresKitTests/TimerTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TimerTests.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ClosuresKit 11 | 12 | class TimerTests: XCTestCase { 13 | 14 | var count=0 15 | var timer:NSTimer? 16 | 17 | func testTimerWithtimeInterval() { 18 | timer = NSTimer.cs_scheduledTimerWithTimeInterval(1, repeats: false, userInfo: ["key":"value"]) {[unowned self] (timer) in 19 | assert(timer.userInfo!["key"]=="value", #function) 20 | print("times:\(self.count)") 21 | } 22 | timer!.fire() 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ClosuresTest/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ClosuresTest 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // 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. 24 | // 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. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /ClosuresTest/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /ClosuresTest/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 | -------------------------------------------------------------------------------- /ClosuresTest/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 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 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 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 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 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /ClosuresTest/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.1 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 2 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /ClosuresTest/UIControlViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIControlViewController.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ClosuresKit 11 | 12 | class UIControlViewController: UIViewController { 13 | 14 | @IBOutlet weak var btn: UIButton! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | btn.cs_addEventHandlerForEvents(.TouchUpInside) { (sender) in 19 | print("TouchUpInside") 20 | } 21 | btn.cs_addEventHandlerForEvents(.TouchDown) { (sender) in 22 | print("TouchDown") 23 | } 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ClosuresTest/UIGestureViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIGestureViewController.swift 3 | // ClosuresKit 4 | // 5 | // Created by 卓同学 on 16/5/9. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ClosuresKit 11 | 12 | class UIGestureViewController: UIViewController { 13 | 14 | @IBOutlet weak var label: UILabel! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | label.cs_whenTapped { (tapGestureRecognizer) in 19 | print("tapped") 20 | } 21 | 22 | view.cs_whenSwipedInDirection(.Down) { (gestureRecognizer) in 23 | print("down") 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ClosuresTestUITests/ClosuresTestUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ClosuresTestUITests.swift 3 | // ClosuresTestUITests 4 | // 5 | // Created by 卓同学 on 16/4/25. 6 | // Copyright © 2016年 zhuo. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class ClosuresTestUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ClosuresTestUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Zhuo 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ClosuresKit 2 | ![Build Status](https://travis-ci.org/lacklock/ClosuresKit.svg) 3 | ![Language](https://img.shields.io/badge/language-swift%202.3-orange.svg) 4 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 5 | ![License](https://img.shields.io/github/license/mashape/apistatus.svg) 6 | 7 | This project is heavily inspired by the popular [BlocksKit](https://github.com/zwaldowski/BlocksKit). 8 | 9 | 在OC时代,我经常使用[BlocksKit](https://github.com/zwaldowski/BlocksKit),在RAC引入之前,blockskit让代码优雅了许多。然而swift发布后,因为swift是门强类型语言,不再推荐使用runtime相关的方法。在swift中,如果想使用runtime的有些特性需要特别的声明比如@objc这样。由此,blockskit并没有swift版本。然而,即使去掉了runtime的一些东西,blockskit也有一些扩展的方法很实用。所以,我就自己写了一些能想到能做到的贴近blockskit的常见方法:[ClosuresKit](https://github.com/lacklock/ClosuresKit)。 10 | 主要有以下3个部分的扩展 11 | ###Foundation 12 | ####集合类型增加了几个判断 13 | - cs_match 14 | 根据传入的闭包找出匹配的一条数据,filter返回的是一个集合,match只返回一条数据,这是区别。示例如下: 15 | ```swift 16 | let testSequence = [2,5,6,9] 17 | 18 | func testMatch() { 19 | let result = testSequence.cs_match { (value) -> Bool in 20 | return value == 5 21 | } 22 | assert(result==5,"match failed") 23 | } 24 | 25 | ``` 26 | - cs_any 27 | 参数和前面一样,返回的是布尔值,通过传入的闭包判断是否集合中有数据符合这个闭包。 28 | - cs_all 29 | 参数和前面一样,返回的是布尔值,通过传入的闭包判断是否集合中**所有**数据符合这个闭包。 30 | - cs_none 31 | 参数和前面一样,返回的是布尔值,通过传入的闭包判断是否集合中**没有任何一条**数据符合这个闭包。 32 | 33 | ####NSObject可以方便的关联对象 34 | 封装了NSObject的objc_setAssociatedObject的方法。 35 | 几个api的区别也就是关联的策略不同,比如reatian、copy、weak等。 36 | ```swift 37 | class AssocaitedObjectTests: XCTestCase { 38 | static var identifier = "identifier" 39 | 40 | func testCopyAssociateValue(){ 41 | let test:NSMutableString="first" 42 | let view = UIView() 43 | view.cs_associateCopyOfValue(test, key: &AssocaitedObjectTests.identifier) 44 | test.appendString("t") 45 | let result = view.cs_associateValueForKey(&AssocaitedObjectTests.identifier) as! NSString 46 | assert(result=="first","CopyAssociateValue failed") 47 | } 48 | 49 | } 50 | ``` 51 | 这是单元测试中写的一个关联对象策略用copy的示例代码。 52 | ####通知 53 | 可以通过cs_addNotificationObserverForName方便的添加对某个通知的处理: 54 | ```swift 55 | func testObserverNotification() { 56 | let notificationName = "Test" 57 | cs_addNotificationObserverForName(name: "Test", object: nil) { (notification) in 58 | assert(notification.userInfo!["value"] as! String == "param",#function) 59 | } 60 | NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: self,userInfo:["value":"param"]) 61 | } 62 | 63 | ``` 64 | ####NSTimer 65 | 可以在添加timer时传入闭包直接处理回调。示例代码: 66 | ```swift 67 | var count=0 68 | var timer:NSTimer? 69 | 70 | func testTimerWithtimeInterval() { 71 | timer = NSTimer.cs_scheduledTimerWithTimeInterval(1, repeats: false, userInfo: ["key":"value"]) {[unowned self] (timer) in 72 | assert(timer.userInfo!["key"]=="value", #function) 73 | print("times:\(self.count)") 74 | } 75 | timer!.fire() 76 | } 77 | ``` 78 | ###UIKIt 79 | 给UIControl加了一个方便处理UIControlEvents的方法cs_addEventHandlerForEvents,示例如下: 80 | ```swift 81 | btn.cs_addEventHandlerForEvents(.TouchUpInside) { (sender) in 82 | print("TouchUpInside") 83 | } 84 | ``` 85 | ###UIGesture 86 | 可以给UIView方便的直接添加手势,支持链式编程,可以在添加手势时那个闭包里配置,连续处理几种不同的状态: 87 | ```swift 88 | label.cs_addPanGesture { (gestureRecognizer) in 89 | gestureRecognizer.maximumNumberOfTouches=2 90 | }.whenBegan { (gestureRecognizer) in 91 | print("began") 92 | } 93 | ``` 94 | 如果不用配置,配置的闭包可以直接为空: 95 | ```swift 96 | label.cs_addPanGesture().whenChanged { (gestureRecognizer) in 97 | print("changed") 98 | } 99 | ``` 100 | 也可以同时给几个状态添加同一个处理闭包: 101 | ```swift 102 | lbState.nc_addPanGesture().whenStatesHappend([.Ended,.Changed]) { (gestureRecognizer) -> Void in 103 | 104 | } 105 | ``` 106 | 还给tap和swipe添加了两个快捷的处理方法: 107 | ```swift 108 | label.cs_whenTapped { (tapGestureRecognizer) in 109 | print("tapped") 110 | } 111 | 112 | view.cs_whenSwipedInDirection(.Down) { (gestureRecognizer) in 113 | print("down") 114 | } 115 | ``` 116 | 目前想到的api就这些,如果有需要添加的可以直接提到issue里,我会及时处理的,也欢迎直接提pull request。 117 | 118 | #Installation 119 | 120 | ###Carthage 121 | github "lacklock/ClosuresKit" 122 | 123 | #Contact 124 | 125 | Weibo : [@没故事的卓同学](http://weibo.com/1926303682) 126 | 127 | # License 128 | 129 | `ClosuresKit` is available under the MIT license. See the [LICENSE](./LICENSE) file for more info. --------------------------------------------------------------------------------