From 24739b0ae6cf014d300d33e82d256d23483a4b66 Mon Sep 17 00:00:00 2001 From: Rui Peres Date: Thu, 22 Sep 2016 11:49:25 +0100 Subject: [PATCH 1/2] Swift3 (Xcode8 GM) fixes --- .travis.yml | 2 +- .../Source/OptionalExtensions.swift | 30 +++++++------------ README.md | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c3c940..cfa256b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode7.3 +osx_image: xcode8 script: - set -o pipefail - xcodebuild test -scheme OptionalExtensions-Mac | xcpretty -c diff --git a/OptionalExtensions/Source/OptionalExtensions.swift b/OptionalExtensions/Source/OptionalExtensions.swift index ae36b02..c1ded18 100644 --- a/OptionalExtensions/Source/OptionalExtensions.swift +++ b/OptionalExtensions/Source/OptionalExtensions.swift @@ -7,52 +7,42 @@ // public extension Optional { - - func filter(_ predicate: @noescape (Wrapped) -> Bool) -> Optional { + func filter(_ predicate: (Wrapped) -> Bool) -> Optional { return map(predicate) == .some(true) ? self : .none } - func mapNil(_ predicate: @noescape (Void) -> Wrapped) -> Optional { - + func mapNil(_ predicate: (Void) -> Wrapped) -> Optional { return self ?? .some(predicate()) } - - func flatMapNil(_ predicate: @noescape (Void) -> Optional) -> Optional { - + + func flatMapNil(_ predicate: (Void) -> Optional) -> Optional { return self ?? predicate() } - func then(_ f: @noescape (Wrapped) -> Void) { - + func then(_ f: (Wrapped) -> Void) { if let wrapped = self { f(wrapped) } } - - - func maybe(_ defaultValue: U, f: @noescape (Wrapped) -> U) -> U { - + + func maybe(_ defaultValue: U, f: (Wrapped) -> U) -> U { return map(f) ?? defaultValue } - func onSome(_ f: @noescape (Wrapped) -> Void) -> Optional { - + func onSome(_ f: (Wrapped) -> Void) -> Optional { then(f) return self } - func onNone(_ f: @noescape (Void) -> Void) -> Optional { - + func onNone(_ f: (Void) -> Void) -> Optional { if isNone { f() } return self } var isSome: Bool { - return self != nil } - var isNone: Bool { - + var isNone: Bool { return !isSome } } diff --git a/README.md b/README.md index 6dcf199..8c4225f 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CocoaPods](https://img.shields.io/cocoapods/v/OptionalExtensions.svg)](https://cocoapods.org/) -[![Swift 3.0 ß6](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/) +[![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/) [![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat)](https://opensource.org/licenses/MIT) ![](https://camo.githubusercontent.com/410f44c161ebf367eacb1fcce9121e336e211bc6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506c6174666f726d2d696f732532302537432532306f737825323025374325323077617463686f7325323025374325323074766f732d6c69676874677265792e7376673f7374796c653d666c6174) From 74b14c1582bfd372a77208431f8168f102e0f208 Mon Sep 17 00:00:00 2001 From: Rui Peres Date: Thu, 22 Sep 2016 11:56:05 +0100 Subject: [PATCH 2/2] Project configuration changes --- OptionalExtensions.xcodeproj/project.pbxproj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OptionalExtensions.xcodeproj/project.pbxproj b/OptionalExtensions.xcodeproj/project.pbxproj index 0c5e351..bfea69c 100644 --- a/OptionalExtensions.xcodeproj/project.pbxproj +++ b/OptionalExtensions.xcodeproj/project.pbxproj @@ -346,18 +346,23 @@ TargetAttributes = { 7DA0535A1C3DC5F3001F27B2 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; 7DA0536A1C3DC675001F27B2 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; C7263FBB1C3C6BB200F402F9 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; C7263FC91C3C6C9E00F402F9 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; C7263FD71C3C6D1000F402F9 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; C7EC1DC31C34503A00BA1261 = { CreatedOnToolsVersion = 7.2; @@ -532,6 +537,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "rp.OptionalExtensions-Mac-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -546,6 +552,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -557,6 +564,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "rp.OptionalExtensions-tvOS-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.1; }; @@ -571,6 +579,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.1; }; @@ -591,6 +600,7 @@ PRODUCT_NAME = OptionalExtensions; SDKROOT = watchos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -612,6 +622,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -631,6 +642,7 @@ PRODUCT_NAME = OptionalExtensions; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -651,6 +663,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -673,6 +686,7 @@ PRODUCT_NAME = OptionalExtensions; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -694,6 +708,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; };