├── .gitignore ├── LICENSE ├── Project ├── swiftf.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── swiftf.xcscheme ├── swiftf │ ├── Info.plist │ ├── swiftf.h │ └── swiftf.swift └── swiftfTests │ ├── ArrayTest.swift │ ├── Info.plist │ ├── OptionalTest.swift │ └── Sample.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 koher 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 | -------------------------------------------------------------------------------- /Project/swiftf.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D6BC3E8C1BA59908000ADE99 /* swiftf.h in Headers */ = {isa = PBXBuildFile; fileRef = D6BC3E8B1BA59908000ADE99 /* swiftf.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | D6BC3E931BA59908000ADE99 /* swiftf.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6BC3E881BA59908000ADE99 /* swiftf.framework */; }; 12 | D6BC3EA31BA5991E000ADE99 /* swiftf.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC3EA21BA5991E000ADE99 /* swiftf.swift */; }; 13 | D6BC3EA61BA5992D000ADE99 /* ArrayTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC3EA41BA5992D000ADE99 /* ArrayTest.swift */; }; 14 | D6BC3EA71BA5992D000ADE99 /* OptionalTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC3EA51BA5992D000ADE99 /* OptionalTest.swift */; }; 15 | D6BC3EB51BA59A9D000ADE99 /* Sample.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC3EB41BA59A9D000ADE99 /* Sample.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXContainerItemProxy section */ 19 | D6BC3E941BA59908000ADE99 /* PBXContainerItemProxy */ = { 20 | isa = PBXContainerItemProxy; 21 | containerPortal = D6BC3E7F1BA59908000ADE99 /* Project object */; 22 | proxyType = 1; 23 | remoteGlobalIDString = D6BC3E871BA59908000ADE99; 24 | remoteInfo = swiftf; 25 | }; 26 | /* End PBXContainerItemProxy section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | D6BC3E881BA59908000ADE99 /* swiftf.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = swiftf.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | D6BC3E8B1BA59908000ADE99 /* swiftf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = swiftf.h; sourceTree = ""; }; 31 | D6BC3E8D1BA59908000ADE99 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | D6BC3E921BA59908000ADE99 /* swiftfTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = swiftfTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | D6BC3E991BA59908000ADE99 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | D6BC3EA21BA5991E000ADE99 /* swiftf.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = swiftf.swift; sourceTree = ""; }; 35 | D6BC3EA41BA5992D000ADE99 /* ArrayTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTest.swift; sourceTree = ""; }; 36 | D6BC3EA51BA5992D000ADE99 /* OptionalTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OptionalTest.swift; sourceTree = ""; }; 37 | D6BC3EB41BA59A9D000ADE99 /* Sample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sample.swift; sourceTree = ""; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | D6BC3E841BA59908000ADE99 /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | D6BC3E8F1BA59908000ADE99 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | D6BC3E931BA59908000ADE99 /* swiftf.framework in Frameworks */, 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | D6BC3E7E1BA59908000ADE99 = { 60 | isa = PBXGroup; 61 | children = ( 62 | D6BC3E8A1BA59908000ADE99 /* swiftf */, 63 | D6BC3E961BA59908000ADE99 /* swiftfTests */, 64 | D6BC3E891BA59908000ADE99 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | D6BC3E891BA59908000ADE99 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | D6BC3E881BA59908000ADE99 /* swiftf.framework */, 72 | D6BC3E921BA59908000ADE99 /* swiftfTests.xctest */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | D6BC3E8A1BA59908000ADE99 /* swiftf */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | D6BC3EA21BA5991E000ADE99 /* swiftf.swift */, 81 | D6BC3E8B1BA59908000ADE99 /* swiftf.h */, 82 | D6BC3E8D1BA59908000ADE99 /* Info.plist */, 83 | ); 84 | path = swiftf; 85 | sourceTree = ""; 86 | }; 87 | D6BC3E961BA59908000ADE99 /* swiftfTests */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | D6BC3EB41BA59A9D000ADE99 /* Sample.swift */, 91 | D6BC3EA41BA5992D000ADE99 /* ArrayTest.swift */, 92 | D6BC3EA51BA5992D000ADE99 /* OptionalTest.swift */, 93 | D6BC3E991BA59908000ADE99 /* Info.plist */, 94 | ); 95 | path = swiftfTests; 96 | sourceTree = ""; 97 | }; 98 | /* End PBXGroup section */ 99 | 100 | /* Begin PBXHeadersBuildPhase section */ 101 | D6BC3E851BA59908000ADE99 /* Headers */ = { 102 | isa = PBXHeadersBuildPhase; 103 | buildActionMask = 2147483647; 104 | files = ( 105 | D6BC3E8C1BA59908000ADE99 /* swiftf.h in Headers */, 106 | ); 107 | runOnlyForDeploymentPostprocessing = 0; 108 | }; 109 | /* End PBXHeadersBuildPhase section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | D6BC3E871BA59908000ADE99 /* swiftf */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = D6BC3E9C1BA59908000ADE99 /* Build configuration list for PBXNativeTarget "swiftf" */; 115 | buildPhases = ( 116 | D6BC3E831BA59908000ADE99 /* Sources */, 117 | D6BC3E841BA59908000ADE99 /* Frameworks */, 118 | D6BC3E851BA59908000ADE99 /* Headers */, 119 | D6BC3E861BA59908000ADE99 /* Resources */, 120 | ); 121 | buildRules = ( 122 | ); 123 | dependencies = ( 124 | ); 125 | name = swiftf; 126 | productName = swiftf; 127 | productReference = D6BC3E881BA59908000ADE99 /* swiftf.framework */; 128 | productType = "com.apple.product-type.framework"; 129 | }; 130 | D6BC3E911BA59908000ADE99 /* swiftfTests */ = { 131 | isa = PBXNativeTarget; 132 | buildConfigurationList = D6BC3E9F1BA59908000ADE99 /* Build configuration list for PBXNativeTarget "swiftfTests" */; 133 | buildPhases = ( 134 | D6BC3E8E1BA59908000ADE99 /* Sources */, 135 | D6BC3E8F1BA59908000ADE99 /* Frameworks */, 136 | D6BC3E901BA59908000ADE99 /* Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | D6BC3E951BA59908000ADE99 /* PBXTargetDependency */, 142 | ); 143 | name = swiftfTests; 144 | productName = swiftfTests; 145 | productReference = D6BC3E921BA59908000ADE99 /* swiftfTests.xctest */; 146 | productType = "com.apple.product-type.bundle.unit-test"; 147 | }; 148 | /* End PBXNativeTarget section */ 149 | 150 | /* Begin PBXProject section */ 151 | D6BC3E7F1BA59908000ADE99 /* Project object */ = { 152 | isa = PBXProject; 153 | attributes = { 154 | LastSwiftUpdateCheck = 0700; 155 | LastUpgradeCheck = 0700; 156 | ORGANIZATIONNAME = koherent.org; 157 | TargetAttributes = { 158 | D6BC3E871BA59908000ADE99 = { 159 | CreatedOnToolsVersion = 7.0; 160 | }; 161 | D6BC3E911BA59908000ADE99 = { 162 | CreatedOnToolsVersion = 7.0; 163 | }; 164 | }; 165 | }; 166 | buildConfigurationList = D6BC3E821BA59908000ADE99 /* Build configuration list for PBXProject "swiftf" */; 167 | compatibilityVersion = "Xcode 3.2"; 168 | developmentRegion = English; 169 | hasScannedForEncodings = 0; 170 | knownRegions = ( 171 | English, 172 | en, 173 | ); 174 | mainGroup = D6BC3E7E1BA59908000ADE99; 175 | productRefGroup = D6BC3E891BA59908000ADE99 /* Products */; 176 | projectDirPath = ""; 177 | projectRoot = ""; 178 | targets = ( 179 | D6BC3E871BA59908000ADE99 /* swiftf */, 180 | D6BC3E911BA59908000ADE99 /* swiftfTests */, 181 | ); 182 | }; 183 | /* End PBXProject section */ 184 | 185 | /* Begin PBXResourcesBuildPhase section */ 186 | D6BC3E861BA59908000ADE99 /* Resources */ = { 187 | isa = PBXResourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | }; 193 | D6BC3E901BA59908000ADE99 /* Resources */ = { 194 | isa = PBXResourcesBuildPhase; 195 | buildActionMask = 2147483647; 196 | files = ( 197 | ); 198 | runOnlyForDeploymentPostprocessing = 0; 199 | }; 200 | /* End PBXResourcesBuildPhase section */ 201 | 202 | /* Begin PBXSourcesBuildPhase section */ 203 | D6BC3E831BA59908000ADE99 /* Sources */ = { 204 | isa = PBXSourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | D6BC3EA31BA5991E000ADE99 /* swiftf.swift in Sources */, 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | D6BC3E8E1BA59908000ADE99 /* Sources */ = { 212 | isa = PBXSourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | D6BC3EA71BA5992D000ADE99 /* OptionalTest.swift in Sources */, 216 | D6BC3EB51BA59A9D000ADE99 /* Sample.swift in Sources */, 217 | D6BC3EA61BA5992D000ADE99 /* ArrayTest.swift in Sources */, 218 | ); 219 | runOnlyForDeploymentPostprocessing = 0; 220 | }; 221 | /* End PBXSourcesBuildPhase section */ 222 | 223 | /* Begin PBXTargetDependency section */ 224 | D6BC3E951BA59908000ADE99 /* PBXTargetDependency */ = { 225 | isa = PBXTargetDependency; 226 | target = D6BC3E871BA59908000ADE99 /* swiftf */; 227 | targetProxy = D6BC3E941BA59908000ADE99 /* PBXContainerItemProxy */; 228 | }; 229 | /* End PBXTargetDependency section */ 230 | 231 | /* Begin XCBuildConfiguration section */ 232 | D6BC3E9A1BA59908000ADE99 /* Debug */ = { 233 | isa = XCBuildConfiguration; 234 | buildSettings = { 235 | ALWAYS_SEARCH_USER_PATHS = NO; 236 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 237 | CLANG_CXX_LIBRARY = "libc++"; 238 | CLANG_ENABLE_MODULES = YES; 239 | CLANG_ENABLE_OBJC_ARC = YES; 240 | CLANG_WARN_BOOL_CONVERSION = YES; 241 | CLANG_WARN_CONSTANT_CONVERSION = YES; 242 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INT_CONVERSION = YES; 246 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 247 | CLANG_WARN_UNREACHABLE_CODE = YES; 248 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 249 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 250 | COPY_PHASE_STRIP = NO; 251 | CURRENT_PROJECT_VERSION = 1; 252 | DEBUG_INFORMATION_FORMAT = dwarf; 253 | ENABLE_STRICT_OBJC_MSGSEND = YES; 254 | ENABLE_TESTABILITY = YES; 255 | GCC_C_LANGUAGE_STANDARD = gnu99; 256 | GCC_DYNAMIC_NO_PIC = NO; 257 | GCC_NO_COMMON_BLOCKS = YES; 258 | GCC_OPTIMIZATION_LEVEL = 0; 259 | GCC_PREPROCESSOR_DEFINITIONS = ( 260 | "DEBUG=1", 261 | "$(inherited)", 262 | ); 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 270 | MTL_ENABLE_DEBUG_INFO = YES; 271 | ONLY_ACTIVE_ARCH = YES; 272 | SDKROOT = iphoneos; 273 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 274 | TARGETED_DEVICE_FAMILY = "1,2"; 275 | VERSIONING_SYSTEM = "apple-generic"; 276 | VERSION_INFO_PREFIX = ""; 277 | }; 278 | name = Debug; 279 | }; 280 | D6BC3E9B1BA59908000ADE99 /* Release */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ALWAYS_SEARCH_USER_PATHS = NO; 284 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 285 | CLANG_CXX_LIBRARY = "libc++"; 286 | CLANG_ENABLE_MODULES = YES; 287 | CLANG_ENABLE_OBJC_ARC = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_UNREACHABLE_CODE = YES; 296 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 297 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 298 | COPY_PHASE_STRIP = NO; 299 | CURRENT_PROJECT_VERSION = 1; 300 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 301 | ENABLE_NS_ASSERTIONS = NO; 302 | ENABLE_STRICT_OBJC_MSGSEND = YES; 303 | GCC_C_LANGUAGE_STANDARD = gnu99; 304 | GCC_NO_COMMON_BLOCKS = YES; 305 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 306 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 307 | GCC_WARN_UNDECLARED_SELECTOR = YES; 308 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 309 | GCC_WARN_UNUSED_FUNCTION = YES; 310 | GCC_WARN_UNUSED_VARIABLE = YES; 311 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 312 | MTL_ENABLE_DEBUG_INFO = NO; 313 | SDKROOT = iphoneos; 314 | TARGETED_DEVICE_FAMILY = "1,2"; 315 | VALIDATE_PRODUCT = YES; 316 | VERSIONING_SYSTEM = "apple-generic"; 317 | VERSION_INFO_PREFIX = ""; 318 | }; 319 | name = Release; 320 | }; 321 | D6BC3E9D1BA59908000ADE99 /* Debug */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | CLANG_ENABLE_MODULES = YES; 325 | DEFINES_MODULE = YES; 326 | DYLIB_COMPATIBILITY_VERSION = 1; 327 | DYLIB_CURRENT_VERSION = 1; 328 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 329 | INFOPLIST_FILE = swiftf/Info.plist; 330 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 331 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 332 | PRODUCT_BUNDLE_IDENTIFIER = org.koherent.swiftf; 333 | PRODUCT_NAME = "$(TARGET_NAME)"; 334 | SKIP_INSTALL = YES; 335 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 336 | SWIFT_VERSION = 5.0; 337 | }; 338 | name = Debug; 339 | }; 340 | D6BC3E9E1BA59908000ADE99 /* Release */ = { 341 | isa = XCBuildConfiguration; 342 | buildSettings = { 343 | CLANG_ENABLE_MODULES = YES; 344 | DEFINES_MODULE = YES; 345 | DYLIB_COMPATIBILITY_VERSION = 1; 346 | DYLIB_CURRENT_VERSION = 1; 347 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 348 | INFOPLIST_FILE = swiftf/Info.plist; 349 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 350 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 351 | PRODUCT_BUNDLE_IDENTIFIER = org.koherent.swiftf; 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | SKIP_INSTALL = YES; 354 | SWIFT_VERSION = 5.0; 355 | }; 356 | name = Release; 357 | }; 358 | D6BC3EA01BA59908000ADE99 /* Debug */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | INFOPLIST_FILE = swiftfTests/Info.plist; 362 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 363 | PRODUCT_BUNDLE_IDENTIFIER = org.koherent.swiftfTests; 364 | PRODUCT_NAME = "$(TARGET_NAME)"; 365 | SWIFT_VERSION = 5.0; 366 | }; 367 | name = Debug; 368 | }; 369 | D6BC3EA11BA59908000ADE99 /* Release */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | INFOPLIST_FILE = swiftfTests/Info.plist; 373 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 374 | PRODUCT_BUNDLE_IDENTIFIER = org.koherent.swiftfTests; 375 | PRODUCT_NAME = "$(TARGET_NAME)"; 376 | SWIFT_VERSION = 5.0; 377 | }; 378 | name = Release; 379 | }; 380 | /* End XCBuildConfiguration section */ 381 | 382 | /* Begin XCConfigurationList section */ 383 | D6BC3E821BA59908000ADE99 /* Build configuration list for PBXProject "swiftf" */ = { 384 | isa = XCConfigurationList; 385 | buildConfigurations = ( 386 | D6BC3E9A1BA59908000ADE99 /* Debug */, 387 | D6BC3E9B1BA59908000ADE99 /* Release */, 388 | ); 389 | defaultConfigurationIsVisible = 0; 390 | defaultConfigurationName = Release; 391 | }; 392 | D6BC3E9C1BA59908000ADE99 /* Build configuration list for PBXNativeTarget "swiftf" */ = { 393 | isa = XCConfigurationList; 394 | buildConfigurations = ( 395 | D6BC3E9D1BA59908000ADE99 /* Debug */, 396 | D6BC3E9E1BA59908000ADE99 /* Release */, 397 | ); 398 | defaultConfigurationIsVisible = 0; 399 | defaultConfigurationName = Release; 400 | }; 401 | D6BC3E9F1BA59908000ADE99 /* Build configuration list for PBXNativeTarget "swiftfTests" */ = { 402 | isa = XCConfigurationList; 403 | buildConfigurations = ( 404 | D6BC3EA01BA59908000ADE99 /* Debug */, 405 | D6BC3EA11BA59908000ADE99 /* Release */, 406 | ); 407 | defaultConfigurationIsVisible = 0; 408 | defaultConfigurationName = Release; 409 | }; 410 | /* End XCConfigurationList section */ 411 | }; 412 | rootObject = D6BC3E7F1BA59908000ADE99 /* Project object */; 413 | } 414 | -------------------------------------------------------------------------------- /Project/swiftf.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Project/swiftf.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Project/swiftf.xcodeproj/xcshareddata/xcschemes/swiftf.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 | -------------------------------------------------------------------------------- /Project/swiftf/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.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Project/swiftf/swiftf.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | //! Project version number for swiftf. 4 | FOUNDATION_EXPORT double swiftfVersionNumber; 5 | 6 | //! Project version string for swiftf. 7 | FOUNDATION_EXPORT const unsigned char swiftfVersionString[]; 8 | 9 | // In this header, you should import all the public headers of your framework using statements like #import 10 | 11 | 12 | -------------------------------------------------------------------------------- /Project/swiftf/swiftf.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension Optional { 4 | public func reduce(_ initialResult: U, nextPartialResult: (U, Wrapped) -> U) -> U { 5 | switch self { 6 | case .none: 7 | return initialResult 8 | case .some(let value): 9 | return nextPartialResult(initialResult, value) 10 | } 11 | } 12 | 13 | public func filter(isIncluded: (Wrapped) -> Bool) -> Wrapped? { 14 | return flatMap { isIncluded($0) ? $0 : nil } 15 | } 16 | 17 | public func forEach(action: (Wrapped) -> ()) { 18 | reduce(()) { action($1) } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Project/swiftfTests/ArrayTest.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import swiftf 3 | 4 | class ArrayTest: XCTestCase { 5 | override func setUp() { 6 | super.setUp() 7 | } 8 | 9 | override func tearDown() { 10 | super.tearDown() 11 | } 12 | 13 | func testFlatMap() { 14 | let r1: [Int] = [[2], [3, 5], [7, 11, 13]].flatMap { $0 } // [2, 3, 5, 7, 11, 13] 15 | let r2: [Int] = [1, 2, 3].flatMap { [Int](repeating: $0, count: $0) } // [1, 2, 2, 3, 3, 3] 16 | 17 | XCTAssertEqual(r1, [2, 3, 5, 7, 11, 13]) 18 | XCTAssertEqual(r2, [1, 2, 2, 3, 3, 3]) 19 | 20 | let strings: [String] = ["2", "3", "four", "5"] 21 | let numbers = strings.compactMap { Int($0) } 22 | 23 | XCTAssertEqual(numbers, [2, 3, 5]) 24 | } 25 | 26 | func testForEach() { 27 | let a = [2, 3, 5] 28 | var i = 0 29 | a.forEach { 30 | XCTAssertEqual($0, a[i]) 31 | i += 1 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Project/swiftfTests/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 | -------------------------------------------------------------------------------- /Project/swiftfTests/OptionalTest.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import swiftf 3 | 4 | class OptionalTest: XCTestCase { 5 | override func setUp() { 6 | super.setUp() 7 | } 8 | 9 | override func tearDown() { 10 | super.tearDown() 11 | } 12 | 13 | func testFlatMap() { 14 | let a: Int? = 2 15 | let b: Int? = 3 16 | 17 | let r: Int? = a.flatMap { a0 in b.flatMap { b0 in a0 + b0 } } // Optional(5) 18 | 19 | XCTAssertEqual(r!, 5) 20 | } 21 | 22 | func testEach() { 23 | let a: Int? = 2 24 | let b: Int? = nil 25 | 26 | a.forEach { XCTAssertEqual($0, a!) } 27 | b.forEach { XCTFail("Never reaches here: \($0)") } 28 | } 29 | 30 | func testFilter() { 31 | let a: Int? = 2 32 | let b: Int? = 3 33 | let c: Int? = nil 34 | 35 | let r1: Int? = a.filter { $0 % 2 == 0 } // Optional(2) 36 | let r2: Int? = b.filter { $0 % 2 == 0 } // nil 37 | let r3: Int? = c.filter { $0 % 2 == 0 } // nil 38 | 39 | XCTAssertTrue(r1 == 2) 40 | XCTAssertTrue(r2 == nil) 41 | XCTAssertTrue(r3 == nil) 42 | } 43 | 44 | func testReduce() { 45 | let name1: String? = "world" 46 | let name2: String? = nil 47 | 48 | let r1: String = name1.reduce("Hello") { $0 + ", " + $1} // Hello, world 49 | let r2: String = name2.reduce("Hello") { $0 + ", " + $1} // Hello 50 | 51 | XCTAssertEqual(r1, "Hello, world") 52 | XCTAssertEqual(r2, "Hello") 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Project/swiftfTests/Sample.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import swiftf 3 | 4 | class Sample: XCTestCase { 5 | func testSample() { 6 | ///// Optional ///// 7 | 8 | // forEach 9 | do { 10 | let a: Int? = 2 11 | let b: Int? = nil 12 | 13 | a.forEach { print($0) } // 2 14 | b.forEach { print($0) } // prints nothing 15 | } 16 | 17 | // filter 18 | do { 19 | let a: Int? = 2 20 | let b: Int? = 3 21 | let c: Int? = nil 22 | 23 | let r1: Int? = a.filter { $0 % 2 == 0 } // Optional(2) 24 | let r2: Int? = b.filter { $0 % 2 == 0 } // nil 25 | let r3: Int? = c.filter { $0 % 2 == 0 } // nil 26 | 27 | print(r1.map { "\($0)" } ?? "nil") 28 | print(r2.map { "\($0)" } ?? "nil") 29 | print(r3.map { "\($0)" } ?? "nil") 30 | } 31 | 32 | // reduce 33 | do { 34 | let name1: String? = "world" 35 | let name2: String? = nil 36 | 37 | let r1: String = name1.reduce("Hello") { $0 + ", " + $1} // Hello, world 38 | let r2: String = name2.reduce("Hello") { $0 + ", " + $1} // Hello 39 | 40 | print(r1) 41 | print(r2) 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | swiftf 2 | ============================ 3 | 4 | _swiftf_ provides some higher-order methods for `Optional`. 5 | 6 | Usage 7 | ---------------------------- 8 | 9 | ### Optional 10 | 11 | #### forEach 12 | 13 | ```swift 14 | let a: Int? = 2 15 | let b: Int? = nil 16 | 17 | a.forEach { print($0) } // 2 18 | b.forEach { print($0) } // prints nothing 19 | ``` 20 | 21 | #### filter 22 | 23 | ```swift 24 | let a: Int? = 2 25 | let b: Int? = 3 26 | let c: Int? = nil 27 | 28 | a.filter { $0 % 2 == 0 } // Optional(2) 29 | b.filter { $0 % 2 == 0 } // nil 30 | c.filter { $0 % 2 == 0 } // nil 31 | ``` 32 | 33 | #### reduce 34 | 35 | ```swift 36 | let name1: String? = "world" 37 | let name2: String? = nil 38 | 39 | let r1: String = name1.reduce("Hello") { $0 + ", " + $1} // Hello, world 40 | let r2: String = name2.reduce("Hello") { $0 + ", " + $1} // Hello 41 | ``` 42 | 43 | How to Install 44 | ---------------------------- 45 | 46 | ### Embedded Framework 47 | 48 | 1. Put [swiftf.xcodeproj](Project/swiftf.xcodeproj) into your project in Xcode. 49 | 2. Click the project icon and select the "General" tab. 50 | 3. Add swiftf.framework to "Embedded Binaries". 51 | 4. `import swiftf` in your swift files. 52 | 53 | Put _swiftf.framework_ into your project. 54 | 55 | License 56 | ---------------------------- 57 | 58 | [The MIT License](LICENSE) 59 | --------------------------------------------------------------------------------