From 45268e7f2f64263d711b26148640ad149e571f5c Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:16:22 -0500 Subject: [PATCH 01/68] added POSIX Thread --- README.md | 13 +-- Sources/SwiftFoundation/Thread.swift | 92 +++++++++++++++++++ .../SwiftFoundation.xcodeproj/project.pbxproj | 8 ++ 3 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 Sources/SwiftFoundation/Thread.swift diff --git a/README.md b/README.md index 9b2f04e..e0a5657 100644 --- a/README.md +++ b/README.md @@ -42,17 +42,18 @@ swift build ## Implemented To see what parts of Foundation are implemented, just look at the unit tests. Completed functionality will be fully unit tested. Note that there is some functionality that is written as a protocol only, that will not be included on this list. +- [x] Base64 +- [x] Data - [x] Date +- [x] FileManager +- [x] JSON - [x] Null - [x] Order (equivalent to ```NSComparisonResult```) +- [X] RegularExpression (POSIX, not ICU) - [x] SortDescriptor -- [x] UUID -- [x] FileManager -- [x] Data +- [x] Thread - [x] URL -- [X] RegularExpression (POSIX, not ICU) -- [x] JSON -- [x] Base64 +- [x] UUID # License diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift new file mode 100644 index 0000000..4a27dba --- /dev/null +++ b/Sources/SwiftFoundation/Thread.swift @@ -0,0 +1,92 @@ +// +// Thread.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 4/5/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + import Darwin.C +#elseif os(Linux) + import Glibc +#endif + +/// POSIX Thread +public final class Thread { + + // MARK: - Private Properties + + #if os(Linux) + private var internalThread: pthread_t = 0 + #else + private var internalThread: pthread_t = nil + #endif + + // MARK: - Intialization + + public init(closure: () -> Void) throws { + + let holder = Unmanaged.passRetained(Closure(closure: closure)) + + #if swift(>=3.0) + let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) + #else + let pointer = UnsafeMutablePointer(holder.toOpaque()) + #endif + + guard pthread_create(&internalThread, nil, ThreadPrivateMain, pointer) == 0 + else { throw POSIXError.fromErrorNumber! } + + pthread_detach(internalThread) + } + + // MARK: - Class Methods + + public static func exit(inout code: Int) { + + pthread_exit(&code) + } + + // MARK: - Methods + + public func join() throws { + + let errorCode = pthread_join(internalThread, nil) + + guard errorCode == 0 + else { throw POSIXError(rawValue: errorCode)! } + } + + public func cancel() throws { + + let errorCode = pthread_cancel(internalThread) + + guard errorCode == 0 + else { throw POSIXError(rawValue: errorCode)! } + } +} + +private func ThreadPrivateMain(arg: UnsafeMutablePointer) -> UnsafeMutablePointer { + + let unmanaged = Unmanaged.fromOpaque(COpaquePointer(arg)) + + unmanaged.takeUnretainedValue().closure() + + unmanaged.release() + + return nil +} + +private extension Thread { + + private final class Closure { + + let closure: () -> () + + init(closure: () -> ()) { + + self.closure = closure + } + } +} diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 750c17f..1e7454d 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 1AE78F671B96774100CDEF17 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1AE78FBF1B96774300CDEF17 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; + 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; + 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; 6E08F85D1BBE7DE900548B1E /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */; }; 6E1ACD4B1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; 6E1ACD4C1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; @@ -296,6 +299,7 @@ /* Begin PBXFileReference section */ 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1AE78FC41B96774300CDEF17 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6E04074D1CB3E07500BE3A79 /* Thread.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Thread.swift; sourceTree = ""; }; 6E08F8571BBE7B8800548B1E /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E1ACD4A1C435822005775FD /* DataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTests.swift; sourceTree = ""; }; 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationConvertible.swift; sourceTree = ""; }; @@ -524,6 +528,7 @@ 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */, 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */, 6E2C2B471C20F6EB00B2C995 /* Task.swift */, + 6E04074D1CB3E07500BE3A79 /* Thread.swift */, 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */, 6E2C2C291C20FC9500B2C995 /* URL */, 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */, @@ -885,6 +890,7 @@ 6E2C2BC21C20F76600B2C995 /* HTTPRequest.swift in Sources */, 6E2C2BCD1C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */, 6E2C2BD11C20F76600B2C995 /* Predicate.swift in Sources */, + 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */, 6E2C2BD21C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BD91C20F76600B2C995 /* String.swift in Sources */, 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, @@ -957,6 +963,7 @@ 6E2C2B8E1C20F76600B2C995 /* HTTPRequest.swift in Sources */, 6E2C2B991C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */, 6E2C2B9D1C20F76600B2C995 /* Predicate.swift in Sources */, + 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */, 6E2C2B9E1C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BA51C20F76600B2C995 /* String.swift in Sources */, 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, @@ -1064,6 +1071,7 @@ 6E2C2BEE1C20F76700B2C995 /* Decimal.swift in Sources */, 6E2C2BEA1C20F76700B2C995 /* Copying.swift in Sources */, 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */, + 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */, 6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */, 6E2C2C091C20F76700B2C995 /* RegularExpressionCompileOption.swift in Sources */, 6E2C2BF71C20F76700B2C995 /* HTTPResponse.swift in Sources */, From 872887cfb181bbd7b61494fc63a2dc490da67058 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:18:57 -0500 Subject: [PATCH 02/68] optimized Thread --- Sources/SwiftFoundation/Thread.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 4a27dba..29277d3 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -17,11 +17,7 @@ public final class Thread { // MARK: - Private Properties - #if os(Linux) - private var internalThread: pthread_t = 0 - #else - private var internalThread: pthread_t = nil - #endif + private let internalThread: pthread_t // MARK: - Intialization @@ -35,9 +31,17 @@ public final class Thread { let pointer = UnsafeMutablePointer(holder.toOpaque()) #endif + #if os(Linux) + var internalThread: pthread_t = 0 + #else + var internalThread: pthread_t = nil + #endif + guard pthread_create(&internalThread, nil, ThreadPrivateMain, pointer) == 0 else { throw POSIXError.fromErrorNumber! } + self.internalThread = internalThread + pthread_detach(internalThread) } From 323c1fe8261470ca4d56c8167debc9c9f392c6e2 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:23:29 -0500 Subject: [PATCH 03/68] Thread Swift 2.2 fix --- Sources/SwiftFoundation/Thread.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 29277d3..201782b 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -25,11 +25,7 @@ public final class Thread { let holder = Unmanaged.passRetained(Closure(closure: closure)) - #if swift(>=3.0) - let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) - #else - let pointer = UnsafeMutablePointer(holder.toOpaque()) - #endif + let pointer = UnsafeMutablePointer(holder.toOpaque()) #if os(Linux) var internalThread: pthread_t = 0 From 17809b6b9e71fdb7eafa1ebd605aeb5c38fee70d Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:23:46 -0500 Subject: [PATCH 04/68] version bump --- Xcode/SwiftFoundation/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xcode/SwiftFoundation/Info.plist b/Xcode/SwiftFoundation/Info.plist index 8435563..0da1879 100644 --- a/Xcode/SwiftFoundation/Info.plist +++ b/Xcode/SwiftFoundation/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.7 + 1.1.8 CFBundleSignature ???? CFBundleVersion From c801529cef2bc08fe2381cc1e75a599f9b662a5b Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:25:16 -0500 Subject: [PATCH 05/68] updated Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 39b6197..27985e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-02-25-a + - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From 80a511a75df8c9e891b03b45995cde05ba140ed7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:35:41 -0500 Subject: [PATCH 06/68] updated Travis CI using Swift 2.2 Release --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 27985e3..cacca04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,9 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install clang uuid-dev libjson-c-dev ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-2.2-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a + - SWIFT_VERSION=swift-2.2-RELEASE script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From 4887c5fe115ef7fff84fccbe8c43a93b695e256b Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:44:39 -0500 Subject: [PATCH 07/68] updated Travis CI building against Swift 2.2 development branch --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cacca04..0764e69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,9 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install clang uuid-dev libjson-c-dev ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-2.2-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-2.2-branch/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-2.2-RELEASE + - SWIFT_VERSION=swift-2.2.1-SNAPSHOT-2016-03-28-a script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From a8218873e87a7596002ef79298a7795e6364bea7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 07:57:29 -0500 Subject: [PATCH 08/68] updated Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0a5657..51e39f2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # SwiftFoundation # -[![Swift](https://img.shields.io/badge/swift-2.2-orange.svg?style=flat)](https://developer.apple.com/swift/) +[![Swift](https://img.shields.io/badge/swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Platforms](https://img.shields.io/badge/platform-osx%20%7C%20ios%20%7C%20watchos%20%7C%20tvos%20%7C%20linux-lightgrey.svg)](https://developer.apple.com/swift/) [![Release](https://img.shields.io/github/release/pureswift/swiftfoundation.svg)](https://github.com/PureSwift/SwiftFoundation/releases) [![License](https://img.shields.io/badge/license-MIT-71787A.svg)](https://tldrlegal.com/license/mit-license) From b73feabf20534d3a722eded295a83b47747fe35f Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 08:03:58 -0500 Subject: [PATCH 09/68] #27 Updated Travis CI for Swift 3.0 development snapshot --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0764e69..27985e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,9 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install clang uuid-dev libjson-c-dev ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-2.2-branch/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-2.2.1-SNAPSHOT-2016-03-28-a + - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From 8ccf3fdc8364e0b1feef2d07c484a3cc04ae9200 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 09:38:16 -0500 Subject: [PATCH 10/68] working on #27 --- .../FoundationConvertible/HTTPClient.swift | 30 +++++++++-- .../NSComparisonResult.swift | 12 ++--- Sources/FoundationConvertible/NSData.swift | 2 +- .../NSJSONSerialization.swift | 14 ++--- .../FoundationConvertible/NSURLSession.swift | 6 +-- Sources/FoundationConvertible/NSUUID.swift | 12 ++--- .../BackwardsCompatibility.swift | 52 +++++++++++++++++++ Sources/SwiftFoundation/BitMaskOption.swift | 10 ++-- Sources/SwiftFoundation/Data.swift | 4 +- Sources/SwiftFoundation/FileManager.swift | 10 ++-- Sources/SwiftFoundation/Hexadecimal.swift | 2 +- Sources/SwiftFoundation/Integer.swift | 4 +- Sources/SwiftFoundation/JSONExtensions.swift | 2 +- Sources/SwiftFoundation/JSONParse.swift | 24 +++++---- .../SwiftFoundation/JSONSerialization.swift | 6 +-- .../POSIXRegularExpression.swift | 4 +- Sources/SwiftFoundation/POSIXTime.swift | 2 +- Sources/SwiftFoundation/POSIXUUID.swift | 20 +++---- Sources/SwiftFoundation/Predicate.swift | 2 +- Sources/SwiftFoundation/Range.swift | 2 +- .../SwiftFoundation/RawRepresentable.swift | 4 +- .../SwiftFoundation/RegularExpression.swift | 2 +- .../RegularExpressionCompileError.swift | 2 +- Sources/SwiftFoundation/SortDescriptor.swift | 2 +- Sources/SwiftFoundation/String.swift | 10 ++-- Sources/SwiftFoundation/Thread.swift | 8 ++- Sources/SwiftFoundation/URL.swift | 4 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 12 ++++- 28 files changed, 179 insertions(+), 85 deletions(-) create mode 100644 Sources/SwiftFoundation/BackwardsCompatibility.swift diff --git a/Sources/FoundationConvertible/HTTPClient.swift b/Sources/FoundationConvertible/HTTPClient.swift index a18be6c..559b03b 100644 --- a/Sources/FoundationConvertible/HTTPClient.swift +++ b/Sources/FoundationConvertible/HTTPClient.swift @@ -16,10 +16,15 @@ public extension HTTP { /// Loads HTTP requests public final class Client: URLClient { + #if swift(>=3.0) + public init(session: NSURLSession = NSURLSession.shared()) { + self.session = session + } + #else public init(session: NSURLSession = NSURLSession.sharedSession()) { - self.session = session } + #endif /// The backing ```NSURLSession```. public let session: NSURLSession @@ -48,7 +53,23 @@ public extension HTTP { var urlResponse: NSHTTPURLResponse? - dataTask = self.session.dataTaskWithRequest(urlRequest) { (data: NSData?, response: NSURLResponse?, responseError: NSError?) -> Void in + #if swift(>=3.0) + + dataTask = self.session.dataTask(with: urlRequest) { (data: NSData?, response: NSURLResponse?, responseError: NSError?) -> () in + + responseData = data + + urlResponse = response as? NSHTTPURLResponse + + error = responseError + + dispatch_semaphore_signal(semaphore); + + } + + #else + + dataTask = self.session.dataTaskWithRequest(urlRequest) { (data: NSData?, response: NSURLResponse?, responseError: NSError?) -> () in responseData = data @@ -57,8 +78,11 @@ public extension HTTP { error = responseError dispatch_semaphore_signal(semaphore); + } + #endif + dataTask!.resume() // wait for task to finish @@ -86,7 +110,7 @@ public extension HTTP { public extension HTTP.Client { - public enum Error: ErrorType { + public enum Error: ErrorProtocol { /// The provided request was malformed. case BadRequest diff --git a/Sources/FoundationConvertible/NSComparisonResult.swift b/Sources/FoundationConvertible/NSComparisonResult.swift index a529f62..a07b5e6 100644 --- a/Sources/FoundationConvertible/NSComparisonResult.swift +++ b/Sources/FoundationConvertible/NSComparisonResult.swift @@ -18,9 +18,9 @@ extension Order: FoundationConvertible { switch foundation { - case .OrderedAscending: self = .Ascending - case .OrderedDescending: self = .Descending - case .OrderedSame: self = .Same + case .orderedAscending: self = .Ascending + case .orderedDescending: self = .Descending + case .orderedSame: self = .Same } } @@ -28,9 +28,9 @@ extension Order: FoundationConvertible { switch self { - case .Ascending: return .OrderedAscending - case .Descending: return .OrderedDescending - case .Same: return .OrderedSame + case .Ascending: return .orderedAscending + case .Descending: return .orderedDescending + case .Same: return .orderedSame } } } diff --git a/Sources/FoundationConvertible/NSData.swift b/Sources/FoundationConvertible/NSData.swift index 06f1880..6297f24 100644 --- a/Sources/FoundationConvertible/NSData.swift +++ b/Sources/FoundationConvertible/NSData.swift @@ -21,7 +21,7 @@ extension Data: FoundationConvertible { let count = foundation.length / sizeof(UInt8) - var bytesArray = [UInt8](count: count, repeatedValue: 0) + var bytesArray = [UInt8] (repeating: 0, count: count) foundation.getBytes(&bytesArray, length:count * sizeof(UInt8)) diff --git a/Sources/FoundationConvertible/NSJSONSerialization.swift b/Sources/FoundationConvertible/NSJSONSerialization.swift index 44ef235..e8b07c0 100644 --- a/Sources/FoundationConvertible/NSJSONSerialization.swift +++ b/Sources/FoundationConvertible/NSJSONSerialization.swift @@ -115,7 +115,7 @@ extension JSON.Value: FoundationConvertible { self = JSON.Value.Number(JSON.Number.Boolean(value as Bool)) } - else if Swift.String.fromCString(value.objCType)! == intObjCType { + else if Swift.String(validatingUTF8: value.objCType)! == intObjCType { self = JSON.Value.Number(.Integer(Int(value))) } @@ -204,19 +204,19 @@ extension JSON.Value: FoundationConvertible { private let trueNumber = NSNumber(bool: true) private let falseNumber = NSNumber(bool: false) -private let trueObjCType = String.fromCString(trueNumber.objCType) -private let falseObjCType = String.fromCString(falseNumber.objCType) +private let trueObjCType = String(validatingUTF8: trueNumber.objCType) +private let falseObjCType = String(validatingUTF8: falseNumber.objCType) private let intNumber = NSNumber(integer: 1) -private let intObjCType = String.fromCString(intNumber.objCType)! +private let intObjCType = String(validatingUTF8: intNumber.objCType)! extension NSNumber { var isBool:Bool { get { - let objCType = String.fromCString(self.objCType) - if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) - || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ + let objCType = String(validatingUTF8: self.objCType) + if (self.compare(trueNumber) == NSComparisonResult.orderedSame && objCType == trueObjCType) + || (self.compare(falseNumber) == NSComparisonResult.orderedSame && objCType == falseObjCType){ return true } else { return false diff --git a/Sources/FoundationConvertible/NSURLSession.swift b/Sources/FoundationConvertible/NSURLSession.swift index 03508e5..ec68718 100644 --- a/Sources/FoundationConvertible/NSURLSession.swift +++ b/Sources/FoundationConvertible/NSURLSession.swift @@ -24,18 +24,18 @@ public extension NSMutableURLRequest { guard let url = NSURL(string: request.URL) else { return nil } - self.URL = url + self.url = url self.timeoutInterval = request.timeoutInterval if let data = request.body { - self.HTTPBody = data.toFoundation() + self.httpBody = data.toFoundation() } self.allHTTPHeaderFields = request.headers - self.HTTPMethod = request.method.rawValue + self.httpMethod = request.method.rawValue } } diff --git a/Sources/FoundationConvertible/NSUUID.swift b/Sources/FoundationConvertible/NSUUID.swift index 317ad86..a67867b 100644 --- a/Sources/FoundationConvertible/NSUUID.swift +++ b/Sources/FoundationConvertible/NSUUID.swift @@ -39,10 +39,10 @@ public extension NSUUID { let bufferType = UnsafeMutablePointer.self - return unsafeBitCast(valuePointer, bufferType) + return unsafeBitCast(valuePointer, to: bufferType) }) - self.init(UUIDBytes: buffer) + self.init(uuidBytes: buffer) } var byteValue: uuid_t { @@ -53,9 +53,9 @@ public extension NSUUID { let bufferType = UnsafeMutablePointer.self - let buffer = unsafeBitCast(valuePointer, bufferType) + let buffer = unsafeBitCast(valuePointer, to: bufferType) - self.getUUIDBytes(buffer) + self.getBytes(buffer) }) return uuid @@ -63,12 +63,12 @@ public extension NSUUID { var rawValue: String { - return UUIDString + return uuidString } convenience init?(rawValue: String) { - self.init(UUIDString: rawValue) + self.init(uuidString: rawValue) } } diff --git a/Sources/SwiftFoundation/BackwardsCompatibility.swift b/Sources/SwiftFoundation/BackwardsCompatibility.swift new file mode 100644 index 0000000..ba97a63 --- /dev/null +++ b/Sources/SwiftFoundation/BackwardsCompatibility.swift @@ -0,0 +1,52 @@ +// +// BackwardsCompatibility.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 4/5/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +// Swift 2.2 compatibility +#if !swift(>=3.0) + + public typealias ErrorProtocol = ErrorType + + public typealias OpaquePointer = COpaquePointer + + public typealias Collection = CollectionType + + public typealias Sequence = SequenceType + + public typealias Integer = IntegerType + + public extension Sequence { + public typealias Generator = Iterator + } + + public extension String { + + @inline(__always) + func uppercased() { return uppercaseString } + + init?(validatingUTF8 cString: UnsafePointer) { + + self = Swift.String.fromCString(cString) + } + } + + public extension UnsafeMutablePointer { + + init(allocatingCapacity count: Int) { + + self = self.alloc(count) + } + + func deallocateCapacity(count: Int) { + + self.dealloc(count) + } + + public var pointee: Memory { } + } + +#endif diff --git a/Sources/SwiftFoundation/BitMaskOption.swift b/Sources/SwiftFoundation/BitMaskOption.swift index 9d2839a..b7472c2 100644 --- a/Sources/SwiftFoundation/BitMaskOption.swift +++ b/Sources/SwiftFoundation/BitMaskOption.swift @@ -12,21 +12,21 @@ public protocol BitMaskOption: RawRepresentable { static func optionsBitmask(options: [Self]) -> Self.RawValue } -public extension BitMaskOption where Self.RawValue: IntegerType { +public extension BitMaskOption where Self.RawValue: Integer { - static func optionsBitmask(options: S) -> Self.RawValue { + static func optionsBitmask(options: S) -> Self.RawValue { return options.reduce(0) { mask, option in mask | option.rawValue } } } -public extension SequenceType where Self.Generator.Element: BitMaskOption, Self.Generator.Element.RawValue: IntegerType { +public extension Sequence where Self.Iterator.Element: BitMaskOption, Self.Iterator.Element.RawValue: Integer { - func optionsBitmask() -> Self.Generator.Element.RawValue { + func optionsBitmask() -> Self.Iterator.Element.RawValue { let array = self.filter { (_) -> Bool in return true } - return Self.Generator.Element.optionsBitmask(array) + return Self.Iterator.Element.optionsBitmask(array) } } \ No newline at end of file diff --git a/Sources/SwiftFoundation/Data.swift b/Sources/SwiftFoundation/Data.swift index cfbeed5..55f74e6 100644 --- a/Sources/SwiftFoundation/Data.swift +++ b/Sources/SwiftFoundation/Data.swift @@ -32,9 +32,9 @@ public extension Data { /// - Precondition: The pointer points to a type exactly a byte long. static func fromBytePointer(pointer: UnsafePointer, length: Int) -> Data { - assert(sizeof(pointer.memory.dynamicType) == sizeof(Byte.self), "Cannot create array of bytes from pointer to \(pointer.memory.dynamicType) because the type is larger than a single byte.") + assert(sizeof(pointer.pointee.dynamicType) == sizeof(Byte.self), "Cannot create array of bytes from pointer to \(pointer.pointee.dynamicType) because the type is larger than a single byte.") - var buffer: [UInt8] = [UInt8](count: length, repeatedValue: 0) + var buffer: [UInt8] = [UInt8](repeating: 0, count: length) memcpy(&buffer, pointer, length) diff --git a/Sources/SwiftFoundation/FileManager.swift b/Sources/SwiftFoundation/FileManager.swift index ca208f5..5c67e3e 100644 --- a/Sources/SwiftFoundation/FileManager.swift +++ b/Sources/SwiftFoundation/FileManager.swift @@ -73,13 +73,13 @@ public final class FileManager { let stringBufferSize = Int(PATH_MAX) - let path = UnsafeMutablePointer.alloc(stringBufferSize) + let path = UnsafeMutablePointer(allocatingCapacity: stringBufferSize) - defer { path.dealloc(stringBufferSize) } + defer { path.deallocateCapacity(stringBufferSize) } getcwd(path, stringBufferSize - 1) - return String.fromCString(path)! + return String(validatingUTF8: path)! } // MARK: - Creating and Deleting Items @@ -187,9 +187,9 @@ public final class FileManager { assert(fileSize <= SSIZE_MAX, "File size (\(fileSize)) is larger than the max number of bytes allowed (\(SSIZE_MAX))") - let memoryPointer = UnsafeMutablePointer.alloc(fileSize) + let memoryPointer = UnsafeMutablePointer(allocatingCapacity: fileSize) - defer { memoryPointer.dealloc(fileSize) } + defer { memoryPointer.deallocateCapacity(fileSize) } let readBytes = read(file, memoryPointer, fileSize) diff --git a/Sources/SwiftFoundation/Hexadecimal.swift b/Sources/SwiftFoundation/Hexadecimal.swift index a97b314..0e6c750 100644 --- a/Sources/SwiftFoundation/Hexadecimal.swift +++ b/Sources/SwiftFoundation/Hexadecimal.swift @@ -17,6 +17,6 @@ public extension UInt8 { string = "0" + string } - return string.uppercaseString + return string.uppercased() } } \ No newline at end of file diff --git a/Sources/SwiftFoundation/Integer.swift b/Sources/SwiftFoundation/Integer.swift index b3e1f61..ae418f2 100644 --- a/Sources/SwiftFoundation/Integer.swift +++ b/Sources/SwiftFoundation/Integer.swift @@ -30,13 +30,13 @@ public extension UInt16 { /// Initializes value from two bytes. public init(bytes: (UInt8, UInt8)) { - self = unsafeBitCast(bytes, UInt16.self) + self = unsafeBitCast(bytes, to: UInt16.self) } /// Converts to two bytes. public var bytes: (UInt8, UInt8) { - return unsafeBitCast(self, (UInt8, UInt8).self) + return unsafeBitCast(self, to: (UInt8, UInt8).self) } } diff --git a/Sources/SwiftFoundation/JSONExtensions.swift b/Sources/SwiftFoundation/JSONExtensions.swift index 47626c8..281a71c 100644 --- a/Sources/SwiftFoundation/JSONExtensions.swift +++ b/Sources/SwiftFoundation/JSONExtensions.swift @@ -74,7 +74,7 @@ extension Bool: JSONDecodable { // MARK: Encodable -public extension CollectionType where Generator.Element: JSONEncodable { +public extension Collection where Iterator.Element: JSONEncodable { func toJSON() -> JSON.Value { diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index 5a19deb..a5769c5 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -16,9 +16,9 @@ public extension JSON.Value { public init?(string: Swift.String) { - let tokenerError = UnsafeMutablePointer.alloc(1) + let tokenerError = UnsafeMutablePointer.init(allocatingCapacity: 1) - defer { tokenerError.dealloc(1) } + defer { tokenerError.deallocateCapacity(1) } let jsonObject = json_tokener_parse_verbose(string, tokenerError) @@ -27,14 +27,18 @@ public extension JSON.Value { // could not parse guard tokenerError != nil else { return nil } + #if swift(>=3.0) + self = self.dynamicType.init(jsonObject: jsonObject) + #else self.init(jsonObject: jsonObject) + #endif } } private extension JSON.Value { /// Create a JSON value from a ```json_object``` pointer created by the **json-c** library. - init(jsonObject: COpaquePointer) { + init(jsonObject: OpaquePointer) { let type = json_object_get_type(jsonObject) switch type { @@ -45,7 +49,7 @@ private extension JSON.Value { let stringPointer = json_object_get_string(jsonObject) - let string = Swift.String.fromCString(stringPointer) ?? "" + let string = Swift.String(validatingUTF8: stringPointer) ?? "" self = JSON.Value.String(string) @@ -100,21 +104,21 @@ private extension JSON.Value { var jsonDictionary = [StringValue: JSONValue]() - var entry = hashTable.memory.head + var entry = hashTable.pointee.head while entry != nil { - let keyPointer = entry.memory.k + let keyPointer = entry.pointee.k - let valuePointer = entry.memory.v + let valuePointer = entry.pointee.v - let key = Swift.String.fromCString(unsafeBitCast(keyPointer, UnsafeMutablePointer.self))! + let key = Swift.String.init(validatingUTF8: unsafeBitCast(keyPointer, to: UnsafeMutablePointer.self))! - let value = json_object_get(unsafeBitCast(valuePointer, COpaquePointer.self)) + let value = json_object_get(unsafeBitCast(valuePointer, to: OpaquePointer.self)) jsonDictionary[key] = JSON.Value(jsonObject: value) - entry = entry.memory.next + entry = entry.pointee.next } self = .Object(jsonDictionary) diff --git a/Sources/SwiftFoundation/JSONSerialization.swift b/Sources/SwiftFoundation/JSONSerialization.swift index 41aa2f1..f9986ae 100755 --- a/Sources/SwiftFoundation/JSONSerialization.swift +++ b/Sources/SwiftFoundation/JSONSerialization.swift @@ -36,7 +36,7 @@ public extension JSON.Value { let stringPointer = json_object_to_json_string_ext(jsonObject, writingFlags) - let string = Swift.String.fromCString(stringPointer)! + let string = Swift.String(validatingUTF8: stringPointer)! return string } @@ -46,7 +46,7 @@ public extension JSON.Value { private extension JSON.Value { - func toJSONObject() -> COpaquePointer { + func toJSONObject() -> OpaquePointer { switch self { @@ -73,7 +73,7 @@ private extension JSON.Value { let jsonArray = json_object_new_array() - for (index, value) in arrayValue.enumerate() { + for (index, value) in arrayValue.enumerated() { let jsonValue = value.toJSONObject() diff --git a/Sources/SwiftFoundation/POSIXRegularExpression.swift b/Sources/SwiftFoundation/POSIXRegularExpression.swift index 7e268e4..ca14054 100644 --- a/Sources/SwiftFoundation/POSIXRegularExpression.swift +++ b/Sources/SwiftFoundation/POSIXRegularExpression.swift @@ -39,8 +39,8 @@ public extension POSIXRegularExpression { let numberOfMatches = re_nsub + 1 // first match is the expression itself, later matches are subexpressions - let matchesPointer = UnsafeMutablePointer.alloc(numberOfMatches) - defer { matchesPointer.destroy(numberOfMatches) } + let matchesPointer = UnsafeMutablePointer.init(allocatingCapacity: numberOfMatches) + defer { matchesPointer.deinitialize(count: numberOfMatches) } let flags = options.optionsBitmask() diff --git a/Sources/SwiftFoundation/POSIXTime.swift b/Sources/SwiftFoundation/POSIXTime.swift index 71ef443..1dc8df8 100644 --- a/Sources/SwiftFoundation/POSIXTime.swift +++ b/Sources/SwiftFoundation/POSIXTime.swift @@ -82,7 +82,7 @@ public extension tm { let timePointer = gmtime(&seconds) - self = timePointer.memory + self = timePointer.pointee } } diff --git a/Sources/SwiftFoundation/POSIXUUID.swift b/Sources/SwiftFoundation/POSIXUUID.swift index 5cdbde2..00cb964 100644 --- a/Sources/SwiftFoundation/POSIXUUID.swift +++ b/Sources/SwiftFoundation/POSIXUUID.swift @@ -29,7 +29,7 @@ public func POSIXUUIDCreateRandom() -> uuid_t { let bufferType = UnsafeMutablePointer.self - let buffer = unsafeBitCast(valuePointer, bufferType) + let buffer = unsafeBitCast(valuePointer, to: bufferType) uuid_generate(buffer) }) @@ -52,11 +52,11 @@ public func POSIXUUIDConvertToUUIDString(uuid: uuid_t) -> POSIXUUIDStringType { withUnsafeMutablePointers(&uuidCopy, &uuidString) { (uuidPointer: UnsafeMutablePointer, uuidStringPointer: UnsafeMutablePointer) -> Void in - let stringBuffer = unsafeBitCast(uuidStringPointer, UnsafeMutablePointer.self) + let stringBuffer = unsafeBitCast(uuidStringPointer, to: UnsafeMutablePointer.self) - let uuidBuffer = unsafeBitCast(uuidPointer, UnsafeMutablePointer.self) + let uuidBuffer = unsafeBitCast(uuidPointer, to: UnsafeMutablePointer.self) - uuid_unparse(unsafeBitCast(uuidBuffer, UnsafePointer.self), stringBuffer) + uuid_unparse(unsafeBitCast(uuidBuffer, to: UnsafePointer.self), stringBuffer) } return uuidString @@ -70,21 +70,21 @@ public func POSIXUUIDStringConvertToString(uuidString: POSIXUUIDStringType) -> S let bufferType = UnsafeMutablePointer.self - let buffer = unsafeBitCast(valuePointer, bufferType) + let buffer = unsafeBitCast(valuePointer, to: bufferType) - return String.fromCString(unsafeBitCast(buffer, UnsafePointer.self))! + return String(validatingUTF8: unsafeBitCast(buffer, to: UnsafePointer.self))! }) } public func POSIXUUIDConvertStringToUUID(string: String) -> uuid_t? { - let uuidPointer = UnsafeMutablePointer.alloc(1) - defer { uuidPointer.dealloc(1) } + let uuidPointer = UnsafeMutablePointer(allocatingCapacity: 1) + defer { uuidPointer.deallocateCapacity(1) } - guard uuid_parse(string, unsafeBitCast(uuidPointer, UnsafeMutablePointer.self)) != -1 else { + guard uuid_parse(string, unsafeBitCast(uuidPointer, to: UnsafeMutablePointer.self)) != -1 else { return nil } - return uuidPointer.memory + return uuidPointer.pointee } diff --git a/Sources/SwiftFoundation/Predicate.swift b/Sources/SwiftFoundation/Predicate.swift index 9b2f3fe..f044b7b 100644 --- a/Sources/SwiftFoundation/Predicate.swift +++ b/Sources/SwiftFoundation/Predicate.swift @@ -15,7 +15,7 @@ public protocol Predicate { func evaluate(object: T) -> Bool } -public extension CollectionType { +public extension Collection { func filter(predicate: Predicate) -> [Self.Generator.Element] { diff --git a/Sources/SwiftFoundation/Range.swift b/Sources/SwiftFoundation/Range.swift index e3bfec6..f4ebf51 100644 --- a/Sources/SwiftFoundation/Range.swift +++ b/Sources/SwiftFoundation/Range.swift @@ -6,7 +6,7 @@ // Copyright © 2016 PureSwift. All rights reserved. // -public extension Range where Element: IntegerType { +public extension Range where Element: Integer { func isSubset(other: Range) -> Bool { diff --git a/Sources/SwiftFoundation/RawRepresentable.swift b/Sources/SwiftFoundation/RawRepresentable.swift index f900510..da269ee 100644 --- a/Sources/SwiftFoundation/RawRepresentable.swift +++ b/Sources/SwiftFoundation/RawRepresentable.swift @@ -26,10 +26,10 @@ public extension RawRepresentable { } } -public extension SequenceType where Self.Generator.Element: RawRepresentable { +public extension Sequence where Self.Iterator.Element: RawRepresentable { /// Convertes a sequence of `RawRepresentable` to its raw values. - var rawValues: [Self.Generator.Element.RawValue] { + var rawValues: [Self.Iterator.Element.RawValue] { return self.map { $0.rawValue } } diff --git a/Sources/SwiftFoundation/RegularExpression.swift b/Sources/SwiftFoundation/RegularExpression.swift index 5c2da41..2333380 100644 --- a/Sources/SwiftFoundation/RegularExpression.swift +++ b/Sources/SwiftFoundation/RegularExpression.swift @@ -145,7 +145,7 @@ public extension String { } func substring(range: Range) -> String? { - let indexRange = utf8.startIndex.advancedBy(range.startIndex) ..< utf8.startIndex.advancedBy(range.endIndex) + let indexRange = utf8.startIndex.advanced(by: range.startIndex) ..< utf8.startIndex.advanced(by: range.endIndex) return String(utf8[indexRange]) } } diff --git a/Sources/SwiftFoundation/RegularExpressionCompileError.swift b/Sources/SwiftFoundation/RegularExpressionCompileError.swift index ad98daf..c6dfac2 100644 --- a/Sources/SwiftFoundation/RegularExpressionCompileError.swift +++ b/Sources/SwiftFoundation/RegularExpressionCompileError.swift @@ -15,7 +15,7 @@ public extension RegularExpression { // POSIX Regular Expression compilation error - public enum CompileError: RawRepresentable, ErrorType { + public enum CompileError: RawRepresentable, ErrorProtocol { /// Invalid use of repetition operators such as using '*' as the first character. /// diff --git a/Sources/SwiftFoundation/SortDescriptor.swift b/Sources/SwiftFoundation/SortDescriptor.swift index 9b22af7..3feb462 100644 --- a/Sources/SwiftFoundation/SortDescriptor.swift +++ b/Sources/SwiftFoundation/SortDescriptor.swift @@ -22,7 +22,7 @@ public protocol SortDescriptorType { // MARK: - Functions /** Returns a sorted array of the collection as specified by the sort descriptor. */ -public func Sort(collection: T, sortDescriptor: S) -> [T.Generator.Element] { +public func Sort(collection: T, sortDescriptor: S) -> [T.Generator.Element] { return collection.sort { (first: T.Generator.Element, second: T.Generator.Element) -> Bool in diff --git a/Sources/SwiftFoundation/String.swift b/Sources/SwiftFoundation/String.swift index 7ca1622..f367206 100644 --- a/Sources/SwiftFoundation/String.swift +++ b/Sources/SwiftFoundation/String.swift @@ -14,6 +14,8 @@ public extension String { var string = "" + fatalError() + /* var generator = data.byteValue.generate() var encoding = UTF8() @@ -22,24 +24,24 @@ public extension String { switch encoding.decode(&generator) { - case .Result (let scalar): + case let .scalarValue(scalar): string.append(scalar) - case .EmptyInput: + case .emptyInput: self = string return - case .Error: + case .error: return nil } } while true - return nil + return nil*/ } func toUTF8Data() -> Data { diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 201782b..8e4629e 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -25,7 +25,11 @@ public final class Thread { let holder = Unmanaged.passRetained(Closure(closure: closure)) - let pointer = UnsafeMutablePointer(holder.toOpaque()) + #if swift(>=3.0) + let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) + #else + let pointer = UnsafeMutablePointer(holder.toOpaque()) + #endif #if os(Linux) var internalThread: pthread_t = 0 @@ -69,7 +73,7 @@ public final class Thread { private func ThreadPrivateMain(arg: UnsafeMutablePointer) -> UnsafeMutablePointer { - let unmanaged = Unmanaged.fromOpaque(COpaquePointer(arg)) + let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) unmanaged.takeUnretainedValue().closure() diff --git a/Sources/SwiftFoundation/URL.swift b/Sources/SwiftFoundation/URL.swift index d3514eb..0f72cfd 100644 --- a/Sources/SwiftFoundation/URL.swift +++ b/Sources/SwiftFoundation/URL.swift @@ -88,7 +88,7 @@ public struct URL: CustomStringConvertible { stringValue += "?" - for (index, queryItem) in query.enumerate() { + for (index, queryItem) in query.enumerated() { let (name, value) = queryItem @@ -148,7 +148,7 @@ public struct URL: CustomStringConvertible { var stringValue = "" - for (index, queryItem) in query.enumerate() { + for (index, queryItem) in query.enumerated() { let (name, value) = queryItem diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 1e7454d..70291cf 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -12,6 +12,10 @@ 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; + 6E0407521CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */; }; + 6E0407531CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */; }; + 6E0407541CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */; }; + 6E041D3D1CB404CD004E080B /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B461C20F6EB00B2C995 /* String.swift */; }; 6E08F85D1BBE7DE900548B1E /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */; }; 6E1ACD4B1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; 6E1ACD4C1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; @@ -190,7 +194,6 @@ 6E2C2C0A1C20F76700B2C995 /* RegularExpressionMatchOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B431C20F6EB00B2C995 /* RegularExpressionMatchOption.swift */; }; 6E2C2C0B1C20F76700B2C995 /* SemanticVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */; }; 6E2C2C0C1C20F76700B2C995 /* SortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */; }; - 6E2C2C0D1C20F76700B2C995 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B461C20F6EB00B2C995 /* String.swift */; }; 6E2C2C0E1C20F76700B2C995 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B471C20F6EB00B2C995 /* Task.swift */; }; 6E2C2C0F1C20F76700B2C995 /* Transformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */; }; 6E2C2C101C20F76700B2C995 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B491C20F6EB00B2C995 /* URL.swift */; }; @@ -300,6 +303,7 @@ 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1AE78FC41B96774300CDEF17 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6E04074D1CB3E07500BE3A79 /* Thread.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Thread.swift; sourceTree = ""; }; + 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackwardsCompatibility.swift; sourceTree = ""; }; 6E08F8571BBE7B8800548B1E /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E1ACD4A1C435822005775FD /* DataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTests.swift; sourceTree = ""; }; 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationConvertible.swift; sourceTree = ""; }; @@ -583,6 +587,7 @@ 6E2C2B461C20F6EB00B2C995 /* String.swift */, 6E2C2B331C20F6EB00B2C995 /* Integer.swift */, 6EFF9A1A1CAD0C6B00917CB3 /* Range.swift */, + 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */, ); name = Swift; sourceTree = ""; @@ -893,6 +898,7 @@ 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */, 6E2C2BD21C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BD91C20F76600B2C995 /* String.swift in Sources */, + 6E0407531CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */, 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2BE01C20F76600B2C995 /* URLResponse.swift in Sources */, 6E2C2BC61C20F76600B2C995 /* Integer.swift in Sources */, @@ -966,6 +972,7 @@ 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */, 6E2C2B9E1C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BA51C20F76600B2C995 /* String.swift in Sources */, + 6E0407541CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */, 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2BAC1C20F76600B2C995 /* URLResponse.swift in Sources */, 6E2C2B921C20F76600B2C995 /* Integer.swift in Sources */, @@ -1061,8 +1068,8 @@ 6E2C2BF61C20F76700B2C995 /* HTTPRequest.swift in Sources */, 6E2C2C011C20F76700B2C995 /* POSIXFileSystemStatus.swift in Sources */, 6E2C2C051C20F76700B2C995 /* Predicate.swift in Sources */, + 6E041D3D1CB404CD004E080B /* String.swift in Sources */, 6E2C2C061C20F76700B2C995 /* RawRepresentable.swift in Sources */, - 6E2C2C0D1C20F76700B2C995 /* String.swift in Sources */, 6E2C2C021C20F76700B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2C141C20F76700B2C995 /* URLResponse.swift in Sources */, 6E2C2BFA1C20F76700B2C995 /* Integer.swift in Sources */, @@ -1082,6 +1089,7 @@ 6E2C2C031C20F76700B2C995 /* POSIXTime.swift in Sources */, 6E2C2B6D1C20F6F700B2C995 /* NSData.swift in Sources */, 6E2C2B6A1C20F6F700B2C995 /* FoundationConvertible.swift in Sources */, + 6E0407521CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */, 6E2C2BF31C20F76700B2C995 /* Formatter.swift in Sources */, 6E2C2C121C20F76700B2C995 /* URLProtocol.swift in Sources */, 6E2C2BFC1C20F76700B2C995 /* JSONExtensions.swift in Sources */, From a7acffc7c72ba836ac9cd0814315394523034de6 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 16:09:26 -0500 Subject: [PATCH 11/68] #27 Updated for Swift 3.0 --- .../FoundationConvertible/HTTPClient.swift | 27 +--------- Sources/FoundationConvertible/NSDate.swift | 4 +- .../NSComparisonResultTests.swift | 4 +- Sources/FoundationUnitTests/NSDateTests.swift | 30 +++++------ .../NSFileManagerTests.swift | 12 ++--- .../NSSortDescriptorTests.swift | 8 +-- Sources/FoundationUnitTests/NSUUIDTests.swift | 16 +++--- .../BackwardsCompatibility.swift | 52 ------------------- Sources/SwiftFoundation/Date.swift | 40 +++++++------- Sources/SwiftFoundation/DateComponents.swift | 4 +- Sources/SwiftFoundation/JSONParse.swift | 4 -- Sources/SwiftFoundation/POSIXFileStatus.swift | 16 +++--- Sources/SwiftFoundation/Predicate.swift | 8 +-- Sources/SwiftFoundation/SortDescriptor.swift | 8 +-- Sources/SwiftFoundation/String.swift | 6 +-- Sources/SwiftFoundation/Thread.swift | 8 +-- Sources/UnitTests/DataTests.swift | 4 +- Sources/UnitTests/DateComponentsTest.swift | 2 +- Sources/UnitTests/JSONTests.swift | 4 +- Sources/UnitTests/POSIXTimeTests.swift | 8 +-- .../UnitTests/RegularExpressionTests.swift | 8 +-- Sources/UnitTests/SortDescriptorTests.swift | 12 ++--- .../SwiftFoundation.xcodeproj/project.pbxproj | 8 --- 23 files changed, 100 insertions(+), 193 deletions(-) delete mode 100644 Sources/SwiftFoundation/BackwardsCompatibility.swift diff --git a/Sources/FoundationConvertible/HTTPClient.swift b/Sources/FoundationConvertible/HTTPClient.swift index 559b03b..5d1ef03 100644 --- a/Sources/FoundationConvertible/HTTPClient.swift +++ b/Sources/FoundationConvertible/HTTPClient.swift @@ -16,15 +16,10 @@ public extension HTTP { /// Loads HTTP requests public final class Client: URLClient { - #if swift(>=3.0) public init(session: NSURLSession = NSURLSession.shared()) { + self.session = session } - #else - public init(session: NSURLSession = NSURLSession.sharedSession()) { - self.session = session - } - #endif /// The backing ```NSURLSession```. public let session: NSURLSession @@ -36,7 +31,7 @@ public extension HTTP { return try sendRequest(request, dataTask: &dataTask) } - public func sendRequest(request: HTTP.Request, inout dataTask: NSURLSessionDataTask?) throws -> HTTP.Response { + public func sendRequest(request: HTTP.Request, dataTask: inout NSURLSessionDataTask?) throws -> HTTP.Response { // build request... @@ -53,8 +48,6 @@ public extension HTTP { var urlResponse: NSHTTPURLResponse? - #if swift(>=3.0) - dataTask = self.session.dataTask(with: urlRequest) { (data: NSData?, response: NSURLResponse?, responseError: NSError?) -> () in responseData = data @@ -66,22 +59,6 @@ public extension HTTP { dispatch_semaphore_signal(semaphore); } - - #else - - dataTask = self.session.dataTaskWithRequest(urlRequest) { (data: NSData?, response: NSURLResponse?, responseError: NSError?) -> () in - - responseData = data - - urlResponse = response as? NSHTTPURLResponse - - error = responseError - - dispatch_semaphore_signal(semaphore); - - } - - #endif dataTask!.resume() diff --git a/Sources/FoundationConvertible/NSDate.swift b/Sources/FoundationConvertible/NSDate.swift index aef1c63..307a0de 100644 --- a/Sources/FoundationConvertible/NSDate.swift +++ b/Sources/FoundationConvertible/NSDate.swift @@ -16,12 +16,12 @@ extension Date: FoundationConvertible { public init(foundation: NSDate) { - self.init(timeIntervalSinceReferenceDate: foundation.timeIntervalSinceReferenceDate) + self.init(sinceReferenceDate: foundation.timeIntervalSinceReferenceDate) } public func toFoundation() -> NSDate { - return NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) + return NSDate(timeIntervalSinceReferenceDate: sinceReferenceDate) } } diff --git a/Sources/FoundationUnitTests/NSComparisonResultTests.swift b/Sources/FoundationUnitTests/NSComparisonResultTests.swift index e13d5a6..3394424 100644 --- a/Sources/FoundationUnitTests/NSComparisonResultTests.swift +++ b/Sources/FoundationUnitTests/NSComparisonResultTests.swift @@ -23,7 +23,7 @@ class NSComparisonResultTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } - + func testComparisonResult() { // number @@ -50,7 +50,7 @@ class NSComparisonResultTests: XCTestCase { let foundationNow = NSDate() - let foundationLater = foundationNow.dateByAddingTimeInterval(0.5) + let foundationLater = foundationNow.addingTimeInterval(0.5) XCTAssert(now.compare(later) == Order(foundation: foundationNow.compare(foundationLater))) diff --git a/Sources/FoundationUnitTests/NSDateTests.swift b/Sources/FoundationUnitTests/NSDateTests.swift index 45bfbfe..2f4deeb 100644 --- a/Sources/FoundationUnitTests/NSDateTests.swift +++ b/Sources/FoundationUnitTests/NSDateTests.swift @@ -24,7 +24,7 @@ class DateTests: XCTestCase { let timeIntervalSinceReferenceDate = NSDate.timeIntervalSinceReferenceDate() - date = Date(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) + date = Date(sinceReferenceDate: timeIntervalSinceReferenceDate) foundationDate = NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) } @@ -44,12 +44,12 @@ class DateTests: XCTestCase { let timeIntervalSinceReferenceDate = NSDate.timeIntervalSinceReferenceDate() - let date = Date(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) + let date = Date(sinceReferenceDate: timeIntervalSinceReferenceDate) let FoundationDate = NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) - XCTAssert(date.timeIntervalSinceReferenceDate == FoundationDate.timeIntervalSinceReferenceDate, - "Date's internal values must be equal. (\(date.timeIntervalSinceReferenceDate) != \(FoundationDate.timeIntervalSinceReferenceDate))") + XCTAssert(date.sinceReferenceDate == FoundationDate.timeIntervalSinceReferenceDate, + "Date's internal values must be equal. (\(date.sinceReferenceDate) != \(FoundationDate.timeIntervalSinceReferenceDate))") } func testTimeIntervalSinceReferenceDateSecondsPrecision() { @@ -76,13 +76,13 @@ class DateTests: XCTestCase { let time2 = NSDate.timeIntervalSinceReferenceDate() - let date2 = Date(timeIntervalSinceReferenceDate: time2) + let date2 = Date(sinceReferenceDate: time2) let foundationDate2 = NSDate(timeIntervalSinceReferenceDate: time2) let intervalSinceDate = date.timeIntervalSinceDate(date2) - let foundationIntervalSinceDate = foundationDate.timeIntervalSinceDate(foundationDate2) + let foundationIntervalSinceDate = foundationDate.timeInterval(since: foundationDate2) XCTAssert(intervalSinceDate == foundationIntervalSinceDate) } @@ -91,7 +91,7 @@ class DateTests: XCTestCase { let date = Date() - let date2 = Date(timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate) + let date2 = Date(sinceReferenceDate: date.sinceReferenceDate) let foundationDate = NSDate() @@ -111,27 +111,27 @@ class DateTests: XCTestCase { let date = Date() - let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate) + let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.sinceReferenceDate) - XCTAssert(date.timeIntervalSince1970 == foundationDate.timeIntervalSince1970) + XCTAssert(date.since1970 == foundationDate.timeIntervalSince1970) } func testCreateWithTimeIntervalSince1970() { let date = Date() - XCTAssert(Date(timeIntervalSince1970: date.timeIntervalSince1970) == date, "Date should be the same as original") + XCTAssert(Date(since1970: date.since1970) == date, "Date should be the same as original") } func testSetWithTimeIntervalSince1970() { var date = Date() - let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.timeIntervalSinceReferenceDate) + let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.sinceReferenceDate) - date.timeIntervalSince1970 = foundationDate.timeIntervalSince1970 + date.since1970 = foundationDate.timeIntervalSince1970 - XCTAssert(date.timeIntervalSinceReferenceDate == foundationDate.timeIntervalSinceReferenceDate) + XCTAssert(date.sinceReferenceDate == foundationDate.timeIntervalSinceReferenceDate) } /* @@ -153,7 +153,7 @@ class DateTests: XCTestCase { func testCreationPerformance() { - self.measureBlock() { + self.measure { for _ in 0...1000000 { @@ -164,7 +164,7 @@ class DateTests: XCTestCase { func testFoundationCreationPerformance() { - self.measureBlock() { + self.measure { for _ in 0...1000000 { diff --git a/Sources/FoundationUnitTests/NSFileManagerTests.swift b/Sources/FoundationUnitTests/NSFileManagerTests.swift index 60baed1..b8635df 100644 --- a/Sources/FoundationUnitTests/NSFileManagerTests.swift +++ b/Sources/FoundationUnitTests/NSFileManagerTests.swift @@ -35,7 +35,7 @@ class FileManagerTests: XCTestCase { let path = NSTemporaryDirectory() + "/" + fileName - XCTAssert(NSFileManager.defaultManager().createFileAtPath(path, contents: NSData(), attributes: nil)) + XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: NSData(), attributes: nil)) XCTAssert(FileManager.fileExists(path)) @@ -44,9 +44,9 @@ class FileManagerTests: XCTestCase { func testDirectoryExists() { - let path = try! NSFileManager.defaultManager().URLForDirectory(NSSearchPathDirectory.UserDirectory, inDomain: NSSearchPathDomainMask.AllDomainsMask, appropriateForURL: nil, create: false).path! + let path = try! NSFileManager.defaultManager().url(for: NSSearchPathDirectory.userDirectory, in: NSSearchPathDomainMask.allDomainsMask, appropriateFor: nil, create: false).path! - assert(NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: nil), + assert(NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: nil), "Setting non existent directory as test parameter") XCTAssert(FileManager.directoryExists(path)) @@ -66,7 +66,7 @@ class FileManagerTests: XCTestCase { let path = NSTemporaryDirectory() + "/" + fileName + ".txt" - XCTAssert(NSFileManager.defaultManager().createFileAtPath(path, contents: data.toFoundation(), attributes: nil)) + XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: data.toFoundation(), attributes: nil)) // read file @@ -92,7 +92,7 @@ class FileManagerTests: XCTestCase { let path = NSTemporaryDirectory() + fileName + ".txt" // create empty file - XCTAssert(NSFileManager.defaultManager().createFileAtPath(path, contents: NSData(), attributes: nil)) + XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: NSData(), attributes: nil)) // write file do { try FileManager.setContents(path, data: data) } @@ -126,7 +126,7 @@ class FileManagerTests: XCTestCase { // read data - XCTAssert(NSFileManager.defaultManager().fileExistsAtPath(path)) + XCTAssert(NSFileManager.defaultManager().fileExists(atPath: path)) NSFileManager.defaultManager() diff --git a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift index 6030e12..06d9f00 100644 --- a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift +++ b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift @@ -32,9 +32,9 @@ class NSSortDescriptorTests: XCTestCase { let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: ascending)) - let foundationSortedItems = (items as NSArray).sortedArrayUsingDescriptors([NSSortDescriptor(key: nil, ascending: ascending)]) + let foundationSortedItems = (items as NSArray).sortedArray(using: [NSSortDescriptor(key: nil, ascending: ascending)]) - for (index, element) in sortedItems.enumerate() { + for (index, element) in sortedItems.enumerated() { let foundationElement = foundationSortedItems[index] @@ -69,9 +69,9 @@ class NSSortDescriptorTests: XCTestCase { return first.compare(second) })) - let foundationSortedItems = (items as NSArray).sortedArrayUsingDescriptors([NSSortDescriptor(key: nil, ascending: ascending)]) + let foundationSortedItems = (items as NSArray).sortedArray(using: [NSSortDescriptor(key: nil, ascending: ascending)]) - for (index, element) in sortedItems.enumerate() { + for (index, element) in sortedItems.enumerated() { let foundationElement = foundationSortedItems[index] diff --git a/Sources/FoundationUnitTests/NSUUIDTests.swift b/Sources/FoundationUnitTests/NSUUIDTests.swift index 6832fd5..e354159 100644 --- a/Sources/FoundationUnitTests/NSUUIDTests.swift +++ b/Sources/FoundationUnitTests/NSUUIDTests.swift @@ -42,7 +42,7 @@ class NSUUIDTests: XCTestCase { let uuid = UUID(byteValue: foundationUUID.byteValue) - XCTAssert(foundationUUID.UUIDString == uuid.rawValue) + XCTAssert(foundationUUID.uuidString == uuid.rawValue) } func testUUIDValidBytes() { @@ -51,12 +51,12 @@ class NSUUIDTests: XCTestCase { let foundationUUID = NSUUID(byteValue: uuid.byteValue) - XCTAssert(uuid.rawValue == foundationUUID.UUIDString) + XCTAssert(uuid.rawValue == foundationUUID.uuidString) } func testCreateFromString() { - let stringValue = NSUUID().UUIDString + let stringValue = NSUUID().uuidString XCTAssert((UUID(rawValue: stringValue) != nil), "Could not create UUID with string \"\(stringValue)\"") @@ -67,7 +67,7 @@ class NSUUIDTests: XCTestCase { func testCreationPerformance() { - self.measureBlock() { + self.measure { for _ in 0...1000000 { @@ -78,7 +78,7 @@ class NSUUIDTests: XCTestCase { func testFoundationCreationPerformance() { - self.measureBlock() { + self.measure { for _ in 0...1000000 { @@ -91,7 +91,7 @@ class NSUUIDTests: XCTestCase { let uuid = UUID() - self.measureBlock { () -> Void in + self.measure { for _ in 0...10000 { @@ -104,11 +104,11 @@ class NSUUIDTests: XCTestCase { let uuid = NSUUID() - self.measureBlock { () -> Void in + self.measure { for _ in 0...10000 { - _ = uuid.UUIDString + _ = uuid.uuidString } } } diff --git a/Sources/SwiftFoundation/BackwardsCompatibility.swift b/Sources/SwiftFoundation/BackwardsCompatibility.swift deleted file mode 100644 index ba97a63..0000000 --- a/Sources/SwiftFoundation/BackwardsCompatibility.swift +++ /dev/null @@ -1,52 +0,0 @@ -// -// BackwardsCompatibility.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 4/5/16. -// Copyright © 2016 PureSwift. All rights reserved. -// - -// Swift 2.2 compatibility -#if !swift(>=3.0) - - public typealias ErrorProtocol = ErrorType - - public typealias OpaquePointer = COpaquePointer - - public typealias Collection = CollectionType - - public typealias Sequence = SequenceType - - public typealias Integer = IntegerType - - public extension Sequence { - public typealias Generator = Iterator - } - - public extension String { - - @inline(__always) - func uppercased() { return uppercaseString } - - init?(validatingUTF8 cString: UnsafePointer) { - - self = Swift.String.fromCString(cString) - } - } - - public extension UnsafeMutablePointer { - - init(allocatingCapacity count: Int) { - - self = self.alloc(count) - } - - func deallocateCapacity(count: Int) { - - self.dealloc(count) - } - - public var pointee: Memory { } - } - -#endif diff --git a/Sources/SwiftFoundation/Date.swift b/Sources/SwiftFoundation/Date.swift index 46d5d26..cc2e247 100644 --- a/Sources/SwiftFoundation/Date.swift +++ b/Sources/SwiftFoundation/Date.swift @@ -18,14 +18,14 @@ public struct Date: Equatable, Comparable, CustomStringConvertible { // MARK: - Properties /// The time interval between the date and the reference date (1 January 2001, GMT). - public var timeIntervalSinceReferenceDate: TimeInterval + public var sinceReferenceDate: TimeInterval /// The time interval between the current date and 1 January 1970, GMT. - public var timeIntervalSince1970: TimeInterval { + public var since1970: TimeInterval { - get { return timeIntervalSinceReferenceDate + TimeIntervalBetween1970AndReferenceDate } + get { return sinceReferenceDate + TimeIntervalBetween1970AndReferenceDate } - set { timeIntervalSinceReferenceDate = timeIntervalSince1970 - TimeIntervalBetween1970AndReferenceDate } + set { sinceReferenceDate = since1970 - TimeIntervalBetween1970AndReferenceDate } } /// Returns the difference between two dates. @@ -36,7 +36,7 @@ public struct Date: Equatable, Comparable, CustomStringConvertible { public var description: String { - return "\(timeIntervalSinceReferenceDate)" + return "\(sinceReferenceDate)" } // MARK: - Initialization @@ -44,19 +44,19 @@ public struct Date: Equatable, Comparable, CustomStringConvertible { /// Creates the date with the current time. public init() { - timeIntervalSinceReferenceDate = TimeIntervalSinceReferenceDate() + sinceReferenceDate = TimeIntervalSinceReferenceDate() } /// Creates the date with the specified time interval since the reference date (1 January 2001, GMT). - public init(timeIntervalSinceReferenceDate timeInterval: TimeInterval) { + public init(sinceReferenceDate timeInterval: TimeInterval) { - timeIntervalSinceReferenceDate = timeInterval + sinceReferenceDate = timeInterval } /// Creates the date with the specified time interval since 1 January 1970, GMT. - public init(timeIntervalSince1970 timeInterval: TimeInterval) { + public init(since1970 timeInterval: TimeInterval) { - timeIntervalSinceReferenceDate = timeInterval - TimeIntervalBetween1970AndReferenceDate + sinceReferenceDate = timeInterval - TimeIntervalBetween1970AndReferenceDate } } @@ -64,50 +64,50 @@ public struct Date: Equatable, Comparable, CustomStringConvertible { public func == (lhs: Date, rhs: Date) -> Bool { - return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate + return lhs.sinceReferenceDate == rhs.sinceReferenceDate } public func < (lhs: Date, rhs: Date) -> Bool { - return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate + return lhs.sinceReferenceDate < rhs.sinceReferenceDate } public func <= (lhs: Date, rhs: Date) -> Bool { - return lhs.timeIntervalSinceReferenceDate <= rhs.timeIntervalSinceReferenceDate + return lhs.sinceReferenceDate <= rhs.sinceReferenceDate } public func >= (lhs: Date, rhs: Date) -> Bool { - return lhs.timeIntervalSinceReferenceDate >= rhs.timeIntervalSinceReferenceDate + return lhs.sinceReferenceDate >= rhs.sinceReferenceDate } public func > (lhs: Date, rhs: Date) -> Bool { - return lhs.timeIntervalSinceReferenceDate > rhs.timeIntervalSinceReferenceDate + return lhs.sinceReferenceDate > rhs.sinceReferenceDate } public func - (lhs: Date, rhs: Date) -> TimeInterval { - return lhs.timeIntervalSinceReferenceDate - rhs.timeIntervalSinceReferenceDate + return lhs.sinceReferenceDate - rhs.sinceReferenceDate } public func + (lhs: Date, rhs: TimeInterval) -> Date { - return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate + rhs) + return Date(sinceReferenceDate: lhs.sinceReferenceDate + rhs) } -public func += (inout lhs: Date, rhs: TimeInterval) { +public func += (lhs: inout Date, rhs: TimeInterval) { lhs = lhs + rhs } public func - (lhs: Date, rhs: TimeInterval) -> Date { - return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate - rhs) + return Date(sinceReferenceDate: lhs.sinceReferenceDate - rhs) } -public func -= (inout lhs: Date, rhs: TimeInterval) { +public func -= (lhs: inout Date, rhs: TimeInterval) { lhs = lhs - rhs } diff --git a/Sources/SwiftFoundation/DateComponents.swift b/Sources/SwiftFoundation/DateComponents.swift index ce79f64..0ccb084 100644 --- a/Sources/SwiftFoundation/DateComponents.swift +++ b/Sources/SwiftFoundation/DateComponents.swift @@ -46,11 +46,11 @@ public struct DateComponents { } public init(fromDate date: Date) { - self.init(timeInterval: date.timeIntervalSince1970) + self.init(timeInterval: date.since1970) } public var date: Date { - return Date(timeIntervalSince1970: timeInterval) + return Date(since1970: timeInterval) } public mutating func setValue(value: Int32, forComponent component: Component) { diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index a5769c5..bd474bc 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -27,11 +27,7 @@ public extension JSON.Value { // could not parse guard tokenerError != nil else { return nil } - #if swift(>=3.0) self = self.dynamicType.init(jsonObject: jsonObject) - #else - self.init(jsonObject: jsonObject) - #endif } } diff --git a/Sources/SwiftFoundation/POSIXFileStatus.swift b/Sources/SwiftFoundation/POSIXFileStatus.swift index 1004db7..b992c22 100644 --- a/Sources/SwiftFoundation/POSIXFileStatus.swift +++ b/Sources/SwiftFoundation/POSIXFileStatus.swift @@ -39,8 +39,8 @@ public extension stat { /// Other routines, like ```mmap```, may or may not update ```st_atime```. var lastAccessDate: Date { - get { return Date(timeIntervalSince1970: st_atimespec.timeIntervalValue) } - set { st_atimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } + get { return Date(since1970: st_atimespec.timeIntervalValue) } + set { st_atimespec = timespec(timeInterval: lastDataModificationDate.since1970) } } /// Date of last data modification. Date of ```st_mtimespec``` or ```st_mtime```. @@ -50,8 +50,8 @@ public extension stat { /// The ```st_mtime``` field is not changed for changes in owner, group, hard link count, or mode. var lastDataModificationDate: Date { - get { return Date(timeIntervalSince1970: st_mtimespec.timeIntervalValue) } - set { st_mtimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } + get { return Date(since1970: st_mtimespec.timeIntervalValue) } + set { st_mtimespec = timespec(timeInterval: lastDataModificationDate.since1970) } } /// Date of last status change. Date of ```st_ctimespec``` or ```st_ctime```. @@ -59,15 +59,15 @@ public extension stat { /// The field ```st_ctime``` is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.). var lastStatusChangeDate: Date { - get { return Date(timeIntervalSince1970: st_ctimespec.timeIntervalValue) } - set { st_ctimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } + get { return Date(since1970: st_ctimespec.timeIntervalValue) } + set { st_ctimespec = timespec(timeInterval: lastDataModificationDate.since1970) } } /// Date file was created. Date of ```st_birthtimespec``` or ```st_birthtime```. var creationDate: Date { - get { return Date(timeIntervalSince1970: st_birthtimespec.timeIntervalValue) } - set { st_birthtimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } + get { return Date(since1970: st_birthtimespec.timeIntervalValue) } + set { st_birthtimespec = timespec(timeInterval: lastDataModificationDate.since1970) } } var fileSize: Int { diff --git a/Sources/SwiftFoundation/Predicate.swift b/Sources/SwiftFoundation/Predicate.swift index f044b7b..6b21f5e 100644 --- a/Sources/SwiftFoundation/Predicate.swift +++ b/Sources/SwiftFoundation/Predicate.swift @@ -17,9 +17,9 @@ public protocol Predicate { public extension Collection { - func filter(predicate: Predicate) -> [Self.Generator.Element] { + func filter(predicate: Predicate) -> [Self.Iterator.Element] { - return self.filter({ (element: Self.Generator.Element) -> Bool in + return self.filter({ (element: Self.Iterator.Element) -> Bool in return predicate.evaluate(element) }) @@ -27,11 +27,11 @@ public extension Collection { } /* -public extension SequenceType { +public extension Sequence { public func contains(predicate: Predicate -> Bool) -> Bool { - return self.contains({ (element: Self.Generator.Element) -> Bool in + return self.contains({ (element: Self.Iterator.Element) -> Bool in return predicate.evaluate(element) }) diff --git a/Sources/SwiftFoundation/SortDescriptor.swift b/Sources/SwiftFoundation/SortDescriptor.swift index 3feb462..52ebcb9 100644 --- a/Sources/SwiftFoundation/SortDescriptor.swift +++ b/Sources/SwiftFoundation/SortDescriptor.swift @@ -22,9 +22,9 @@ public protocol SortDescriptorType { // MARK: - Functions /** Returns a sorted array of the collection as specified by the sort descriptor. */ -public func Sort(collection: T, sortDescriptor: S) -> [T.Generator.Element] { +public func Sort(collection: T, sortDescriptor: S) -> [T.Iterator.Element] { - return collection.sort { (first: T.Generator.Element, second: T.Generator.Element) -> Bool in + return collection.sorted { (first: T.Iterator.Element, second: T.Iterator.Element) -> Bool in let order = sortDescriptor.sort(first, second: second) @@ -47,9 +47,9 @@ public func Sort(collection: T, sortDescriptors: [S]) -> [T.Generator.Element] { +public func Sort(collection: T, sortDescriptors: [S]) -> [T.Iterator.Element] { - var sortedArray = collection.map { (element: T.Generator.Element) -> T in } + var sortedArray = collection.map { (element: T.Iterator.Element) -> T in } for sortDescriptor in sortDescriptors { diff --git a/Sources/SwiftFoundation/String.swift b/Sources/SwiftFoundation/String.swift index f367206..85b0af5 100644 --- a/Sources/SwiftFoundation/String.swift +++ b/Sources/SwiftFoundation/String.swift @@ -14,9 +14,7 @@ public extension String { var string = "" - fatalError() - /* - var generator = data.byteValue.generate() + var generator = data.byteValue.makeIterator() var encoding = UTF8() @@ -41,7 +39,7 @@ public extension String { } while true - return nil*/ + return nil } func toUTF8Data() -> Data { diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 8e4629e..3095abc 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -25,11 +25,7 @@ public final class Thread { let holder = Unmanaged.passRetained(Closure(closure: closure)) - #if swift(>=3.0) - let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) - #else - let pointer = UnsafeMutablePointer(holder.toOpaque()) - #endif + let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) #if os(Linux) var internalThread: pthread_t = 0 @@ -47,7 +43,7 @@ public final class Thread { // MARK: - Class Methods - public static func exit(inout code: Int) { + public static func exit(code: inout Int) { pthread_exit(&code) } diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index a5b48c8..92a0d33 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -25,9 +25,9 @@ final class DataTests: XCTestCase { let dataLength = testData.byteValue.count - let dataPointer = UnsafeMutablePointer.alloc(dataLength) + let dataPointer = UnsafeMutablePointer(allocatingCapacity: dataLength) - defer { dataPointer.dealloc(dataLength) } + defer { dataPointer.deallocateCapacity(dataLength) } memcpy(&testData.byteValue, dataPointer, dataLength) diff --git a/Sources/UnitTests/DateComponentsTest.swift b/Sources/UnitTests/DateComponentsTest.swift index 7f55bf0..926527d 100644 --- a/Sources/UnitTests/DateComponentsTest.swift +++ b/Sources/UnitTests/DateComponentsTest.swift @@ -20,7 +20,7 @@ final class DateComponentsTest: XCTestCase { dateComponents.month = 10 dateComponents.dayOfMonth = 10 - let assertionDate = Date(timeIntervalSince1970: 560822400) + let assertionDate = Date(since1970: 560822400) let madeDate = dateComponents.date print(assertionDate, madeDate) diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 8b8b9b1..63020a5 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -42,7 +42,7 @@ final class JSONTests: XCTestCase { // validate JSON string on Darwin do { - try NSJSONSerialization.JSONObjectWithData(jsonString.toUTF8Data().toFoundation(), options: NSJSONReadingOptions()) + try NSJSONSerialization.jsonObject(with: jsonString.toUTF8Data().toFoundation(), options: NSJSONReadingOptions(rawValue: 0)) } catch { XCTFail("Invalid JSON String"); return } @@ -88,7 +88,7 @@ final class JSONTests: XCTestCase { #if os(OSX) || os(iOS) - let foundationJSONOutput = try! NSJSONSerialization.dataWithJSONObject(json.toFoundation().rawValue, options: NSJSONWritingOptions()) + let foundationJSONOutput = try! NSJSONSerialization.data(withJSONObject: json.toFoundation().rawValue, options: NSJSONWritingOptions(rawValue: 0)) let foundationJSONOutputString = NSString(data: foundationJSONOutput, encoding: NSUTF8StringEncoding) diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index 3882bf9..f0cad67 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -35,20 +35,20 @@ final class POSIXTimeTests: XCTestCase { let date = Date() - let time = timeval(timeInterval: date.timeIntervalSince1970) + let time = timeval(timeInterval: date.since1970) - XCTAssert(Int(time.timeIntervalValue) == Int(date.timeIntervalSince1970), "TimeVal derived interval: \(time.timeIntervalValue) must equal Date's timeIntervalSince1970 \(date.timeIntervalSince1970)") + XCTAssert(Int(time.timeIntervalValue) == Int(date.since1970), "TimeVal derived interval: \(time.timeIntervalValue) must equal Date's timeIntervalSince1970 \(date.since1970)") } func testTimeSpec() { let date = Date() - let time = timespec(timeInterval: date.timeIntervalSince1970) + let time = timespec(timeInterval: date.since1970) #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - XCTAssert(time.timeIntervalValue == date.timeIntervalSince1970, "timespec: \(time.timeIntervalValue) == Date: \(date)") + XCTAssert(time.timeIntervalValue == date.since1970, "timespec: \(time.timeIntervalValue) == Date: \(date)") #elseif os(Linux) diff --git a/Sources/UnitTests/RegularExpressionTests.swift b/Sources/UnitTests/RegularExpressionTests.swift index 6f418d6..ffe9a11 100644 --- a/Sources/UnitTests/RegularExpressionTests.swift +++ b/Sources/UnitTests/RegularExpressionTests.swift @@ -29,7 +29,7 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substringWithRange(stringRange) + let matchString = string.toFoundation().substring(with: stringRange) XCTAssert(matchString == "Welcome") } @@ -47,7 +47,7 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substringWithRange(stringRange) + let matchString = string.toFoundation().substring(with: stringRange) XCTAssert(matchString == "aaa") } @@ -64,7 +64,7 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substringWithRange(stringRange) + let matchString = string.toFoundation().substring(with: stringRange) XCTAssert(matchString == "Bird", matchString) } @@ -81,7 +81,7 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substringWithRange(stringRange) + let matchString = string.toFoundation().substring(with: stringRange) // matched whole string XCTAssert(matchString == string) diff --git a/Sources/UnitTests/SortDescriptorTests.swift b/Sources/UnitTests/SortDescriptorTests.swift index 6fa411a..77c049d 100644 --- a/Sources/UnitTests/SortDescriptorTests.swift +++ b/Sources/UnitTests/SortDescriptorTests.swift @@ -27,7 +27,7 @@ final class SortDescriptorTests: XCTestCase { let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: true)) - let expected = items.sort() + let expected = items.sorted() XCTAssert(expected == sortedItems, "Ascending: \(expected) == \(sortedItems)") } @@ -38,7 +38,7 @@ final class SortDescriptorTests: XCTestCase { let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: false)) - let expected = Array(items.sort().reverse()) + let expected = Array(items.sorted().reversed()) XCTAssert(expected == sortedItems, "Descending: \(expected) == \(sortedItems)") } @@ -51,7 +51,7 @@ final class SortDescriptorTests: XCTestCase { let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: true)) - let expected = items.sort() + let expected = items.sorted() XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") } @@ -62,7 +62,7 @@ final class SortDescriptorTests: XCTestCase { let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: false)) - let expected = Array(items.sort().reverse()) + let expected = Array(items.sorted().reversed()) XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") } @@ -81,7 +81,7 @@ final class SortDescriptorTests: XCTestCase { return first.compare(second) })) - let expected = items.sort() + let expected = items.sorted() XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") } @@ -95,7 +95,7 @@ final class SortDescriptorTests: XCTestCase { return first.compare(second) })) - let expected = Array(items.sort().reverse()) + let expected = Array(items.sorted().reversed()) XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") } diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 70291cf..b3370eb 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -12,9 +12,6 @@ 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; }; - 6E0407521CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */; }; - 6E0407531CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */; }; - 6E0407541CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */; }; 6E041D3D1CB404CD004E080B /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B461C20F6EB00B2C995 /* String.swift */; }; 6E08F85D1BBE7DE900548B1E /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */; }; 6E1ACD4B1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; @@ -303,7 +300,6 @@ 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1AE78FC41B96774300CDEF17 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6E04074D1CB3E07500BE3A79 /* Thread.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Thread.swift; sourceTree = ""; }; - 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackwardsCompatibility.swift; sourceTree = ""; }; 6E08F8571BBE7B8800548B1E /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E1ACD4A1C435822005775FD /* DataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTests.swift; sourceTree = ""; }; 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationConvertible.swift; sourceTree = ""; }; @@ -587,7 +583,6 @@ 6E2C2B461C20F6EB00B2C995 /* String.swift */, 6E2C2B331C20F6EB00B2C995 /* Integer.swift */, 6EFF9A1A1CAD0C6B00917CB3 /* Range.swift */, - 6E0407511CB3EE1C00BE3A79 /* BackwardsCompatibility.swift */, ); name = Swift; sourceTree = ""; @@ -898,7 +893,6 @@ 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */, 6E2C2BD21C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BD91C20F76600B2C995 /* String.swift in Sources */, - 6E0407531CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */, 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2BE01C20F76600B2C995 /* URLResponse.swift in Sources */, 6E2C2BC61C20F76600B2C995 /* Integer.swift in Sources */, @@ -972,7 +966,6 @@ 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */, 6E2C2B9E1C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BA51C20F76600B2C995 /* String.swift in Sources */, - 6E0407541CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */, 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2BAC1C20F76600B2C995 /* URLResponse.swift in Sources */, 6E2C2B921C20F76600B2C995 /* Integer.swift in Sources */, @@ -1089,7 +1082,6 @@ 6E2C2C031C20F76700B2C995 /* POSIXTime.swift in Sources */, 6E2C2B6D1C20F6F700B2C995 /* NSData.swift in Sources */, 6E2C2B6A1C20F6F700B2C995 /* FoundationConvertible.swift in Sources */, - 6E0407521CB3EE1C00BE3A79 /* BackwardsCompatibility.swift in Sources */, 6E2C2BF31C20F76700B2C995 /* Formatter.swift in Sources */, 6E2C2C121C20F76700B2C995 /* URLProtocol.swift in Sources */, 6E2C2BFC1C20F76700B2C995 /* JSONExtensions.swift in Sources */, From 0be3f8ced16ecda7078274a052d9326aa58adc94 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 16:52:01 -0500 Subject: [PATCH 12/68] #27 Updated unit tests for Swift 3.0 on Linux --- Package.swift | 9 +-- Sources/SwiftFoundation/POSIXError.swift | 2 +- Sources/UnitTests/DataTests.swift | 2 +- Sources/UnitTests/DateComponentsTest.swift | 2 +- Sources/UnitTests/JSONTests.swift | 8 +-- Sources/UnitTests/OrderTests.swift | 2 +- Sources/UnitTests/POSIXTimeTests.swift | 8 +-- Sources/UnitTests/RangeTests.swift | 2 +- .../UnitTests/RegularExpressionTests.swift | 56 +++++++++---------- Sources/UnitTests/SortDescriptorTests.swift | 6 +- Sources/UnitTests/StringTests.swift | 2 +- Sources/UnitTests/UUIDTests.swift | 10 ++-- Sources/UnitTests/main.swift | 31 +++++----- .../SwiftFoundation.xcodeproj/project.pbxproj | 2 +- 14 files changed, 66 insertions(+), 76 deletions(-) diff --git a/Package.swift b/Package.swift index b62508b..fc461df 100644 --- a/Package.swift +++ b/Package.swift @@ -11,13 +11,8 @@ let package = Package( Target( name: "UnitTests", dependencies: [.Target(name: "SwiftFoundation")]), - Target( - name: "FoundationUnitTests", - dependencies: [.Target(name: "SwiftFoundation")]), - Target( - name: "FoundationConvertible", - dependencies: [.Target(name: "SwiftFoundation")]), Target( name: "SwiftFoundation") - ] + ], + exclude: ["Xcode", "Carthage", "Sources/FoundationConvertible", "Sources/FoundationUnitTests"] ) \ No newline at end of file diff --git a/Sources/SwiftFoundation/POSIXError.swift b/Sources/SwiftFoundation/POSIXError.swift index 4539fe1..eff8a7d 100644 --- a/Sources/SwiftFoundation/POSIXError.swift +++ b/Sources/SwiftFoundation/POSIXError.swift @@ -21,7 +21,7 @@ public extension POSIXError { #if os(Linux) /// Enumeration describing POSIX error codes. - public enum POSIXError: ErrorType, RawRepresentable { + public enum POSIXError: ErrorProtocol, RawRepresentable { case Value(CInt) diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index 92a0d33..e3401b9 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -15,7 +15,7 @@ import SwiftFoundation final class DataTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = [("testFromBytePointer", self.testFromBytePointer)] + static let allTests: [(String, DataTests -> () throws -> Void)] = [("testFromBytePointer", testFromBytePointer)] func testFromBytePointer() { diff --git a/Sources/UnitTests/DateComponentsTest.swift b/Sources/UnitTests/DateComponentsTest.swift index 926527d..94eb648 100644 --- a/Sources/UnitTests/DateComponentsTest.swift +++ b/Sources/UnitTests/DateComponentsTest.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class DateComponentsTest: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = [("testBuildDate", self.testBuildDate)] + static let allTests: [(String, DateComponentsTest -> () throws -> Void)] = [("testBuildDate", testBuildDate)] func testBuildDate() { diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 63020a5..482301c 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -11,11 +11,11 @@ import SwiftFoundation final class JSONTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = [ + static let allTests: [(String, JSONTests -> () throws -> Void)] = [ - ("testJSONEncodable", self.testJSONEncodable), - ("testJSONParse", self.testJSONParse), - ("testJSONWriting", self.testJSONWriting) + ("testJSONEncodable", testJSONEncodable), + ("testJSONParse", testJSONParse), + ("testJSONWriting", testJSONWriting) ] func testJSONEncodable() { diff --git a/Sources/UnitTests/OrderTests.swift b/Sources/UnitTests/OrderTests.swift index 8b3dbec..4470c64 100644 --- a/Sources/UnitTests/OrderTests.swift +++ b/Sources/UnitTests/OrderTests.swift @@ -12,7 +12,7 @@ import SwiftFoundation final class OrderTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = [("testComparisonResult", self.testComparisonResult)] + static let allTests: [(String, OrderTests -> () throws -> Void)] = [("testComparisonResult", testComparisonResult)] func testComparisonResult() { diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index f0cad67..3ca9753 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -17,10 +17,10 @@ import SwiftFoundation final class POSIXTimeTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = - [("testGetTimeOfDay", self.testGetTimeOfDay), - ("testTimeVal", self.testTimeVal), - ("testTimeSpec", self.testTimeSpec)] + static let allTests: [(String, POSIXTimeTests -> () throws -> Void)] = + [("testGetTimeOfDay", testGetTimeOfDay), + ("testTimeVal", testTimeVal), + ("testTimeSpec", testTimeSpec)] func testGetTimeOfDay() { diff --git a/Sources/UnitTests/RangeTests.swift b/Sources/UnitTests/RangeTests.swift index 393403b..cb243ca 100644 --- a/Sources/UnitTests/RangeTests.swift +++ b/Sources/UnitTests/RangeTests.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class RangeTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = [ ("testSubset", self.testSubset) ] + static let allTests: [(String, RangeTests -> () throws -> Void)] = [ ("testSubset", testSubset) ] func testSubset() { diff --git a/Sources/UnitTests/RegularExpressionTests.swift b/Sources/UnitTests/RegularExpressionTests.swift index ffe9a11..c1ba7ce 100644 --- a/Sources/UnitTests/RegularExpressionTests.swift +++ b/Sources/UnitTests/RegularExpressionTests.swift @@ -12,11 +12,11 @@ import Foundation final class RegularExpressionTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = - [("testSimpleRegex", self.testSimpleRegex), - ("testExtendedRegex", self.testExtendedRegex), - ("testMultipleSubexpressions", self.testMultipleSubexpressions), - ("testEmoji", self.testEmoji)] + static let allTests: [(String, RegularExpressionTests -> () throws -> Void)] = + [("testSimpleRegex", testSimpleRegex), + ("testExtendedRegex", testExtendedRegex), + ("testMultipleSubexpressions", testMultipleSubexpressions), + ("testEmoji", testEmoji)] func testSimpleRegex() { @@ -29,7 +29,11 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substring(with: stringRange) + #if os(Linux) + let matchString = NSString(string: string).substringWithRange(stringRange) + #else + let matchString = NSString(string: string).substring(with: stringRange) + #endif XCTAssert(matchString == "Welcome") } @@ -47,7 +51,11 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substring(with: stringRange) + #if os(Linux) + let matchString = NSString(string: string).substringWithRange(stringRange) + #else + let matchString = NSString(string: string).substring(with: stringRange) + #endif XCTAssert(matchString == "aaa") } @@ -64,7 +72,11 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substring(with: stringRange) + #if os(Linux) + let matchString = NSString(string: string).substringWithRange(stringRange) + #else + let matchString = NSString(string: string).substring(with: stringRange) + #endif XCTAssert(matchString == "Bird", matchString) } @@ -81,7 +93,11 @@ final class RegularExpressionTests: XCTestCase { let stringRange = NSRange(match.range) - let matchString = string.toFoundation().substring(with: stringRange) + #if os(Linux) + let matchString = NSString(string: string).substringWithRange(stringRange) + #else + let matchString = NSString(string: string).substring(with: stringRange) + #endif // matched whole string XCTAssert(matchString == string) @@ -124,25 +140,3 @@ final class RegularExpressionTests: XCTestCase { } } } - -// MARK: - Private - -#if os(Linux) - -extension String { - - public init(foundation: NSString) { - - self.init("\(foundation)") - } - - public func toFoundation() -> NSString { - - guard let foundationString = NSString(bytes: self, length: self.utf8.count, encoding: NSUTF8StringEncoding) - else { fatalError("Could not convert String to NSString") } - - return foundationString - } -} - -#endif diff --git a/Sources/UnitTests/SortDescriptorTests.swift b/Sources/UnitTests/SortDescriptorTests.swift index 77c049d..f3656ca 100644 --- a/Sources/UnitTests/SortDescriptorTests.swift +++ b/Sources/UnitTests/SortDescriptorTests.swift @@ -11,9 +11,9 @@ import SwiftFoundation final class SortDescriptorTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = - [("testComparableSorting", self.testComparableSorting), - ("testComparatorSorting", self.testComparatorSorting)] + static let allTests: [(String, SortDescriptorTests -> () throws -> Void)] = + [("testComparableSorting", testComparableSorting), + ("testComparatorSorting", testComparatorSorting)] // MARK: - Functional Tests diff --git a/Sources/UnitTests/StringTests.swift b/Sources/UnitTests/StringTests.swift index 1d8f22d..01fa00b 100644 --- a/Sources/UnitTests/StringTests.swift +++ b/Sources/UnitTests/StringTests.swift @@ -10,7 +10,7 @@ import XCTest final class StringTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = [("testUTF8Data", self.testUTF8Data)] + static let allTests: [(String, StringTests -> () throws -> Void)] = [("testUTF8Data", testUTF8Data)] // MARK: - Functional Tests diff --git a/Sources/UnitTests/UUIDTests.swift b/Sources/UnitTests/UUIDTests.swift index f4bf2a3..8b635eb 100644 --- a/Sources/UnitTests/UUIDTests.swift +++ b/Sources/UnitTests/UUIDTests.swift @@ -12,11 +12,11 @@ import SwiftFoundation final class UUIDTests: XCTestCase { - lazy var allTests: [(String, () throws -> ())] = - [("testCreateRandomUUID", self.testCreateRandomUUID), - ("testUUIDString", self.testUUIDString), - ("testCreateFromString", self.testCreateFromString), - ("testBytes", self.testBytes)] + static let allTests: [(String, UUIDTests -> () throws -> Void)] = + [("testCreateRandomUUID", testCreateRandomUUID), + ("testUUIDString", testUUIDString), + ("testCreateFromString", testCreateFromString), + ("testBytes", testBytes)] // MARK: - Functional Tests diff --git a/Sources/UnitTests/main.swift b/Sources/UnitTests/main.swift index 38d7c90..97e39e5 100644 --- a/Sources/UnitTests/main.swift +++ b/Sources/UnitTests/main.swift @@ -8,20 +8,21 @@ import XCTest -#if os(OSX) || os(iOS) - func XCTMain(cases: [XCTestCase]) { fatalError("Not Implemented. Linux only") } -#endif - -#if os(Linux) - XCTMain([DateComponentsTest(), - OrderTests(), - POSIXTimeTests(), - RegularExpressionTests(), - SortDescriptorTests(), - StringTests(), - UUIDTests(), - DataTests(), - JSONTests(), - RangeTests()]) +#if os(OSX) || os(iOS) || os(watchOS) + func XCTMain(testCases: [XCTestCaseEntry]) { fatalError("Not Implemented. Linux only") } + + func testCase(allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry { fatalError("Not Implemented. Linux only") } + + struct XCTestCaseEntry { } #endif +XCTMain([testCase(DateComponentsTest.allTests), + testCase(OrderTests.allTests), + testCase(POSIXTimeTests.allTests), + testCase(RegularExpressionTests.allTests), + testCase(SortDescriptorTests.allTests), + testCase(StringTests.allTests), + testCase(UUIDTests.allTests), + testCase(DataTests.allTests), + testCase(JSONTests.allTests), + testCase(RangeTests.allTests)]) diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index b3370eb..4909db4 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -540,6 +540,7 @@ 6E2C2B501C20F6EB00B2C995 /* UnitTests */ = { isa = PBXGroup; children = ( + 6E2C2C2E1C2128C600B2C995 /* main.swift */, 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */, 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */, 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */, @@ -550,7 +551,6 @@ 6E1ACD4A1C435822005775FD /* DataTests.swift */, 6E957C561C442E3E003F3C51 /* JSONTests.swift */, 6EFF9A1C1CAD108400917CB3 /* RangeTests.swift */, - 6E2C2C2E1C2128C600B2C995 /* main.swift */, ); path = UnitTests; sourceTree = ""; From dc3dc1fa04ce24537bc5f88721642ffbd2030ab8 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 16:53:20 -0500 Subject: [PATCH 13/68] updated Travis CI Linux only --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 27985e3..f2a9ad0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: generic -osx_image: xcode7.3 +#osx_image: xcode7.3 os: - linux - - osx +# - osx sudo: required dist: trusty before_install: From 2396d4b50996d53dacf41fc6861f20f350b2ea42 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 16:53:44 -0500 Subject: [PATCH 14/68] version bump --- Xcode/SwiftFoundation/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xcode/SwiftFoundation/Info.plist b/Xcode/SwiftFoundation/Info.plist index 0da1879..6c36814 100644 --- a/Xcode/SwiftFoundation/Info.plist +++ b/Xcode/SwiftFoundation/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.8 + 1.2.0 CFBundleSignature ???? CFBundleVersion From d7d27d7f9304769cf4fe0bc10244f80c355dbeb0 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 5 Apr 2016 17:18:14 -0500 Subject: [PATCH 15/68] updated Travis CI removed OS X build --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f2a9ad0..3a11998 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: generic -#osx_image: xcode7.3 os: - linux -# - osx sudo: required dist: trusty before_install: From 43eb171b122587c7614ecc51432049cc8797de1e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 10 Apr 2016 23:31:44 -0500 Subject: [PATCH 16/68] added Lock --- Sources/SwiftFoundation/Lock.swift | 155 ++++++++++++++++++ .../SwiftFoundation.xcodeproj/project.pbxproj | 8 + 2 files changed, 163 insertions(+) create mode 100644 Sources/SwiftFoundation/Lock.swift diff --git a/Sources/SwiftFoundation/Lock.swift b/Sources/SwiftFoundation/Lock.swift new file mode 100644 index 0000000..a4ac1ab --- /dev/null +++ b/Sources/SwiftFoundation/Lock.swift @@ -0,0 +1,155 @@ +// +// Lock.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 4/9/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + import Darwin.C +#elseif os(Linux) + import Glibc +#endif + +/// Protocol defining lock and unlock operations. +public protocol Locking { + + /// Block until acquiring lock. + func lock() + + /// Relinquish lock. + func unlock() +} + +/// Used to coordinate the operation of multiple threads of execution within the same application. +/// A lock object can be used to mediate access to an application’s global data or to protect a critical section of code, +/// allowing it to run atomically. +/// +/// - Note: `Lock` uses POSIX threads to implement its locking behavior. +/// When sending an unlock message to a `Lock`, you must be sure that message is sent from the same thread +/// that sent the initial lock message. Unlocking a lock from a different thread can result in undefined behavior. +/// You should not use this class to implement a recursive lock. +/// Calling the lock method twice on the same thread will lock up your thread permanently. +/// Unlocking a lock that is not locked is considered a programmer error and should be fixed in your code. +/// The `Lock` reports such errors by printing an error message to the console when they occur. +public final class Lock: Locking { + + // MARK: - Properties + + /// You can use a name string to identify a lock within your code. + public var name: String? + + private var internalMutex = pthread_mutex_t() + + // MARK: - Intialization + + deinit { pthread_mutex_destroy(&internalMutex) } + + public init() { + + pthread_mutex_init(&internalMutex, nil) + } + + // MARK: - Methods + + /// Attempts to acquire a lock before a given time. + /// + /// - Discussion: The thread is blocked until the receiver acquires the lock or limit is reached. + public func lock(before limit: Date) { + + assert(Date() < limit, "\(limit) must be after the current date.") + + guard tryLock() else { + + repeat { sched_yield() } + + while limit - Date() > 0 + + return + } + } + + public func lock() { + + let errorCode = pthread_mutex_lock(&internalMutex) + + guard errorCode == 0 else { fatalError("Could not lock mutex. \(POSIXError(rawValue: errorCode)!)") } + } + + public func unlock() { + + let errorCode = pthread_mutex_unlock(&internalMutex) + + guard errorCode == 0 else { fatalError("Could not unlock mutex. \(POSIXError(rawValue: errorCode)!)") } + } + + /// Try to acquire lock and return immediately. + public func tryLock() -> Bool { + + return pthread_mutex_trylock(&internalMutex) == 0 + } +} + +// MARK: - Private Types + +private extension Lock { + + /// POSIX Mutex (`Lock`) Attribute + private final class Attribute { + + // MARK: - Singletons + + private static let Normal = Attribute(type: .normal) + + private static let ErrorCheck = Attribute(type: .errorCheck) + + private static let Recursive = Attribute(type: .recursive) + + // MARK: - Properties + + private var internalAttribute = pthread_mutexattr_t() + + // MARK: - Initialization + + deinit { pthread_mutexattr_destroy(&internalAttribute) } + + private init() { + + pthread_mutexattr_init(&internalAttribute) + } + + private convenience init(type: AttributeType) { + + self.init() + + self.type = type + } + + // MARK: - Methods + + private var type: AttributeType { + + get { + + var typeRawValue: CInt = 0 + + pthread_mutexattr_gettype(&internalAttribute, &typeRawValue) + + return AttributeType(rawValue: typeRawValue)! + } + + set { pthread_mutexattr_settype(&internalAttribute, newValue.rawValue) } + } + } + + /// POSIX Mutex (`Lock`) Attribute Type + private enum AttributeType: CInt { + + case normal = 0 + case errorCheck = 1 + case recursive = 2 + + private init() { self = normal } + } +} diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 4909db4..3fcffe7 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -223,6 +223,9 @@ 6E2C2C361C212C5700B2C995 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C311C212C2200B2C995 /* NSString.swift */; }; 6E30BA111B40F543009B1B49 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6E30BA181B40F543009B1B49 /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E30BA0D1B40F543009B1B49 /* SwiftFoundation.framework */; }; + 6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; + 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; + 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E957C261C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; @@ -381,6 +384,7 @@ 6E30BA121B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6E30BA171B40F543009B1B49 /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E30BA1E1B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6E82FD711CBA06C10049CD1B /* Lock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = ""; }; 6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = ""; }; 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = ""; }; 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = ""; }; @@ -517,6 +521,7 @@ 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */, 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */, 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */, + 6E82FD711CBA06C10049CD1B /* Lock.swift */, 6E2C2B361C20F6EB00B2C995 /* Null.swift */, 6E2C2B371C20F6EB00B2C995 /* Order.swift */, 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */, @@ -880,6 +885,7 @@ 6E2C2BCC1C20F76600B2C995 /* POSIXFileStatus.swift in Sources */, 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2BC01C20F76600B2C995 /* HTTP.swift in Sources */, + 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */, 6E2C2B621C20F6F600B2C995 /* HTTPClient.swift in Sources */, 6E2C2B661C20F6F600B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2BBE1C20F76600B2C995 /* FileType.swift in Sources */, @@ -953,6 +959,7 @@ 6E2C2B981C20F76600B2C995 /* POSIXFileStatus.swift in Sources */, 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2B8C1C20F76600B2C995 /* HTTP.swift in Sources */, + 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */, 6E2C2B591C20F6F500B2C995 /* HTTPClient.swift in Sources */, 6E2C2B5D1C20F6F500B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2B8A1C20F76600B2C995 /* FileType.swift in Sources */, @@ -1073,6 +1080,7 @@ 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */, 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */, 6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */, + 6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */, 6E2C2C091C20F76700B2C995 /* RegularExpressionCompileOption.swift in Sources */, 6E2C2BF71C20F76700B2C995 /* HTTPResponse.swift in Sources */, 6E2C2C161C20F76700B2C995 /* Version.swift in Sources */, From eeb83dd80bcc450b6203d8fab6cc66ea4b0a5c0d Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 00:21:15 -0500 Subject: [PATCH 17/68] Added Atomic --- Sources/SwiftFoundation/Atomic.swift | 84 +++++++++++++++++++ .../SwiftFoundation.xcodeproj/project.pbxproj | 8 ++ 2 files changed, 92 insertions(+) create mode 100644 Sources/SwiftFoundation/Atomic.swift diff --git a/Sources/SwiftFoundation/Atomic.swift b/Sources/SwiftFoundation/Atomic.swift new file mode 100644 index 0000000..818d446 --- /dev/null +++ b/Sources/SwiftFoundation/Atomic.swift @@ -0,0 +1,84 @@ +// +// Atomic.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 4/10/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +/// Encapsulates atomic values that are thread-safe. +public struct Atomic { + + // MARK: - Properties + + public var value: Value { + + get { return storage.value } + + mutating set { + + ensureUnique() + storage.value = newValue + } + } + + // MARK: - Private Properties + + private var storage: AtomicStorage + + // MARK: - Initialization + + public init(_ value: Value) { + + self.storage = AtomicStorage(value) + } + + // MARK: - Private Methods + + private mutating func ensureUnique() { + + if !isUniquelyReferencedNonObjC(&storage) { + storage = storage.copy + } + } +} + +/// Internal Storage for `Atomic`. +private final class AtomicStorage { + + /// Actual storage for property + var _value: Value + + var value: Value { + + get { + + let value: Value + + lock.lock() + value = _value + lock.unlock() + + return value + } + + set { + + lock.lock() + _value = newValue + lock.unlock() + } + } + + let lock = Lock() + + init(_ value: Value) { + + _value = value + } + + var copy: AtomicStorage { + + return AtomicStorage(_value) + } +} diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 3fcffe7..28aa675 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -226,6 +226,9 @@ 6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; + 6E82FD761CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; + 6E82FD771CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; + 6E82FD781CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; 6E957C261C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; @@ -385,6 +388,7 @@ 6E30BA171B40F543009B1B49 /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E30BA1E1B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6E82FD711CBA06C10049CD1B /* Lock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = ""; }; + 6E82FD751CBB61220049CD1B /* Atomic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Atomic.swift; sourceTree = ""; }; 6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = ""; }; 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = ""; }; 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = ""; }; @@ -498,6 +502,7 @@ isa = PBXGroup; children = ( 6E2C2C251C20FAED00B2C995 /* Standard Library Extensions */, + 6E82FD751CBB61220049CD1B /* Atomic.swift */, 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */, 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */, 6E2C2B1F1C20F6EB00B2C995 /* ByteValueType.swift */, @@ -886,6 +891,7 @@ 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2BC01C20F76600B2C995 /* HTTP.swift in Sources */, 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */, + 6E82FD771CBB61220049CD1B /* Atomic.swift in Sources */, 6E2C2B621C20F6F600B2C995 /* HTTPClient.swift in Sources */, 6E2C2B661C20F6F600B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2BBE1C20F76600B2C995 /* FileType.swift in Sources */, @@ -960,6 +966,7 @@ 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2B8C1C20F76600B2C995 /* HTTP.swift in Sources */, 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */, + 6E82FD781CBB61220049CD1B /* Atomic.swift in Sources */, 6E2C2B591C20F6F500B2C995 /* HTTPClient.swift in Sources */, 6E2C2B5D1C20F6F500B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2B8A1C20F76600B2C995 /* FileType.swift in Sources */, @@ -1076,6 +1083,7 @@ 6E2C2C131C20F76700B2C995 /* URLRequest.swift in Sources */, 6EFF9A1B1CAD0C6B00917CB3 /* Range.swift in Sources */, 6E2C2BEE1C20F76700B2C995 /* Decimal.swift in Sources */, + 6E82FD761CBB61220049CD1B /* Atomic.swift in Sources */, 6E2C2BEA1C20F76700B2C995 /* Copying.swift in Sources */, 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */, 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */, From 368949a22eae24a1943615484dcb7bb2289a7cc8 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 00:27:03 -0500 Subject: [PATCH 18/68] working on Atomic --- Sources/SwiftFoundation/Atomic.swift | 66 +++++++++------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/Sources/SwiftFoundation/Atomic.swift b/Sources/SwiftFoundation/Atomic.swift index 818d446..68a0020 100644 --- a/Sources/SwiftFoundation/Atomic.swift +++ b/Sources/SwiftFoundation/Atomic.swift @@ -13,72 +13,46 @@ public struct Atomic { public var value: Value { - get { return storage.value } - - mutating set { - - ensureUnique() - storage.value = newValue - } - } - - // MARK: - Private Properties - - private var storage: AtomicStorage - - // MARK: - Initialization - - public init(_ value: Value) { - - self.storage = AtomicStorage(value) - } - - // MARK: - Private Methods - - private mutating func ensureUnique() { - - if !isUniquelyReferencedNonObjC(&storage) { - storage = storage.copy - } - } -} - -/// Internal Storage for `Atomic`. -private final class AtomicStorage { - - /// Actual storage for property - var _value: Value - - var value: Value { - get { let value: Value lock.lock() - value = _value + value = internalValue lock.unlock() return value } - set { + mutating set { + + ensureUnique() lock.lock() - _value = newValue + internalValue = newValue lock.unlock() } } - let lock = Lock() + // MARK: - Private Properties + + private var internalValue: Value + + private var lock = Lock() + + // MARK: - Initialization - init(_ value: Value) { + public init(_ value: Value) { - _value = value + self.internalValue = value } - var copy: AtomicStorage { + // MARK: - Private Methods + + private mutating func ensureUnique() { - return AtomicStorage(_value) + if !isUniquelyReferencedNonObjC(&lock) { + lock = Lock() + } } } From 44f3ccebdcf9b975271ca1e7f76d5a1d4a00a045 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 01:20:19 -0500 Subject: [PATCH 19/68] working on Atomic --- Sources/SwiftFoundation/Lock.swift | 9 ++- Sources/SwiftFoundation/Thread.swift | 4 +- Sources/UnitTests/AtomicTests.swift | 75 +++++++++++++++++++ Sources/UnitTests/main.swift | 4 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 6 ++ 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 Sources/UnitTests/AtomicTests.swift diff --git a/Sources/SwiftFoundation/Lock.swift b/Sources/SwiftFoundation/Lock.swift index a4ac1ab..36b44f5 100644 --- a/Sources/SwiftFoundation/Lock.swift +++ b/Sources/SwiftFoundation/Lock.swift @@ -70,21 +70,24 @@ public final class Lock: Locking { } } + @inline(__always) public func lock() { let errorCode = pthread_mutex_lock(&internalMutex) - guard errorCode == 0 else { fatalError("Could not lock mutex. \(POSIXError(rawValue: errorCode)!)") } + assert(errorCode == 0, "Could not lock mutex. \(POSIXError(rawValue: errorCode)!)") } + @inline(__always) public func unlock() { let errorCode = pthread_mutex_unlock(&internalMutex) - guard errorCode == 0 else { fatalError("Could not unlock mutex. \(POSIXError(rawValue: errorCode)!)") } + assert(errorCode == 0, "Could not unlock mutex. \(POSIXError(rawValue: errorCode)!)") } - /// Try to acquire lock and return immediately. + /// Try to acquire lock and return immediately. + @inline(__always) public func tryLock() -> Bool { return pthread_mutex_trylock(&internalMutex) == 0 diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 3095abc..7d9f0dd 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -21,7 +21,7 @@ public final class Thread { // MARK: - Intialization - public init(closure: () -> Void) throws { + public init(_ closure: () -> ()) throws { let holder = Unmanaged.passRetained(Closure(closure: closure)) @@ -67,6 +67,8 @@ public final class Thread { } } +// MARK: - Private + private func ThreadPrivateMain(arg: UnsafeMutablePointer) -> UnsafeMutablePointer { let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift new file mode 100644 index 0000000..3c4fd2b --- /dev/null +++ b/Sources/UnitTests/AtomicTests.swift @@ -0,0 +1,75 @@ +// +// AtomicTests.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 4/11/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +import XCTest +import SwiftFoundation + +final class AtomicTests: XCTestCase { + + static let allTests: [(String, AtomicTests -> () throws -> Void)] = [("testAtomic", testAtomic)] + + func testAtomic() { + + var atomic = Atomic(0) + + var thread2Finished = false + + var thread3Finished = false + + // thread 2 + let _ = try! Thread { + + for _ in 0 ..< 10 { + + atomic.value += 1 + + print("\(atomic.value) (Thread 2)") + } + + print("Finished thread 2") + + thread2Finished = true + } + + // thread 3 + let _ = try! Thread { + + for _ in 0 ..< 10 { + + atomic.value += 1 + + print("\(atomic.value) (Thread 3)") + } + + print("Finished thread 3") + + thread3Finished = true + } + + // main thread + for _ in 0 ..< 10 { + + atomic.value += 1 + + print("\(atomic.value) (Thread 1)") + } + + let finalValue = 30 + + print("Waiting for threads to finish") + + while thread2Finished == false || thread3Finished == false { + + sleep(1) + } + + XCTAssert(atomic.value == finalValue, "Value is \(atomic.value), should be \(finalValue)") + + print("Final value \(atomic.value)") + } +} diff --git a/Sources/UnitTests/main.swift b/Sources/UnitTests/main.swift index 97e39e5..5d17708 100644 --- a/Sources/UnitTests/main.swift +++ b/Sources/UnitTests/main.swift @@ -25,4 +25,6 @@ XCTMain([testCase(DateComponentsTest.allTests), testCase(UUIDTests.allTests), testCase(DataTests.allTests), testCase(JSONTests.allTests), - testCase(RangeTests.allTests)]) + testCase(RangeTests.allTests), + testCase(AtomicTests.allTests) + ]) diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 28aa675..ede6871 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -229,6 +229,8 @@ 6E82FD761CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; 6E82FD771CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; 6E82FD781CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; + 6E82FD7A1CBB70710049CD1B /* AtomicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD791CBB70710049CD1B /* AtomicTests.swift */; }; + 6E82FD7B1CBB70710049CD1B /* AtomicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD791CBB70710049CD1B /* AtomicTests.swift */; }; 6E957C261C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; @@ -389,6 +391,7 @@ 6E30BA1E1B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6E82FD711CBA06C10049CD1B /* Lock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = ""; }; 6E82FD751CBB61220049CD1B /* Atomic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Atomic.swift; sourceTree = ""; }; + 6E82FD791CBB70710049CD1B /* AtomicTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomicTests.swift; sourceTree = ""; }; 6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = ""; }; 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = ""; }; 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = ""; }; @@ -551,6 +554,7 @@ isa = PBXGroup; children = ( 6E2C2C2E1C2128C600B2C995 /* main.swift */, + 6E82FD791CBB70710049CD1B /* AtomicTests.swift */, 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */, 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */, 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */, @@ -1039,6 +1043,7 @@ files = ( 6E2C2C181C20F76B00B2C995 /* OrderTests.swift in Sources */, 6E2C2C301C2128C600B2C995 /* main.swift in Sources */, + 6E82FD7B1CBB70710049CD1B /* AtomicTests.swift in Sources */, 6EFF9A1F1CAD11F600917CB3 /* Range.swift in Sources */, 6E2C2C1D1C20F76B00B2C995 /* UUIDTests.swift in Sources */, 6E2C2C2D1C21115C00B2C995 /* NSComparisonResultTests.swift in Sources */, @@ -1138,6 +1143,7 @@ buildActionMask = 2147483647; files = ( 6E2C2C1F1C20F76D00B2C995 /* OrderTests.swift in Sources */, + 6E82FD7A1CBB70710049CD1B /* AtomicTests.swift in Sources */, 6E2C2C2F1C2128C600B2C995 /* main.swift in Sources */, 6E2C2C241C20F76D00B2C995 /* UUIDTests.swift in Sources */, 6E2C2C2C1C21115C00B2C995 /* NSComparisonResultTests.swift in Sources */, From 7be78140176b6dc34ec700da8dc51a0d6c7f0888 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 15:47:44 -0500 Subject: [PATCH 20/68] updated Atomic unit test --- Sources/UnitTests/AtomicTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index 3c4fd2b..ae02417 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -59,7 +59,7 @@ final class AtomicTests: XCTestCase { print("\(atomic.value) (Thread 1)") } - let finalValue = 30 + let finalValue = 28 print("Waiting for threads to finish") From 012248329007ea5019a866bfd98fc9fc5cfdd394 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 23:38:43 -0500 Subject: [PATCH 21/68] fixed Atomic unit test for Linux --- Sources/UnitTests/AtomicTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index ae02417..bb7842b 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -6,6 +6,12 @@ // Copyright © 2016 PureSwift. All rights reserved. // +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + import Darwin.C +#elseif os(Linux) + import Glibc +#endif + import XCTest import SwiftFoundation From b9d24703556a03a8ac7f9bd4069190fe691e7723 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 23:46:26 -0500 Subject: [PATCH 22/68] updated Atomic test --- Sources/UnitTests/AtomicTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index bb7842b..08f2da7 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -65,7 +65,7 @@ final class AtomicTests: XCTestCase { print("\(atomic.value) (Thread 1)") } - let finalValue = 28 + let finalValue = 30 print("Waiting for threads to finish") From 383e1992db80dfa2efc8358b99d0f47a09b9da18 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Mon, 11 Apr 2016 23:50:27 -0500 Subject: [PATCH 23/68] updated Atomic Unit Tests --- Sources/UnitTests/AtomicTests.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index 08f2da7..69f3a8a 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -27,6 +27,14 @@ final class AtomicTests: XCTestCase { var thread3Finished = false + // main thread + for _ in 0 ..< 10 { + + atomic.value += 1 + + print("\(atomic.value) (Thread 1)") + } + // thread 2 let _ = try! Thread { @@ -57,14 +65,6 @@ final class AtomicTests: XCTestCase { thread3Finished = true } - // main thread - for _ in 0 ..< 10 { - - atomic.value += 1 - - print("\(atomic.value) (Thread 1)") - } - let finalValue = 30 print("Waiting for threads to finish") From fd1126f830c6329dce20d368321ab359a5571eaa Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 12 Apr 2016 00:00:54 -0500 Subject: [PATCH 24/68] updated Atomic Unit tests --- Sources/UnitTests/AtomicTests.swift | 44 ++++------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index 69f3a8a..5bc1785 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -23,56 +23,24 @@ final class AtomicTests: XCTestCase { var atomic = Atomic(0) - var thread2Finished = false - - var thread3Finished = false - // main thread - for _ in 0 ..< 10 { - - atomic.value += 1 + for i in 0 ..< 10 { - print("\(atomic.value) (Thread 1)") - } - - // thread 2 - let _ = try! Thread { - - for _ in 0 ..< 10 { - - atomic.value += 1 + let _ = try! Thread { - print("\(atomic.value) (Thread 2)") - } - - print("Finished thread 2") - - thread2Finished = true - } - - // thread 3 - let _ = try! Thread { - - for _ in 0 ..< 10 { + let oldValue = atomic.value atomic.value += 1 - print("\(atomic.value) (Thread 3)") + print("\(oldValue) -> \(atomic.value) (Thread \(i))") } - - print("Finished thread 3") - - thread3Finished = true } - let finalValue = 30 + let finalValue = 10 print("Waiting for threads to finish") - while thread2Finished == false || thread3Finished == false { - - sleep(1) - } + sleep(1) XCTAssert(atomic.value == finalValue, "Value is \(atomic.value), should be \(finalValue)") From ab7e383556262a0d90937f06c16f16091a9b7877 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 14 Apr 2016 03:02:50 -0500 Subject: [PATCH 25/68] updated Atomic unit tests --- Sources/UnitTests/AtomicTests.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index 5bc1785..4230791 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -23,6 +23,8 @@ final class AtomicTests: XCTestCase { var atomic = Atomic(0) + var wait = true + // main thread for i in 0 ..< 10 { @@ -40,7 +42,10 @@ final class AtomicTests: XCTestCase { print("Waiting for threads to finish") - sleep(1) + while atomic.value != finalValue { + + sleep(1) + } XCTAssert(atomic.value == finalValue, "Value is \(atomic.value), should be \(finalValue)") From 9552441db0b2bdd7879e8b21e34c363d32f50787 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 14 Apr 2016 11:33:24 -0500 Subject: [PATCH 26/68] Updated for latest Swift 3.0 development snapshot April 12, 2016 release --- .../FoundationConvertible/HTTPClient.swift | 6 +-- .../NSComparisonResult.swift | 12 ++--- .../NSJSONSerialization.swift | 14 +++--- .../NSComparisonResultTests.swift | 6 +-- Sources/FoundationUnitTests/NSDateTests.swift | 4 +- .../NSFileManagerTests.swift | 18 +++---- .../NSSortDescriptorTests.swift | 8 ++-- Sources/SwiftFoundation/Base64.swift | 4 +- Sources/SwiftFoundation/BitMaskOption.swift | 6 +-- .../ComparableSortDescriptor.swift | 2 +- .../ComparatorSortDescriptor.swift | 2 +- Sources/SwiftFoundation/Data.swift | 2 +- Sources/SwiftFoundation/Date.swift | 2 +- Sources/SwiftFoundation/FileManager.swift | 38 +++++++-------- Sources/SwiftFoundation/JSON.swift | 2 +- Sources/SwiftFoundation/JSONParse.swift | 5 +- .../SwiftFoundation/JSONSerialization.swift | 2 +- Sources/SwiftFoundation/Order.swift | 14 +++--- .../POSIXRegularExpression.swift | 4 +- Sources/SwiftFoundation/POSIXUUID.swift | 14 +++--- Sources/SwiftFoundation/Predicate.swift | 2 +- Sources/SwiftFoundation/Range.swift | 2 +- .../SwiftFoundation/RawRepresentable.swift | 2 +- .../SwiftFoundation/RegularExpression.swift | 6 +-- Sources/SwiftFoundation/SortDescriptor.swift | 47 ++++++------------- Sources/SwiftFoundation/Thread.swift | 12 +++-- Sources/SwiftFoundation/URLClient.swift | 2 +- Sources/UnitTests/AtomicTests.swift | 4 +- Sources/UnitTests/DataTests.swift | 2 +- Sources/UnitTests/JSONTests.swift | 4 +- Sources/UnitTests/OrderTests.swift | 15 +++--- .../UnitTests/RegularExpressionTests.swift | 2 +- Sources/UnitTests/SortDescriptorTests.swift | 16 +++---- Sources/UnitTests/main.swift | 4 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 2 +- .../xcschemes/SwiftFoundation OS X.xcscheme | 2 +- 36 files changed, 136 insertions(+), 153 deletions(-) diff --git a/Sources/FoundationConvertible/HTTPClient.swift b/Sources/FoundationConvertible/HTTPClient.swift index 5d1ef03..b9dd5d1 100644 --- a/Sources/FoundationConvertible/HTTPClient.swift +++ b/Sources/FoundationConvertible/HTTPClient.swift @@ -24,14 +24,14 @@ public extension HTTP { /// The backing ```NSURLSession```. public let session: NSURLSession - public func sendRequest(request: HTTP.Request) throws -> HTTP.Response { + public func send(request: HTTP.Request) throws -> HTTP.Response { var dataTask: NSURLSessionDataTask? - return try sendRequest(request, dataTask: &dataTask) + return try send(request: request, dataTask: &dataTask) } - public func sendRequest(request: HTTP.Request, dataTask: inout NSURLSessionDataTask?) throws -> HTTP.Response { + public func send(request: HTTP.Request, dataTask: inout NSURLSessionDataTask?) throws -> HTTP.Response { // build request... diff --git a/Sources/FoundationConvertible/NSComparisonResult.swift b/Sources/FoundationConvertible/NSComparisonResult.swift index a07b5e6..ba34358 100644 --- a/Sources/FoundationConvertible/NSComparisonResult.swift +++ b/Sources/FoundationConvertible/NSComparisonResult.swift @@ -18,9 +18,9 @@ extension Order: FoundationConvertible { switch foundation { - case .orderedAscending: self = .Ascending - case .orderedDescending: self = .Descending - case .orderedSame: self = .Same + case .orderedAscending: self = .ascending + case .orderedDescending: self = .descending + case .orderedSame: self = .same } } @@ -28,9 +28,9 @@ extension Order: FoundationConvertible { switch self { - case .Ascending: return .orderedAscending - case .Descending: return .orderedDescending - case .Same: return .orderedSame + case .ascending: return .orderedAscending + case .descending: return .orderedDescending + case .same: return .orderedSame } } } diff --git a/Sources/FoundationConvertible/NSJSONSerialization.swift b/Sources/FoundationConvertible/NSJSONSerialization.swift index e8b07c0..8ec2a70 100644 --- a/Sources/FoundationConvertible/NSJSONSerialization.swift +++ b/Sources/FoundationConvertible/NSJSONSerialization.swift @@ -44,7 +44,7 @@ public extension NSJSONSerialization { return } - if let rawArray = rawValue as? [AnyObject], let jsonArray: [NSJSONSerialization.Value] = NSJSONSerialization.Value.fromRawValues(rawArray) { + if let rawArray = rawValue as? [AnyObject], let jsonArray: [NSJSONSerialization.Value] = NSJSONSerialization.Value.from(rawValues: rawArray) { self = .Array(jsonArray) return @@ -166,11 +166,11 @@ extension JSON.Value: FoundationConvertible { switch number { - case let .Integer(value): return NSJSONSerialization.Value.Number(NSNumber(integer: value)) + case let .Integer(value): return NSJSONSerialization.Value.Number(NSNumber(value: value)) - case let .Double(value): return NSJSONSerialization.Value.Number(NSNumber(double: value)) + case let .Double(value): return NSJSONSerialization.Value.Number(NSNumber(value: value)) - case let .Boolean(value): return NSJSONSerialization.Value.Number(NSNumber(bool: value)) + case let .Boolean(value): return NSJSONSerialization.Value.Number(NSNumber(value: value)) } case .Array(let array): @@ -202,12 +202,12 @@ extension JSON.Value: FoundationConvertible { } } -private let trueNumber = NSNumber(bool: true) -private let falseNumber = NSNumber(bool: false) +private let trueNumber: NSNumber = true +private let falseNumber: NSNumber = false private let trueObjCType = String(validatingUTF8: trueNumber.objCType) private let falseObjCType = String(validatingUTF8: falseNumber.objCType) -private let intNumber = NSNumber(integer: 1) +private let intNumber: NSNumber = Int(1) private let intObjCType = String(validatingUTF8: intNumber.objCType)! diff --git a/Sources/FoundationUnitTests/NSComparisonResultTests.swift b/Sources/FoundationUnitTests/NSComparisonResultTests.swift index 3394424..6bda9fa 100644 --- a/Sources/FoundationUnitTests/NSComparisonResultTests.swift +++ b/Sources/FoundationUnitTests/NSComparisonResultTests.swift @@ -28,11 +28,11 @@ class NSComparisonResultTests: XCTestCase { // number - XCTAssert(1.compare(2) == Order(foundation: 1.compare(NSNumber(integer: 2)))) + XCTAssert((1 as Int).compare(2) == Order(foundation: 1.compare(NSNumber(value: 2)))) - XCTAssert(2.compare(1) == Order(foundation: 2.compare(NSNumber(integer: 1)))) + XCTAssert((2 as Int).compare(1) == Order(foundation: 2.compare(NSNumber(value: 1)))) - XCTAssert(1.compare(1) == Order(foundation: 1.compare(NSNumber(integer: 1)))) + XCTAssert((1 as Int).compare(1) == Order(foundation: 1.compare(NSNumber(value: 1)))) // string diff --git a/Sources/FoundationUnitTests/NSDateTests.swift b/Sources/FoundationUnitTests/NSDateTests.swift index 2f4deeb..be9f364 100644 --- a/Sources/FoundationUnitTests/NSDateTests.swift +++ b/Sources/FoundationUnitTests/NSDateTests.swift @@ -80,9 +80,9 @@ class DateTests: XCTestCase { let foundationDate2 = NSDate(timeIntervalSinceReferenceDate: time2) - let intervalSinceDate = date.timeIntervalSinceDate(date2) + let intervalSinceDate = date.timeIntervalSince(date: date2) - let foundationIntervalSinceDate = foundationDate.timeInterval(since: foundationDate2) + let foundationIntervalSinceDate = foundationDate.timeIntervalSince(foundationDate2) XCTAssert(intervalSinceDate == foundationIntervalSinceDate) } diff --git a/Sources/FoundationUnitTests/NSFileManagerTests.swift b/Sources/FoundationUnitTests/NSFileManagerTests.swift index b8635df..cb3f601 100644 --- a/Sources/FoundationUnitTests/NSFileManagerTests.swift +++ b/Sources/FoundationUnitTests/NSFileManagerTests.swift @@ -37,21 +37,21 @@ class FileManagerTests: XCTestCase { XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: NSData(), attributes: nil)) - XCTAssert(FileManager.fileExists(path)) + XCTAssert(FileManager.fileExists(at: path)) - XCTAssert(!FileManager.directoryExists(path)) + XCTAssert(!FileManager.directoryExists(at: path)) } func testDirectoryExists() { - let path = try! NSFileManager.defaultManager().url(for: NSSearchPathDirectory.userDirectory, in: NSSearchPathDomainMask.allDomainsMask, appropriateFor: nil, create: false).path! + let path = try! NSFileManager.defaultManager().urlForDirectory( NSSearchPathDirectory.userDirectory, in: NSSearchPathDomainMask.allDomainsMask, appropriateFor: nil, create: false).path! assert(NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: nil), "Setting non existent directory as test parameter") - XCTAssert(FileManager.directoryExists(path)) + XCTAssert(FileManager.directoryExists(at: path)) - XCTAssert(!FileManager.fileExists(path)) + XCTAssert(!FileManager.fileExists(at: path)) } func testReadFile() { @@ -72,7 +72,7 @@ class FileManagerTests: XCTestCase { var readData: Data - do { readData = try FileManager.contents(path) } + do { readData = try FileManager.contents(at: path) } catch { XCTFail("\(error)"); return } @@ -95,7 +95,7 @@ class FileManagerTests: XCTestCase { XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: NSData(), attributes: nil)) // write file - do { try FileManager.setContents(path, data: data) } + do { try FileManager.set(contents: data, at: path) } catch { XCTFail("\(error)"); return } @@ -103,7 +103,7 @@ class FileManagerTests: XCTestCase { var readData: Data - do { readData = try FileManager.contents(path) } + do { readData = try FileManager.contents(at: path) } catch { XCTFail("\(error)"); return } @@ -120,7 +120,7 @@ class FileManagerTests: XCTestCase { // create file - do { try FileManager.createFile(path, contents: data) } + do { try FileManager.createFile(at: path, contents: data) } catch { XCTFail("\(error)"); return } diff --git a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift index 06d9f00..34e221e 100644 --- a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift +++ b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift @@ -28,9 +28,9 @@ class NSSortDescriptorTests: XCTestCase { func testComparableSorting() { - func verifySort(items: [String], ascending: Bool = true) { + func verifySort(_ items: [String], ascending: Bool = true) { - let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: ascending)) + let sortedItems = items.sorted(ComparableSortDescriptor(ascending: ascending)) let foundationSortedItems = (items as NSArray).sortedArray(using: [NSSortDescriptor(key: nil, ascending: ascending)]) @@ -62,9 +62,9 @@ class NSSortDescriptorTests: XCTestCase { func testComparatorSorting() { - func verifySort(items: [String], ascending: Bool = true) { + func verifySort(_ items: [String], ascending: Bool = true) { - let sortedItems = Sort(items, sortDescriptor: ComparatorSortDescriptor(ascending: ascending, comparator: { (first: String, second: String) -> Order in + let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: ascending, comparator: { (first: String, second: String) -> Order in return first.compare(second) })) diff --git a/Sources/SwiftFoundation/Base64.swift b/Sources/SwiftFoundation/Base64.swift index a7e13c6..3ed654d 100644 --- a/Sources/SwiftFoundation/Base64.swift +++ b/Sources/SwiftFoundation/Base64.swift @@ -28,7 +28,7 @@ public struct Base64 { var encoded : [UInt8] = [] - let table = Base64.tableForAlphabet(alphabet) + let table = Base64.table(for: alphabet) let padding = table[64] var i = 0 @@ -103,7 +103,7 @@ public extension Base64 { private extension Base64 { /// Get the encoding table for the alphabet. - static func tableForAlphabet(alphabet : Alphabet) -> [UInt8] { + static func table(for alphabet: Alphabet) -> [UInt8] { switch alphabet { case .Standard: return StandardAlphabet diff --git a/Sources/SwiftFoundation/BitMaskOption.swift b/Sources/SwiftFoundation/BitMaskOption.swift index b7472c2..1b742ef 100644 --- a/Sources/SwiftFoundation/BitMaskOption.swift +++ b/Sources/SwiftFoundation/BitMaskOption.swift @@ -9,12 +9,12 @@ /// Bit mask that represents various options public protocol BitMaskOption: RawRepresentable { - static func optionsBitmask(options: [Self]) -> Self.RawValue + static func bitmask(options: [Self]) -> Self.RawValue } public extension BitMaskOption where Self.RawValue: Integer { - static func optionsBitmask(options: S) -> Self.RawValue { + static func bitmask(options: S) -> Self.RawValue { return options.reduce(0) { mask, option in mask | option.rawValue } @@ -27,6 +27,6 @@ public extension Sequence where Self.Iterator.Element: BitMaskOption, Self.Itera let array = self.filter { (_) -> Bool in return true } - return Self.Iterator.Element.optionsBitmask(array) + return Self.Iterator.Element.bitmask(options: array) } } \ No newline at end of file diff --git a/Sources/SwiftFoundation/ComparableSortDescriptor.swift b/Sources/SwiftFoundation/ComparableSortDescriptor.swift index 7c630ef..4c1d608 100644 --- a/Sources/SwiftFoundation/ComparableSortDescriptor.swift +++ b/Sources/SwiftFoundation/ComparableSortDescriptor.swift @@ -7,7 +7,7 @@ // /** Sorts ```Comparable``` types. */ -public struct ComparableSortDescriptor: SortDescriptorType { +public struct ComparableSortDescriptor: SortDescriptor { public var ascending: Bool diff --git a/Sources/SwiftFoundation/ComparatorSortDescriptor.swift b/Sources/SwiftFoundation/ComparatorSortDescriptor.swift index 634dd75..24d7993 100644 --- a/Sources/SwiftFoundation/ComparatorSortDescriptor.swift +++ b/Sources/SwiftFoundation/ComparatorSortDescriptor.swift @@ -7,7 +7,7 @@ // /** Sorts according to a given closure. */ -public struct ComparatorSortDescriptor: SortDescriptorType { +public struct ComparatorSortDescriptor: SortDescriptor { public typealias Comparator = (T, T) -> Order diff --git a/Sources/SwiftFoundation/Data.swift b/Sources/SwiftFoundation/Data.swift index 55f74e6..88faa82 100644 --- a/Sources/SwiftFoundation/Data.swift +++ b/Sources/SwiftFoundation/Data.swift @@ -30,7 +30,7 @@ public extension Data { /// Initializes ```Data``` from an unsafe byte pointer. /// /// - Precondition: The pointer points to a type exactly a byte long. - static func fromBytePointer(pointer: UnsafePointer, length: Int) -> Data { + static func from(pointer: UnsafePointer, length: Int) -> Data { assert(sizeof(pointer.pointee.dynamicType) == sizeof(Byte.self), "Cannot create array of bytes from pointer to \(pointer.pointee.dynamicType) because the type is larger than a single byte.") diff --git a/Sources/SwiftFoundation/Date.swift b/Sources/SwiftFoundation/Date.swift index cc2e247..43cc2d1 100644 --- a/Sources/SwiftFoundation/Date.swift +++ b/Sources/SwiftFoundation/Date.swift @@ -29,7 +29,7 @@ public struct Date: Equatable, Comparable, CustomStringConvertible { } /// Returns the difference between two dates. - public func timeIntervalSinceDate(date: Date) -> TimeInterval { + public func timeIntervalSince(date: Date) -> TimeInterval { return self - date } diff --git a/Sources/SwiftFoundation/FileManager.swift b/Sources/SwiftFoundation/FileManager.swift index 5c67e3e..7a62c4b 100644 --- a/Sources/SwiftFoundation/FileManager.swift +++ b/Sources/SwiftFoundation/FileManager.swift @@ -26,13 +26,13 @@ public final class FileManager { // MARK: - Determining Access to Files /// Determines whether a file descriptor exists at the specified path. Can be regular file, directory, socket, etc. - public static func itemExists(path: String) -> Bool { + public static func itemExists(at path: String) -> Bool { return (stat(path, nil) == 0) } /// Determines whether a file exists at the specified path. - public static func fileExists(path: String) -> Bool { + public static func fileExists(at path: String) -> Bool { var inodeInfo = stat() @@ -46,7 +46,7 @@ public final class FileManager { } /// Determines whether a directory exists at the specified path. - public static func directoryExists(path: String) -> Bool { + public static func directoryExists(at path: String) -> Bool { var inodeInfo = stat() @@ -62,7 +62,7 @@ public final class FileManager { // MARK: - Managing the Current Directory /// Attempts to change the current directory - public static func changeCurrentDirectory(newCurrentDirectory: String) throws { + public static func changeCurrentDirectory(_ newCurrentDirectory: String) throws { guard chdir(newCurrentDirectory) == 0 else { throw POSIXError.fromErrorNumber! } @@ -84,7 +84,7 @@ public final class FileManager { // MARK: - Creating and Deleting Items - public static func createFile(path: String, contents data: Data? = nil, attributes: FileAttributes = FileAttributes()) throws { + public static func createFile(at path: String, contents data: Data? = nil, attributes: FileAttributes = FileAttributes()) throws { // get file descriptor for path (open file) let file = open(path, O_CREAT, DefaultFileMode) @@ -97,16 +97,16 @@ public final class FileManager { // write data if let data = data { - try self.setContents(path, data: data) + try self.set(contents: data, at: path) } // TODO: set attributes } - public static func createDirectory(path: String, withIntermediateDirectories createIntermediates: Bool = false, attributes: FileAttributes = FileAttributes()) throws { + public static func createDirectory(at path: String, createIntermediateDirectories: Bool = false, attributes: FileAttributes = FileAttributes()) throws { - if createIntermediates { + if createIntermediateDirectories { fatalError("Create Intermediate Directories Not Implemented") } @@ -121,48 +121,48 @@ public final class FileManager { // MARK: - Creating Symbolic and Hard Links - public static func createSymbolicLink(path: String, withDestinationPath destinationPath: String) throws { + public static func createSymbolicLink(at path: String, to destinationPath: String) throws { fatalError() } - public static func linkItem(path: String, toPath destinationPath: String) throws { + public static func linkItem(at path: String, to destinationPath: String) throws { fatalError() } - public static func destinationOfSymbolicLink(path: String) throws -> String { + public static func destinationOfSymbolicLink(at path: String) throws -> String { fatalError() } // MARK: - Moving and Copying Items - public static func copyItem(sourcePath: String, toPath destinationPath: String) throws { + public static func copy(_ sourcePath: String, to destinationPath: String) throws { fatalError() } - public static func moveItem(sourcePath: String, toPath destinationPath: String) throws { + public static func move(_ sourcePath: String, to destinationPath: String) throws { fatalError() } // MARK: - Getting and Setting Attributes - public static func attributesOfItem(path: String) throws -> FileAttributes { + public static func attributes(at path: String) throws -> FileAttributes { return try FileAttributes(path: path) } - public static func setAttributes(attributes: FileAttributes, ofItemAtPath path: String) throws { + public static func set(attributes: FileAttributes, at path: String) throws { // let originalAttributes = try self.attributesOfItem(atPath: path) fatalError("Not Implemented") } - public static func attributesOfFileSystem(forPath path: String) throws -> FileSystemAttributes { + public static func fileSystemAttributes(at path: String) throws -> FileSystemAttributes { return try FileSystemAttributes(path: path) } @@ -170,7 +170,7 @@ public final class FileManager { // MARK: - Getting and Comparing File Contents /// Reads the contents of a file. - public static func contents(path: String) throws -> Data { + public static func contents(at path: String) throws -> Data { // get file descriptor for path (open file) let file = open(path, O_RDONLY) @@ -197,13 +197,13 @@ public final class FileManager { //guard readBytes == fileSize else { fatalError() } - let data = Data.fromBytePointer(memoryPointer, length: readBytes) + let data = Data.from(pointer: memoryPointer, length: readBytes) return data } /// Sets the contents of an existing file. - public static func setContents(path: String, data: Data) throws { + public static func set(contents data: Data, at path: String) throws { // get file descriptor for path (open file) let file = open(path, O_WRONLY) diff --git a/Sources/SwiftFoundation/JSON.swift b/Sources/SwiftFoundation/JSON.swift index 6512c5b..5571ca5 100644 --- a/Sources/SwiftFoundation/JSON.swift +++ b/Sources/SwiftFoundation/JSON.swift @@ -115,7 +115,7 @@ public extension JSON.Value { return } - if let rawArray = rawValue as? [Any], let jsonArray: [JSON.Value] = JSON.Value.fromRawValues(rawArray) { + if let rawArray = rawValue as? [Any], let jsonArray: [JSON.Value] = JSON.Value.from(rawValues: rawArray) { self = .Array(jsonArray) return diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index bd474bc..18309ff 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -16,7 +16,7 @@ public extension JSON.Value { public init?(string: Swift.String) { - let tokenerError = UnsafeMutablePointer.init(allocatingCapacity: 1) + let tokenerError: UnsafeMutablePointer! = UnsafeMutablePointer(allocatingCapacity: 1) defer { tokenerError.deallocateCapacity(1) } @@ -34,7 +34,8 @@ public extension JSON.Value { private extension JSON.Value { /// Create a JSON value from a ```json_object``` pointer created by the **json-c** library. - init(jsonObject: OpaquePointer) { + init(jsonObject: OpaquePointer?) { + let type = json_object_get_type(jsonObject) switch type { diff --git a/Sources/SwiftFoundation/JSONSerialization.swift b/Sources/SwiftFoundation/JSONSerialization.swift index f9986ae..7c3d3ad 100755 --- a/Sources/SwiftFoundation/JSONSerialization.swift +++ b/Sources/SwiftFoundation/JSONSerialization.swift @@ -46,7 +46,7 @@ public extension JSON.Value { private extension JSON.Value { - func toJSONObject() -> OpaquePointer { + func toJSONObject() -> OpaquePointer? { switch self { diff --git a/Sources/SwiftFoundation/Order.swift b/Sources/SwiftFoundation/Order.swift index 43a3ecd..731270b 100644 --- a/Sources/SwiftFoundation/Order.swift +++ b/Sources/SwiftFoundation/Order.swift @@ -9,9 +9,9 @@ /// Indicates how items are ordered. public enum Order: Int { - case Ascending = -1 - case Same = 0 - case Descending = 1 + case ascending = -1 + case same = 0 + case descending = 1 } // MARK: - Implementation @@ -19,19 +19,19 @@ public enum Order: Int { public extension Comparable { /** Compares the reciever with another and returns their order. */ - func compare(other: Self) -> Order { + func compare(_ other: Self) -> Order { if self < other { - return .Ascending + return .ascending } if self > other { - return .Descending + return .descending } - return .Same + return .same } } diff --git a/Sources/SwiftFoundation/POSIXRegularExpression.swift b/Sources/SwiftFoundation/POSIXRegularExpression.swift index ca14054..a2494f8 100644 --- a/Sources/SwiftFoundation/POSIXRegularExpression.swift +++ b/Sources/SwiftFoundation/POSIXRegularExpression.swift @@ -16,7 +16,7 @@ public typealias POSIXRegularExpression = regex_t public extension POSIXRegularExpression { - public static func compile(pattern: String, options: [RegularExpression.CompileOption]) -> (ErrorCode, POSIXRegularExpression) { + public static func compile(_ pattern: String, options: [RegularExpression.CompileOption]) -> (ErrorCode, POSIXRegularExpression) { var regularExpression = POSIXRegularExpression() @@ -32,7 +32,7 @@ public extension POSIXRegularExpression { regfree(&self) } - public func firstMatch(string: String, options: [RegularExpression.MatchOption]) -> RegularExpressionMatch? { + public func firstMatch(_ string: String, options: [RegularExpression.MatchOption]) -> RegularExpressionMatch? { // we are sure that that this method does not mutate the regular expression, so we make a copy var expression = self diff --git a/Sources/SwiftFoundation/POSIXUUID.swift b/Sources/SwiftFoundation/POSIXUUID.swift index 00cb964..bd792e7 100644 --- a/Sources/SwiftFoundation/POSIXUUID.swift +++ b/Sources/SwiftFoundation/POSIXUUID.swift @@ -16,12 +16,12 @@ // MARK: - POSIX UUID System Type Functions #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - public typealias POSIXUUIDStringType = uuid_string_t + internal typealias POSIXUUIDStringType = uuid_string_t #elseif os(Linux) - public typealias POSIXUUIDStringType = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8) + internal typealias POSIXUUIDStringType = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8) #endif -public func POSIXUUIDCreateRandom() -> uuid_t { +internal func POSIXUUIDCreateRandom() -> uuid_t { var uuid = uuid_t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) @@ -37,14 +37,14 @@ public func POSIXUUIDCreateRandom() -> uuid_t { return uuid } -public func POSIXUUIDConvertToString(uuid: uuid_t) -> String { +internal func POSIXUUIDConvertToString(_ uuid: uuid_t) -> String { let uuidString = POSIXUUIDConvertToUUIDString(uuid) return POSIXUUIDStringConvertToString(uuidString) } -public func POSIXUUIDConvertToUUIDString(uuid: uuid_t) -> POSIXUUIDStringType { +internal func POSIXUUIDConvertToUUIDString(_ uuid: uuid_t) -> POSIXUUIDStringType { var uuidCopy = uuid @@ -62,7 +62,7 @@ public func POSIXUUIDConvertToUUIDString(uuid: uuid_t) -> POSIXUUIDStringType { return uuidString } -public func POSIXUUIDStringConvertToString(uuidString: POSIXUUIDStringType) -> String { +internal func POSIXUUIDStringConvertToString(_ uuidString: POSIXUUIDStringType) -> String { var uuidStringCopy = uuidString @@ -76,7 +76,7 @@ public func POSIXUUIDStringConvertToString(uuidString: POSIXUUIDStringType) -> S }) } -public func POSIXUUIDConvertStringToUUID(string: String) -> uuid_t? { +internal func POSIXUUIDConvertStringToUUID(_ string: String) -> uuid_t? { let uuidPointer = UnsafeMutablePointer(allocatingCapacity: 1) defer { uuidPointer.deallocateCapacity(1) } diff --git a/Sources/SwiftFoundation/Predicate.swift b/Sources/SwiftFoundation/Predicate.swift index 6b21f5e..c07b18a 100644 --- a/Sources/SwiftFoundation/Predicate.swift +++ b/Sources/SwiftFoundation/Predicate.swift @@ -12,7 +12,7 @@ public protocol Predicate { /// Returns a Boolean value that indicates whether a given object matches the conditions specified by the predicate. /// - func evaluate(object: T) -> Bool + func evaluate(_ object: T) -> Bool } public extension Collection { diff --git a/Sources/SwiftFoundation/Range.swift b/Sources/SwiftFoundation/Range.swift index f4ebf51..ffc6027 100644 --- a/Sources/SwiftFoundation/Range.swift +++ b/Sources/SwiftFoundation/Range.swift @@ -8,7 +8,7 @@ public extension Range where Element: Integer { - func isSubset(other: Range) -> Bool { + func isSubset(_ other: Range) -> Bool { return self.startIndex >= other.startIndex && self.startIndex <= other.endIndex diff --git a/Sources/SwiftFoundation/RawRepresentable.swift b/Sources/SwiftFoundation/RawRepresentable.swift index da269ee..76e9e7a 100644 --- a/Sources/SwiftFoundation/RawRepresentable.swift +++ b/Sources/SwiftFoundation/RawRepresentable.swift @@ -11,7 +11,7 @@ public extension RawRepresentable { /// Creates a collection of ```RawRepresentable``` from a collection of raw values. Returns ```nil``` if an element in the array had an invalid raw value. - static func fromRawValues(rawValues: [RawValue]) -> [Self]? { + static func from(rawValues: [RawValue]) -> [Self]? { var representables = [Self]() diff --git a/Sources/SwiftFoundation/RegularExpression.swift b/Sources/SwiftFoundation/RegularExpression.swift index 2333380..884b9a3 100644 --- a/Sources/SwiftFoundation/RegularExpression.swift +++ b/Sources/SwiftFoundation/RegularExpression.swift @@ -24,7 +24,7 @@ public protocol RegularExpressionType: RawRepresentable, CustomStringConvertible init(_ pattern: String, options: CompileOptions) throws /// Finds the first match in the string - func match(string: String, options: MatchOptions) -> RegularExpressionMatch? + func match(_ string: String, options: MatchOptions) -> RegularExpressionMatch? } // MARK: - Protocol Implementation @@ -95,7 +95,7 @@ final public class RegularExpression: RegularExpressionType { guard code == POSIXRegularExpression.ErrorCode(0) else { throw CompileError(rawValue: code)! } } - public func match(string: String, options: [RegularExpression.MatchOption] = []) -> RegularExpressionMatch? { + public func match(_ string: String, options: [RegularExpression.MatchOption] = []) -> RegularExpressionMatch? { guard let match = internalExpression.firstMatch(string, options: options) else { return nil } @@ -140,7 +140,7 @@ public extension String { case .NotFound: return nil case let .Found(r): - return substring(r) + return substring(range: r) } } diff --git a/Sources/SwiftFoundation/SortDescriptor.swift b/Sources/SwiftFoundation/SortDescriptor.swift index 52ebcb9..73640cf 100644 --- a/Sources/SwiftFoundation/SortDescriptor.swift +++ b/Sources/SwiftFoundation/SortDescriptor.swift @@ -8,54 +8,35 @@ // MARK: - Protocol -/** Describes a basis for ordering types. */ -public protocol SortDescriptorType { +/// Describes a basis for ordering types. +public protocol SortDescriptor { - associatedtype SortedType + associatedtype Sorted var ascending: Bool { get } /** Compares two types and gets their order. */ - func sort(first: SortedType, second: SortedType) -> Order + func sort(first: Sorted, second: Sorted) -> Order } -// MARK: - Functions - -/** Returns a sorted array of the collection as specified by the sort descriptor. */ -public func Sort(collection: T, sortDescriptor: S) -> [T.Iterator.Element] { +public extension Collection { - return collection.sorted { (first: T.Iterator.Element, second: T.Iterator.Element) -> Bool in - - let order = sortDescriptor.sort(first, second: second) + /// Returns a sorted array of the collection as specified by the sort descriptor. + func sorted(_ sortDescriptor: S) -> [Iterator.Element] { - let first: Bool = { + return self.sorted { (first: Iterator.Element, second: Iterator.Element) -> Bool in + + let order = sortDescriptor.sort(first: first, second: second) switch order { - case .Ascending: return sortDescriptor.ascending + case .ascending: return sortDescriptor.ascending - case .Descending: return !sortDescriptor.ascending + case .descending: return !sortDescriptor.ascending - case .Same: return true + case .same: return true } - }() - - return first + } } } - -/* -/** Returns a sorted array if the collection sorted as specified by a given array of sort descriptors. */ -public func Sort(collection: T, sortDescriptors: [S]) -> [T.Iterator.Element] { - - var sortedArray = collection.map { (element: T.Iterator.Element) -> T in } - - for sortDescriptor in sortDescriptors { - - sortedArray = Sort(sortDescriptor, collection: sortedArray) - } - - return sortedArray -} -*/ \ No newline at end of file diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 7d9f0dd..b2d63ca 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -29,14 +29,18 @@ public final class Thread { #if os(Linux) var internalThread: pthread_t = 0 - #else - var internalThread: pthread_t = nil + #elseif os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + var internalThread: pthread_t? = nil #endif guard pthread_create(&internalThread, nil, ThreadPrivateMain, pointer) == 0 else { throw POSIXError.fromErrorNumber! } - self.internalThread = internalThread + #if os(Linux) + self.internalThread = internalThread + #elseif os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + self.internalThread = internalThread! + #endif pthread_detach(internalThread) } @@ -69,7 +73,7 @@ public final class Thread { // MARK: - Private -private func ThreadPrivateMain(arg: UnsafeMutablePointer) -> UnsafeMutablePointer { +private func ThreadPrivateMain(arg: UnsafeMutablePointer!) -> UnsafeMutablePointer! { let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) diff --git a/Sources/SwiftFoundation/URLClient.swift b/Sources/SwiftFoundation/URLClient.swift index a19e1b4..2beff9b 100644 --- a/Sources/SwiftFoundation/URLClient.swift +++ b/Sources/SwiftFoundation/URLClient.swift @@ -12,5 +12,5 @@ public protocol URLClient { associatedtype Response: URLResponse - func sendRequest(request: Request) throws -> Response + func send(request: Request) throws -> Response } \ No newline at end of file diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index 4230791..44f87f7 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -22,9 +22,7 @@ final class AtomicTests: XCTestCase { func testAtomic() { var atomic = Atomic(0) - - var wait = true - + // main thread for i in 0 ..< 10 { diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index e3401b9..f7ad8cd 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -31,7 +31,7 @@ final class DataTests: XCTestCase { memcpy(&testData.byteValue, dataPointer, dataLength) - let data = Data.fromBytePointer(dataPointer, length: dataLength) + let data = Data.from(pointer: dataPointer, length: dataLength) XCTAssert(data == testData, "\(data) == \(testData)") } diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 482301c..85643a9 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -35,7 +35,7 @@ final class JSONTests: XCTestCase { func testJSONParse() { - func parseJSON(jsonValue: JSON.Value, _ jsonString: String) { + func parseJSON(_ jsonValue: JSON.Value, _ jsonString: String) { #if os(OSX) || os(iOS) @@ -81,7 +81,7 @@ final class JSONTests: XCTestCase { func testJSONWriting() { - func writeJSON(json: JSON.Value, _ expectedJSONString: String) { + func writeJSON(_ json: JSON.Value, _ expectedJSONString: String) { guard let jsonString = json.toString() else { XCTFail("Could not serialize JSON"); return } diff --git a/Sources/UnitTests/OrderTests.swift b/Sources/UnitTests/OrderTests.swift index 4470c64..14a566a 100644 --- a/Sources/UnitTests/OrderTests.swift +++ b/Sources/UnitTests/OrderTests.swift @@ -7,7 +7,6 @@ // import XCTest -import Foundation import SwiftFoundation final class OrderTests: XCTestCase { @@ -18,19 +17,19 @@ final class OrderTests: XCTestCase { // number - XCTAssert(1.compare(2) == Order.Ascending) + XCTAssert((1 as Int).compare(2) == .ascending) - XCTAssert(2.compare(1) == Order.Descending) + XCTAssert((2 as Int).compare(1) == .descending) - XCTAssert(1.compare(1) == Order.Same) + XCTAssert((1 as Int).compare(1) == .same) // string - XCTAssert("a".compare("b") == Order.Ascending) + XCTAssert("a".compare("b") == .ascending) - XCTAssert("b".compare("a") == Order.Descending) + XCTAssert("b".compare("a") == .descending) - XCTAssert("a".compare("a") == Order.Same) + XCTAssert("a".compare("a") == .same) // dates @@ -38,7 +37,7 @@ final class OrderTests: XCTestCase { let later = now + 0.5 - XCTAssert(now.compare(later) == Order.Ascending) + XCTAssert(now.compare(later) == .ascending) XCTAssert(now < later) } diff --git a/Sources/UnitTests/RegularExpressionTests.swift b/Sources/UnitTests/RegularExpressionTests.swift index c1ba7ce..d050933 100644 --- a/Sources/UnitTests/RegularExpressionTests.swift +++ b/Sources/UnitTests/RegularExpressionTests.swift @@ -128,7 +128,7 @@ final class RegularExpressionTests: XCTestCase { return } - guard let capturedString = testString.substring(beerRange) else { + guard let capturedString = testString.substring(range: beerRange) else { XCTFail("Failed to get a substring with range \(beerRange) in \(testString)") return } diff --git a/Sources/UnitTests/SortDescriptorTests.swift b/Sources/UnitTests/SortDescriptorTests.swift index f3656ca..7107cc4 100644 --- a/Sources/UnitTests/SortDescriptorTests.swift +++ b/Sources/UnitTests/SortDescriptorTests.swift @@ -25,7 +25,7 @@ final class SortDescriptorTests: XCTestCase { let items = names - let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: true)) + let sortedItems = items.sorted(ComparableSortDescriptor(ascending: true)) let expected = items.sorted() @@ -36,7 +36,7 @@ final class SortDescriptorTests: XCTestCase { let items = names - let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: false)) + let sortedItems = items.sorted(ComparableSortDescriptor(ascending: false)) let expected = Array(items.sorted().reversed()) @@ -49,7 +49,7 @@ final class SortDescriptorTests: XCTestCase { let items = places - let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: true)) + let sortedItems = items.sorted(ComparableSortDescriptor(ascending: true)) let expected = items.sorted() @@ -60,7 +60,7 @@ final class SortDescriptorTests: XCTestCase { let items = places - let sortedItems = Sort(items, sortDescriptor: ComparableSortDescriptor(ascending: false)) + let sortedItems = items.sorted(ComparableSortDescriptor(ascending: false)) let expected = Array(items.sorted().reversed()) @@ -76,7 +76,7 @@ final class SortDescriptorTests: XCTestCase { let items = names - let sortedItems = Sort(items, sortDescriptor: ComparatorSortDescriptor(ascending: true, comparator: { (first: String, second: String) -> Order in + let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: true, comparator: { (first: String, second: String) -> Order in return first.compare(second) })) @@ -90,7 +90,7 @@ final class SortDescriptorTests: XCTestCase { let items = names - let sortedItems = Sort(items, sortDescriptor: ComparatorSortDescriptor(ascending: false, comparator: { (first: String, second: String) -> Order in + let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: false, comparator: { (first: String, second: String) -> Order in return first.compare(second) })) @@ -106,7 +106,7 @@ final class SortDescriptorTests: XCTestCase { let items = places - let sortedItems = Sort(items, sortDescriptor: ComparatorSortDescriptor(ascending: true, comparator: { (first: String, second: String) -> Order in + let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: true, comparator: { (first: String, second: String) -> Order in return first.compare(second) })) @@ -118,7 +118,7 @@ final class SortDescriptorTests: XCTestCase { let items = places - let sortedItems = Sort(items, sortDescriptor: ComparatorSortDescriptor(ascending: false, comparator: { (first: String, second: String) -> Order in + let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: false, comparator: { (first: String, second: String) -> Order in return first.compare(second) })) diff --git a/Sources/UnitTests/main.swift b/Sources/UnitTests/main.swift index 5d17708..8e82751 100644 --- a/Sources/UnitTests/main.swift +++ b/Sources/UnitTests/main.swift @@ -9,9 +9,9 @@ import XCTest #if os(OSX) || os(iOS) || os(watchOS) - func XCTMain(testCases: [XCTestCaseEntry]) { fatalError("Not Implemented. Linux only") } + func XCTMain(_ testCases: [XCTestCaseEntry]) { fatalError("Not Implemented. Linux only") } - func testCase(allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry { fatalError("Not Implemented. Linux only") } + func testCase(_ allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry { fatalError("Not Implemented. Linux only") } struct XCTestCaseEntry { } #endif diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index ede6871..a064f63 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -533,7 +533,6 @@ 6E2C2B361C20F6EB00B2C995 /* Null.swift */, 6E2C2B371C20F6EB00B2C995 /* Order.swift */, 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */, - 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */, 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */, 6E2C2B411C20F6EB00B2C995 /* RegularExpressionCompileError.swift */, 6E2C2B421C20F6EB00B2C995 /* RegularExpressionCompileOption.swift */, @@ -594,6 +593,7 @@ 6E2C2C271C20FB0600B2C995 /* Swift */ = { isa = PBXGroup; children = ( + 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */, 6E2C2B461C20F6EB00B2C995 /* String.swift */, 6E2C2B331C20F6EB00B2C995 /* Integer.swift */, 6EFF9A1A1CAD0C6B00917CB3 /* Range.swift */, diff --git a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme index 9fedf47..0b5edd9 100644 --- a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme +++ b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme @@ -23,7 +23,7 @@ Date: Thu, 14 Apr 2016 11:34:15 -0500 Subject: [PATCH 27/68] updated Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a11998..27efe20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a + - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From d6d7670377c537beeaaa368ad0e68ebea496b827 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 14 Apr 2016 11:38:52 -0500 Subject: [PATCH 28/68] Updated Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 27efe20..ae3f7db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,6 @@ script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool build -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$(pwd)/tests/$SWIFT_VERSION-ubuntu14.04/usr/bin:"${PATH}" ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then swift build -c release ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then swift build release ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then .build/release/UnitTests ; fi \ No newline at end of file From aca70ddca59f69455775295ed8e9399d062de8de Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 14 Apr 2016 11:44:20 -0500 Subject: [PATCH 29/68] update Travis CI --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae3f7db..9dd5eeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,6 @@ script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool build -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$(pwd)/tests/$SWIFT_VERSION-ubuntu14.04/usr/bin:"${PATH}" ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then swift build release ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then .build/release/UnitTests ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then swift build ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then .build/debug/UnitTests ; fi \ No newline at end of file From 2490130e2a72183f5fe209df82b0fc012f41f532 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Fri, 22 Apr 2016 21:41:48 -0500 Subject: [PATCH 30/68] updated DateComponents for Swift 3.0 --- Sources/SwiftFoundation/DateComponents.swift | 131 ++++++++++--------- Sources/UnitTests/DateComponentsTest.swift | 13 +- 2 files changed, 80 insertions(+), 64 deletions(-) diff --git a/Sources/SwiftFoundation/DateComponents.swift b/Sources/SwiftFoundation/DateComponents.swift index 0ccb084..3d56486 100644 --- a/Sources/SwiftFoundation/DateComponents.swift +++ b/Sources/SwiftFoundation/DateComponents.swift @@ -13,15 +13,16 @@ #endif public struct DateComponents { + public enum Component { - case Second - case Minute - case Hour - case DayOfMonth - case Month - case Year - case Weekday - case DayOfYear + case second + case minute + case hour + case dayOfMonth + case month + case year + case weekday + case dayOfYear } public var second: Int32 = 0 @@ -33,73 +34,79 @@ public struct DateComponents { public var weekday: Int32 public var dayOfYear: Int32 = 1 - public init(timeInterval: TimeInterval) { - self.init( - brokenDown: tm( - UTCSecondsSince1970: timeval(timeInterval: timeInterval).tv_sec - ) - ) + /// Intializes from a time interval interval between the current date and 1 January 1970, GMT. + public init(since1970 timeinterval: TimeInterval) { + + self.init(brokenDown: tm(UTCSecondsSince1970: timeval(timeInterval: timeinterval).tv_sec )) } public init() { weekday = 0 } - public init(fromDate date: Date) { - self.init(timeInterval: date.since1970) + /// Initializes from a `Date`. + public init(date: Date) { + + self.init(since1970: date.since1970) } public var date: Date { return Date(since1970: timeInterval) } - public mutating func setValue(value: Int32, forComponent component: Component) { - switch component { - case .Second: - second = value - break - case .Minute: - minute = value - break - case .Hour: - hour = value - break - case .DayOfMonth: - dayOfMonth = value - break - case .Month: - month = value - break - case .Year: - year = value - break - case .Weekday: - weekday = value - break - case .DayOfYear: - dayOfYear = value - break + /// Get the value for the specified component. + public subscript(component: Component) -> Int32 { + + get { + + switch component { + case .second: + return second + case .minute: + return minute + case .hour: + return hour + case .dayOfMonth: + return dayOfMonth + case .month: + return month + case .year: + return year + case .weekday: + return weekday + case .dayOfYear: + return dayOfYear + } } - } - - public func valueForComponent(component: Component) -> Int32 { - switch component { - case .Second: - return second - case .Minute: - return minute - case .Hour: - return hour - case .DayOfMonth: - return dayOfMonth - case .Month: - return month - case .Year: - return year - case .Weekday: - return weekday - case .DayOfYear: - return dayOfYear + + set { + + switch component { + case .second: + second = newValue + break + case .minute: + minute = newValue + break + case .hour: + hour = newValue + break + case .dayOfMonth: + dayOfMonth = newValue + break + case .month: + month = newValue + break + case .year: + year = newValue + break + case .weekday: + weekday = newValue + break + case .dayOfYear: + dayOfYear = newValue + break + } } } diff --git a/Sources/UnitTests/DateComponentsTest.swift b/Sources/UnitTests/DateComponentsTest.swift index 94eb648..99e109c 100644 --- a/Sources/UnitTests/DateComponentsTest.swift +++ b/Sources/UnitTests/DateComponentsTest.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class DateComponentsTest: XCTestCase { - static let allTests: [(String, DateComponentsTest -> () throws -> Void)] = [("testBuildDate", testBuildDate)] + static let allTests: [(String, DateComponentsTest -> () throws -> Void)] = [("testBuildDate", testBuildDate), ("testValueForComponent", testValueForComponent)] func testBuildDate() { @@ -27,4 +27,13 @@ final class DateComponentsTest: XCTestCase { XCTAssert(assertionDate == madeDate) } -} \ No newline at end of file + + func testValueForComponent() { + + let dateComponents = DateComponents(since1970: 560822400) + + XCTAssert(dateComponents[.year] == 1987) + XCTAssert(dateComponents[.month] == 10) + XCTAssert(dateComponents[.dayOfMonth] == 10) + } +} From 972d26d648249d90d749a49bc1373347796b8bd5 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 30 Apr 2016 21:57:22 -0500 Subject: [PATCH 31/68] enabled WatchOS target --- .../SwiftFoundation WatchOS.xcscheme | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation WatchOS.xcscheme diff --git a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation WatchOS.xcscheme b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation WatchOS.xcscheme new file mode 100644 index 0000000..eaa5fc1 --- /dev/null +++ b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation WatchOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b29845eb861f6c0c49e6c0980a020f058fc94624 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 30 Apr 2016 22:23:26 -0500 Subject: [PATCH 32/68] deleted workspace --- .../contents.xcworkspacedata | 10 ----- .../xcshareddata/SwiftFoundation.xccheckout | 41 ------------------- .../xcdebugger/Breakpoints_v2.xcbkptlist | 23 ----------- 3 files changed, 74 deletions(-) delete mode 100644 SwiftFoundation.xcworkspace/contents.xcworkspacedata delete mode 100644 SwiftFoundation.xcworkspace/xcshareddata/SwiftFoundation.xccheckout delete mode 100644 SwiftFoundation.xcworkspace/xcuserdata/Coleman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist diff --git a/SwiftFoundation.xcworkspace/contents.xcworkspacedata b/SwiftFoundation.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index f0ad398..0000000 --- a/SwiftFoundation.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/SwiftFoundation.xcworkspace/xcshareddata/SwiftFoundation.xccheckout b/SwiftFoundation.xcworkspace/xcshareddata/SwiftFoundation.xccheckout deleted file mode 100644 index 3ce8630..0000000 --- a/SwiftFoundation.xcworkspace/xcshareddata/SwiftFoundation.xccheckout +++ /dev/null @@ -1,41 +0,0 @@ - - - - - IDESourceControlProjectFavoriteDictionaryKey - - IDESourceControlProjectIdentifier - 857F9637-0165-435F-B5B2-41B999953D76 - IDESourceControlProjectName - SwiftFoundation - IDESourceControlProjectOriginsDictionary - - 4202455695F7B021363B482C067D3C0730DD1B34 - https://github.com/PureSwift/SwiftFoundation.git - - IDESourceControlProjectPath - SwiftFoundation.xcworkspace - IDESourceControlProjectRelativeInstallPathDictionary - - 4202455695F7B021363B482C067D3C0730DD1B34 - .. - - IDESourceControlProjectURL - https://github.com/PureSwift/SwiftFoundation.git - IDESourceControlProjectVersion - 111 - IDESourceControlProjectWCCIdentifier - 4202455695F7B021363B482C067D3C0730DD1B34 - IDESourceControlProjectWCConfigurations - - - IDESourceControlRepositoryExtensionIdentifierKey - public.vcs.git - IDESourceControlWCCIdentifierKey - 4202455695F7B021363B482C067D3C0730DD1B34 - IDESourceControlWCCName - SwiftFoundation - - - - diff --git a/SwiftFoundation.xcworkspace/xcuserdata/Coleman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/SwiftFoundation.xcworkspace/xcuserdata/Coleman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index 09034a0..0000000 --- a/SwiftFoundation.xcworkspace/xcuserdata/Coleman.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - From f82643136dab94fd3f49ade0ba0b00825f3bd0a7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 30 Apr 2016 22:25:56 -0500 Subject: [PATCH 33/68] fixed WatchOS target --- Cartfile.resolved | 2 +- Xcode/SwiftFoundation.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index b8525bb..0619d85 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "PureSwift/json-c" "e8e38025563d43e425536200002ad13c3f35a98b" +github "PureSwift/JSON-C" "098c5ad91d262de5ad695a6162b6d0d4b384741d" diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index a064f63..d63b5f5 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -1232,6 +1232,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = $SRCROOT/../Carthage/Build/WatchOS; FRAMEWORK_VERSION = A; INFOPLIST_FILE = "$(SRCROOT)/SwiftFoundation/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -1252,6 +1253,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = $SRCROOT/../Carthage/Build/WatchOS; FRAMEWORK_VERSION = A; INFOPLIST_FILE = "$(SRCROOT)/SwiftFoundation/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; From c64cdccdc64082990ea95f8e8134819f5adbcdb7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Wed, 4 May 2016 23:27:54 -0500 Subject: [PATCH 34/68] updated for Swift 3.0 swift-DEVELOPMENT-SNAPSHOT-2016-05-03 --- .../NSFileManagerTests.swift | 16 +++---- .../POSIXRegularExpression.swift | 2 +- Sources/SwiftFoundation/Range.swift | 10 ++-- .../SwiftFoundation/RegularExpression.swift | 8 +--- Sources/SwiftFoundation/String.swift | 5 ++ Sources/UnitTests/RangeTests.swift | 46 ++++++++++++++++--- 6 files changed, 60 insertions(+), 27 deletions(-) diff --git a/Sources/FoundationUnitTests/NSFileManagerTests.swift b/Sources/FoundationUnitTests/NSFileManagerTests.swift index cb3f601..1cd4343 100644 --- a/Sources/FoundationUnitTests/NSFileManagerTests.swift +++ b/Sources/FoundationUnitTests/NSFileManagerTests.swift @@ -26,7 +26,7 @@ class FileManagerTests: XCTestCase { func testGetCurrentDirectory() { - XCTAssert(FileManager.currentDirectory == NSFileManager.defaultManager().currentDirectoryPath) + XCTAssert(FileManager.currentDirectory == NSFileManager.default().currentDirectoryPath) } func testFileExists() { @@ -35,7 +35,7 @@ class FileManagerTests: XCTestCase { let path = NSTemporaryDirectory() + "/" + fileName - XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: NSData(), attributes: nil)) + XCTAssert(NSFileManager.default().createFile(atPath: path, contents: NSData(), attributes: nil)) XCTAssert(FileManager.fileExists(at: path)) @@ -44,9 +44,9 @@ class FileManagerTests: XCTestCase { func testDirectoryExists() { - let path = try! NSFileManager.defaultManager().urlForDirectory( NSSearchPathDirectory.userDirectory, in: NSSearchPathDomainMask.allDomainsMask, appropriateFor: nil, create: false).path! + let path = try! NSFileManager.default().urlForDirectory( NSSearchPathDirectory.userDirectory, in: NSSearchPathDomainMask.allDomainsMask, appropriateFor: nil, create: false).path! - assert(NSFileManager.defaultManager().fileExists(atPath: path, isDirectory: nil), + assert(NSFileManager.default().fileExists(atPath: path, isDirectory: nil), "Setting non existent directory as test parameter") XCTAssert(FileManager.directoryExists(at: path)) @@ -66,7 +66,7 @@ class FileManagerTests: XCTestCase { let path = NSTemporaryDirectory() + "/" + fileName + ".txt" - XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: data.toFoundation(), attributes: nil)) + XCTAssert(NSFileManager.default().createFile(atPath: path, contents: data.toFoundation(), attributes: nil)) // read file @@ -92,7 +92,7 @@ class FileManagerTests: XCTestCase { let path = NSTemporaryDirectory() + fileName + ".txt" // create empty file - XCTAssert(NSFileManager.defaultManager().createFile(atPath: path, contents: NSData(), attributes: nil)) + XCTAssert(NSFileManager.default().createFile(atPath: path, contents: NSData(), attributes: nil)) // write file do { try FileManager.set(contents: data, at: path) } @@ -126,9 +126,9 @@ class FileManagerTests: XCTestCase { // read data - XCTAssert(NSFileManager.defaultManager().fileExists(atPath: path)) + XCTAssert(NSFileManager.default().fileExists(atPath: path)) - NSFileManager.defaultManager() + NSFileManager.default() guard let readData = NSData(contentsOfFile: path) else { XCTFail("Could not read data"); return } diff --git a/Sources/SwiftFoundation/POSIXRegularExpression.swift b/Sources/SwiftFoundation/POSIXRegularExpression.swift index a2494f8..fb2c70d 100644 --- a/Sources/SwiftFoundation/POSIXRegularExpression.swift +++ b/Sources/SwiftFoundation/POSIXRegularExpression.swift @@ -82,7 +82,7 @@ public extension POSIXRegularExpression { let range = Int(subexpressionMatch.rm_so) ..< Int(subexpressionMatch.rm_eo) - match.subexpressionRanges.append(RegularExpressionMatch.Range.Found(range)) + match.subexpressionRanges.append(RegularExpressionMatch.Range.Found(Range(range))) } } diff --git a/Sources/SwiftFoundation/Range.swift b/Sources/SwiftFoundation/Range.swift index ffc6027..42d2709 100644 --- a/Sources/SwiftFoundation/Range.swift +++ b/Sources/SwiftFoundation/Range.swift @@ -6,13 +6,13 @@ // Copyright © 2016 PureSwift. All rights reserved. // -public extension Range where Element: Integer { +public extension Range where Bound: Integer { func isSubset(_ other: Range) -> Bool { - return self.startIndex >= other.startIndex - && self.startIndex <= other.endIndex - && self.endIndex >= other.startIndex - && self.endIndex <= other.endIndex + return self.lowerBound >= other.lowerBound + && self.lowerBound <= other.upperBound + && self.upperBound >= other.lowerBound + && self.upperBound <= other.upperBound } } \ No newline at end of file diff --git a/Sources/SwiftFoundation/RegularExpression.swift b/Sources/SwiftFoundation/RegularExpression.swift index 884b9a3..1f0f3e8 100644 --- a/Sources/SwiftFoundation/RegularExpression.swift +++ b/Sources/SwiftFoundation/RegularExpression.swift @@ -1,4 +1,4 @@ -// +// // RegularExpression.swift // SwiftFoundation // @@ -135,6 +135,7 @@ public struct RegularExpressionMatch { } public extension String { + func substring(range: RegularExpressionMatch.Range) -> String? { switch range { case .NotFound: @@ -143,9 +144,4 @@ public extension String { return substring(range: r) } } - - func substring(range: Range) -> String? { - let indexRange = utf8.startIndex.advanced(by: range.startIndex) ..< utf8.startIndex.advanced(by: range.endIndex) - return String(utf8[indexRange]) - } } diff --git a/Sources/SwiftFoundation/String.swift b/Sources/SwiftFoundation/String.swift index 85b0af5..cd9303c 100644 --- a/Sources/SwiftFoundation/String.swift +++ b/Sources/SwiftFoundation/String.swift @@ -46,4 +46,9 @@ public extension String { return Data(byteValue: [] + utf8) } + + func substring(range: Range) -> String? { + let indexRange = utf8.index(utf8.startIndex, offsetBy: range.lowerBound) ..< utf8.index(utf8.startIndex, offsetBy: range.upperBound) + return String(utf8[indexRange]) + } } \ No newline at end of file diff --git a/Sources/UnitTests/RangeTests.swift b/Sources/UnitTests/RangeTests.swift index cb243ca..0ea607a 100644 --- a/Sources/UnitTests/RangeTests.swift +++ b/Sources/UnitTests/RangeTests.swift @@ -15,14 +15,46 @@ final class RangeTests: XCTestCase { func testSubset() { - let superset = 1 ... 10 + let superset = Range(1 ... 10) - XCTAssert((1...10).isSubset(superset)) - XCTAssert((1...9).isSubset(superset)) - XCTAssert((2...10).isSubset(superset)) - XCTAssert((2...9).isSubset(superset)) + XCTAssert(Range(1...10).isSubset(superset)) + XCTAssert(Range(1...9).isSubset(superset)) + XCTAssert(Range(2...10).isSubset(superset)) + XCTAssert(Range(2...9).isSubset(superset)) - XCTAssert((0...10).isSubset(superset) == false) - XCTAssert((0...11).isSubset(superset) == false) + XCTAssert((Range(0...10).isSubset(superset)) == false) + XCTAssert((Range(0...11).isSubset(superset)) == false) + + + } + + func testSubsetContainsElement() { + + let superset = Range(1 ... 10) + + XCTAssert(Range(1...10).verifyElements(of: superset)) + XCTAssert(Range(1...9).verifyElements(of: superset)) + XCTAssert(Range(2...10).verifyElements(of: superset)) + XCTAssert(Range(2...9).verifyElements(of: superset)) + + XCTAssert((Range(0...10).verifyElements(of: superset)) == false) + XCTAssert((Range(0...11).verifyElements(of: superset)) == false) } } + +private extension Range where Bound: Integer { + + func verifyElements(of superset: Range) -> Bool { + + /// dont try this at home kids + let range = unsafeBitCast(self, to: Range.self) + + for element in range.lowerBound ..< range.upperBound { + + guard superset.contains(element) + else { return false } + } + + return true + } +} \ No newline at end of file From 13ee1c9d3eb58fd2623c9b8cceb77acc5cc72726 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Wed, 4 May 2016 23:35:43 -0500 Subject: [PATCH 35/68] updated Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9dd5eeb..472a29a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a + - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-05-03-a script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From 5e17b3a4d2c650058f863a5440ee44f852922162 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Wed, 4 May 2016 23:47:26 -0500 Subject: [PATCH 36/68] updated unit tests for Linux --- Sources/UnitTests/RegularExpressionTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/UnitTests/RegularExpressionTests.swift b/Sources/UnitTests/RegularExpressionTests.swift index d050933..1e40f99 100644 --- a/Sources/UnitTests/RegularExpressionTests.swift +++ b/Sources/UnitTests/RegularExpressionTests.swift @@ -27,7 +27,7 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(match.range) + let stringRange = NSRange(Range(match.range)) #if os(Linux) let matchString = NSString(string: string).substringWithRange(stringRange) @@ -49,7 +49,7 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(match.range) + let stringRange = NSRange(Range(match.range)) #if os(Linux) let matchString = NSString(string: string).substringWithRange(stringRange) @@ -70,7 +70,7 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(match.range) + let stringRange = NSRange(Range(match.range)) #if os(Linux) let matchString = NSString(string: string).substringWithRange(stringRange) @@ -91,7 +91,7 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(match.range) + let stringRange = NSRange(Range(match.range)) #if os(Linux) let matchString = NSString(string: string).substringWithRange(stringRange) From 38d1bfef02fce983db6e6e06c58cda962e968b2e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Fri, 6 May 2016 03:08:14 -0500 Subject: [PATCH 37/68] updated Unit Tests for Linux --- .../UnitTests/RegularExpressionTests.swift | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/Sources/UnitTests/RegularExpressionTests.swift b/Sources/UnitTests/RegularExpressionTests.swift index 1e40f99..8d3086a 100644 --- a/Sources/UnitTests/RegularExpressionTests.swift +++ b/Sources/UnitTests/RegularExpressionTests.swift @@ -27,13 +27,9 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(Range(match.range)) + let stringRange = NSRange(match.range) - #if os(Linux) - let matchString = NSString(string: string).substringWithRange(stringRange) - #else - let matchString = NSString(string: string).substring(with: stringRange) - #endif + let matchString = NSString(string: string).substring(with: stringRange) XCTAssert(matchString == "Welcome") } @@ -49,13 +45,9 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(Range(match.range)) + let stringRange = NSRange(match.range) - #if os(Linux) - let matchString = NSString(string: string).substringWithRange(stringRange) - #else - let matchString = NSString(string: string).substring(with: stringRange) - #endif + let matchString = NSString(string: string).substring(with: stringRange) XCTAssert(matchString == "aaa") } @@ -70,13 +62,9 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(Range(match.range)) + let stringRange = NSRange(match.range) - #if os(Linux) - let matchString = NSString(string: string).substringWithRange(stringRange) - #else - let matchString = NSString(string: string).substring(with: stringRange) - #endif + let matchString = NSString(string: string).substring(with: stringRange) XCTAssert(matchString == "Bird", matchString) } @@ -91,13 +79,9 @@ final class RegularExpressionTests: XCTestCase { guard let match = regex.match(string, options: []) else { XCTFail("Could not find match"); return } - let stringRange = NSRange(Range(match.range)) + let stringRange = NSRange(match.range) - #if os(Linux) - let matchString = NSString(string: string).substringWithRange(stringRange) - #else - let matchString = NSString(string: string).substring(with: stringRange) - #endif + let matchString = NSString(string: string).substring(with: stringRange) // matched whole string XCTAssert(matchString == string) @@ -140,3 +124,15 @@ final class RegularExpressionTests: XCTestCase { } } } + +#if os(Linux) + +extension NSRange { + + init(_ range: Range) { + + self = NSRange(CountableRange(range)) + } +} + +#endif From 8c64dc3cc814c198749a6caebbd2737061912b01 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 19 May 2016 22:02:09 -0500 Subject: [PATCH 38/68] updated for Swift 3.0 09-05-2016 --- Sources/FoundationConvertible/HTTPClient.swift | 2 +- Sources/FoundationConvertible/NSJSONSerialization.swift | 6 +++--- Sources/SwiftFoundation/JSONParse.swift | 4 ++-- Sources/SwiftFoundation/JSONSerialization.swift | 2 +- Sources/SwiftFoundation/POSIXTime.swift | 4 +++- Sources/SwiftFoundation/Thread.swift | 4 ++-- Sources/UnitTests/AtomicTests.swift | 2 +- Sources/UnitTests/DataTests.swift | 2 +- Sources/UnitTests/DateComponentsTest.swift | 2 +- Sources/UnitTests/JSONTests.swift | 8 ++++---- Sources/UnitTests/OrderTests.swift | 2 +- Sources/UnitTests/POSIXTimeTests.swift | 2 +- Sources/UnitTests/RangeTests.swift | 2 +- Sources/UnitTests/RegularExpressionTests.swift | 2 +- Sources/UnitTests/SortDescriptorTests.swift | 2 +- Sources/UnitTests/StringTests.swift | 2 +- Sources/UnitTests/UUIDTests.swift | 2 +- Sources/UnitTests/main.swift | 2 +- 18 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Sources/FoundationConvertible/HTTPClient.swift b/Sources/FoundationConvertible/HTTPClient.swift index b9dd5d1..f153027 100644 --- a/Sources/FoundationConvertible/HTTPClient.swift +++ b/Sources/FoundationConvertible/HTTPClient.swift @@ -40,7 +40,7 @@ public extension HTTP { // execute request - let semaphore = dispatch_semaphore_create(0); + let semaphore = dispatch_semaphore_create(0)!; var error: NSError? diff --git a/Sources/FoundationConvertible/NSJSONSerialization.swift b/Sources/FoundationConvertible/NSJSONSerialization.swift index 8ec2a70..4d85401 100644 --- a/Sources/FoundationConvertible/NSJSONSerialization.swift +++ b/Sources/FoundationConvertible/NSJSONSerialization.swift @@ -80,7 +80,7 @@ public extension NSJSONSerialization { case .Number(let number): return number - case .Array(let array): return array.rawValues + case .Array(let array): return array.rawValues as NSArray case .Dictionary(let dictionary): @@ -91,7 +91,7 @@ public extension NSJSONSerialization { dictionaryValue[key] = value.rawValue } - return dictionaryValue + return dictionaryValue as NSDictionary } } @@ -207,7 +207,7 @@ private let falseNumber: NSNumber = false private let trueObjCType = String(validatingUTF8: trueNumber.objCType) private let falseObjCType = String(validatingUTF8: falseNumber.objCType) -private let intNumber: NSNumber = Int(1) +private let intNumber: NSNumber = NSNumber(value: Int(1)) private let intObjCType = String(validatingUTF8: intNumber.objCType)! diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index 18309ff..5a47e4d 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -44,7 +44,7 @@ private extension JSON.Value { case json_type_string: - let stringPointer = json_object_get_string(jsonObject) + let stringPointer = json_object_get_string(jsonObject)! let string = Swift.String(validatingUTF8: stringPointer) ?? "" @@ -97,7 +97,7 @@ private extension JSON.Value { case json_type_object: - let hashTable = json_object_get_object(jsonObject) + let hashTable = json_object_get_object(jsonObject)! var jsonDictionary = [StringValue: JSONValue]() diff --git a/Sources/SwiftFoundation/JSONSerialization.swift b/Sources/SwiftFoundation/JSONSerialization.swift index 7c3d3ad..d219952 100755 --- a/Sources/SwiftFoundation/JSONSerialization.swift +++ b/Sources/SwiftFoundation/JSONSerialization.swift @@ -34,7 +34,7 @@ public extension JSON.Value { let writingFlags = options.optionsBitmask() - let stringPointer = json_object_to_json_string_ext(jsonObject, writingFlags) + let stringPointer = json_object_to_json_string_ext(jsonObject, writingFlags)! let string = Swift.String(validatingUTF8: stringPointer)! diff --git a/Sources/SwiftFoundation/POSIXTime.swift b/Sources/SwiftFoundation/POSIXTime.swift index 1dc8df8..583b762 100644 --- a/Sources/SwiftFoundation/POSIXTime.swift +++ b/Sources/SwiftFoundation/POSIXTime.swift @@ -80,7 +80,9 @@ public extension tm { var seconds = UTCSecondsSince1970 - let timePointer = gmtime(&seconds) + let timePointer = gmtime(&seconds)! + + defer { free(timePointer) } self = timePointer.pointee } diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index b2d63ca..220c1d6 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -73,9 +73,9 @@ public final class Thread { // MARK: - Private -private func ThreadPrivateMain(arg: UnsafeMutablePointer!) -> UnsafeMutablePointer! { +private func ThreadPrivateMain(arg: UnsafeMutablePointer?) -> UnsafeMutablePointer? { - let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) + let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg!)) unmanaged.takeUnretainedValue().closure() diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift index 44f87f7..aafde80 100644 --- a/Sources/UnitTests/AtomicTests.swift +++ b/Sources/UnitTests/AtomicTests.swift @@ -17,7 +17,7 @@ import SwiftFoundation final class AtomicTests: XCTestCase { - static let allTests: [(String, AtomicTests -> () throws -> Void)] = [("testAtomic", testAtomic)] + static let allTests: [(String, (AtomicTests) -> () throws -> Void)] = [("testAtomic", testAtomic)] func testAtomic() { diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index f7ad8cd..67ffce6 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -15,7 +15,7 @@ import SwiftFoundation final class DataTests: XCTestCase { - static let allTests: [(String, DataTests -> () throws -> Void)] = [("testFromBytePointer", testFromBytePointer)] + static let allTests: [(String, (DataTests) -> () throws -> Void)] = [("testFromBytePointer", testFromBytePointer)] func testFromBytePointer() { diff --git a/Sources/UnitTests/DateComponentsTest.swift b/Sources/UnitTests/DateComponentsTest.swift index 99e109c..bc597e5 100644 --- a/Sources/UnitTests/DateComponentsTest.swift +++ b/Sources/UnitTests/DateComponentsTest.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class DateComponentsTest: XCTestCase { - static let allTests: [(String, DateComponentsTest -> () throws -> Void)] = [("testBuildDate", testBuildDate), ("testValueForComponent", testValueForComponent)] + static let allTests: [(String, (DateComponentsTest) -> () throws -> Void)] = [("testBuildDate", testBuildDate), ("testValueForComponent", testValueForComponent)] func testBuildDate() { diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 85643a9..9bced20 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class JSONTests: XCTestCase { - static let allTests: [(String, JSONTests -> () throws -> Void)] = [ + static let allTests: [(String, (JSONTests) -> () throws -> Void)] = [ ("testJSONEncodable", testJSONEncodable), ("testJSONParse", testJSONParse), @@ -90,11 +90,11 @@ final class JSONTests: XCTestCase { let foundationJSONOutput = try! NSJSONSerialization.data(withJSONObject: json.toFoundation().rawValue, options: NSJSONWritingOptions(rawValue: 0)) - let foundationJSONOutputString = NSString(data: foundationJSONOutput, encoding: NSUTF8StringEncoding) + let foundationJSONOutputString = NSString(data: foundationJSONOutput, encoding: NSUTF8StringEncoding)! - XCTAssert(jsonString == foundationJSONOutputString, "Must match Foundation output. \(jsonString) == \(foundationJSONOutputString)") + XCTAssert(jsonString == foundationJSONOutputString as String, "Must match Foundation output. \(jsonString) == \(foundationJSONOutputString)") - XCTAssert(jsonString == foundationJSONOutputString, "Expected JSON string must match Foundation output. \(expectedJSONString) == \(foundationJSONOutputString)") + XCTAssert(jsonString == foundationJSONOutputString as String, "Expected JSON string must match Foundation output. \(expectedJSONString) == \(foundationJSONOutputString)") #endif XCTAssert(jsonString == expectedJSONString, "Does not match expected output. \(jsonString) == \(expectedJSONString)") diff --git a/Sources/UnitTests/OrderTests.swift b/Sources/UnitTests/OrderTests.swift index 14a566a..8c5cc71 100644 --- a/Sources/UnitTests/OrderTests.swift +++ b/Sources/UnitTests/OrderTests.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class OrderTests: XCTestCase { - static let allTests: [(String, OrderTests -> () throws -> Void)] = [("testComparisonResult", testComparisonResult)] + static let allTests: [(String, (OrderTests) -> () throws -> Void)] = [("testComparisonResult", testComparisonResult)] func testComparisonResult() { diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index 3ca9753..469318e 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -17,7 +17,7 @@ import SwiftFoundation final class POSIXTimeTests: XCTestCase { - static let allTests: [(String, POSIXTimeTests -> () throws -> Void)] = + static let allTests: [(String, (POSIXTimeTests) -> () throws -> Void)] = [("testGetTimeOfDay", testGetTimeOfDay), ("testTimeVal", testTimeVal), ("testTimeSpec", testTimeSpec)] diff --git a/Sources/UnitTests/RangeTests.swift b/Sources/UnitTests/RangeTests.swift index 0ea607a..41ce877 100644 --- a/Sources/UnitTests/RangeTests.swift +++ b/Sources/UnitTests/RangeTests.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class RangeTests: XCTestCase { - static let allTests: [(String, RangeTests -> () throws -> Void)] = [ ("testSubset", testSubset) ] + static let allTests: [(String, (RangeTests) -> () throws -> Void)] = [ ("testSubset", testSubset) ] func testSubset() { diff --git a/Sources/UnitTests/RegularExpressionTests.swift b/Sources/UnitTests/RegularExpressionTests.swift index 8d3086a..46c810e 100644 --- a/Sources/UnitTests/RegularExpressionTests.swift +++ b/Sources/UnitTests/RegularExpressionTests.swift @@ -12,7 +12,7 @@ import Foundation final class RegularExpressionTests: XCTestCase { - static let allTests: [(String, RegularExpressionTests -> () throws -> Void)] = + static let allTests: [(String, (RegularExpressionTests) -> () throws -> Void)] = [("testSimpleRegex", testSimpleRegex), ("testExtendedRegex", testExtendedRegex), ("testMultipleSubexpressions", testMultipleSubexpressions), diff --git a/Sources/UnitTests/SortDescriptorTests.swift b/Sources/UnitTests/SortDescriptorTests.swift index 7107cc4..c7e402f 100644 --- a/Sources/UnitTests/SortDescriptorTests.swift +++ b/Sources/UnitTests/SortDescriptorTests.swift @@ -11,7 +11,7 @@ import SwiftFoundation final class SortDescriptorTests: XCTestCase { - static let allTests: [(String, SortDescriptorTests -> () throws -> Void)] = + static let allTests: [(String, (SortDescriptorTests) -> () throws -> Void)] = [("testComparableSorting", testComparableSorting), ("testComparatorSorting", testComparatorSorting)] diff --git a/Sources/UnitTests/StringTests.swift b/Sources/UnitTests/StringTests.swift index 01fa00b..eebfe42 100644 --- a/Sources/UnitTests/StringTests.swift +++ b/Sources/UnitTests/StringTests.swift @@ -10,7 +10,7 @@ import XCTest final class StringTests: XCTestCase { - static let allTests: [(String, StringTests -> () throws -> Void)] = [("testUTF8Data", testUTF8Data)] + static let allTests: [(String, (StringTests) -> () throws -> Void)] = [("testUTF8Data", testUTF8Data)] // MARK: - Functional Tests diff --git a/Sources/UnitTests/UUIDTests.swift b/Sources/UnitTests/UUIDTests.swift index 8b635eb..583398f 100644 --- a/Sources/UnitTests/UUIDTests.swift +++ b/Sources/UnitTests/UUIDTests.swift @@ -12,7 +12,7 @@ import SwiftFoundation final class UUIDTests: XCTestCase { - static let allTests: [(String, UUIDTests -> () throws -> Void)] = + static let allTests: [(String, (UUIDTests) -> () throws -> Void)] = [("testCreateRandomUUID", testCreateRandomUUID), ("testUUIDString", testUUIDString), ("testCreateFromString", testCreateFromString), diff --git a/Sources/UnitTests/main.swift b/Sources/UnitTests/main.swift index 8e82751..7c5b8e6 100644 --- a/Sources/UnitTests/main.swift +++ b/Sources/UnitTests/main.swift @@ -11,7 +11,7 @@ import XCTest #if os(OSX) || os(iOS) || os(watchOS) func XCTMain(_ testCases: [XCTestCaseEntry]) { fatalError("Not Implemented. Linux only") } - func testCase(_ allTests: [(String, T -> () throws -> Void)]) -> XCTestCaseEntry { fatalError("Not Implemented. Linux only") } + func testCase(_ allTests: [(String, (T) -> () throws -> Void)]) -> XCTestCaseEntry { fatalError("Not Implemented. Linux only") } struct XCTestCaseEntry { } #endif From fcdef6028237ffe18806852bc93ed187ab06fde1 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 19 May 2016 22:05:24 -0500 Subject: [PATCH 39/68] Updated Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 472a29a..b29d53a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-05-03-a + - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi From 6a29f3017d283c21f2c7b8c144f5383b677b2825 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 19 May 2016 22:11:02 -0500 Subject: [PATCH 40/68] fixed gmtime() crash on Linux --- Sources/SwiftFoundation/POSIXTime.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftFoundation/POSIXTime.swift b/Sources/SwiftFoundation/POSIXTime.swift index 583b762..8610a3b 100644 --- a/Sources/SwiftFoundation/POSIXTime.swift +++ b/Sources/SwiftFoundation/POSIXTime.swift @@ -80,10 +80,11 @@ public extension tm { var seconds = UTCSecondsSince1970 + // don't free! + // The return value points to a statically allocated struct which might be overwritten by subsequent calls to any of the date and time functions. + // http://linux.die.net/man/3/gmtime let timePointer = gmtime(&seconds)! - defer { free(timePointer) } - self = timePointer.pointee } } From 2fa806aaadc732f4949bce0fb41c350968a614b2 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 4 Jun 2016 12:36:04 -0500 Subject: [PATCH 41/68] removed warning in Time unit test --- Sources/UnitTests/POSIXTimeTests.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index 469318e..7860e0c 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -23,12 +23,17 @@ final class POSIXTimeTests: XCTestCase { ("testTimeSpec", testTimeSpec)] func testGetTimeOfDay() { - - do { try timeval.timeOfDay() } + + var time = timeval() + + do { time = try timeval.timeOfDay() } + catch { XCTFail("Error getting time: \(error)") } + + print("Current time: \(time)") } func testTimeVal() { From 676b0acfdb28d2d52a299389917bd448f801d4f9 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Wed, 8 Jun 2016 03:13:57 -0500 Subject: [PATCH 42/68] fixed FileManager for Linux --- Sources/SwiftFoundation/FileManager.swift | 21 ++++++++++++------- Sources/SwiftFoundation/POSIXFileStatus.swift | 8 +++---- .../POSIXFileSystemStatus.swift | 4 ---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Sources/SwiftFoundation/FileManager.swift b/Sources/SwiftFoundation/FileManager.swift index 7a62c4b..aff2e8b 100644 --- a/Sources/SwiftFoundation/FileManager.swift +++ b/Sources/SwiftFoundation/FileManager.swift @@ -10,25 +10,27 @@ import Darwin.C #elseif os(Linux) import Glibc + import CStatfs #endif -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - public typealias FileSystemAttributes = statfs public typealias FileAttributes = stat -/// Class for interacting with the file system. -/// -/// Only availible on Darwin (```open``` has been marked as unavailible). -public final class FileManager { +/// Type for interacting with the file system. +public struct FileManager { // MARK: - Determining Access to Files /// Determines whether a file descriptor exists at the specified path. Can be regular file, directory, socket, etc. public static func itemExists(at path: String) -> Bool { - return (stat(path, nil) == 0) + var inodeInfo = stat() + + guard stat(path, &inodeInfo) == 0 + else { return false } + + return true } /// Determines whether a file exists at the specified path. @@ -185,7 +187,11 @@ public final class FileManager { let fileSize = attributes.fileSize + #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + assert(fileSize <= SSIZE_MAX, "File size (\(fileSize)) is larger than the max number of bytes allowed (\(SSIZE_MAX))") + + #endif let memoryPointer = UnsafeMutablePointer(allocatingCapacity: fileSize) @@ -221,5 +227,4 @@ public final class FileManager { public let DefaultFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH -#endif diff --git a/Sources/SwiftFoundation/POSIXFileStatus.swift b/Sources/SwiftFoundation/POSIXFileStatus.swift index b992c22..ff5c697 100644 --- a/Sources/SwiftFoundation/POSIXFileStatus.swift +++ b/Sources/SwiftFoundation/POSIXFileStatus.swift @@ -13,8 +13,6 @@ import CStatfs #endif -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - public extension stat { // MARK: - Initialization @@ -33,6 +31,8 @@ public extension stat { // MARK: - Properties + #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + /// Date of last access. Date of ```st_atimespec``` or ```st_atime```. /// /// The field ```st_atime``` is changed by file accesses, for example, by ```execve```, ```mknod```, ```pipe```, ```utime```, and ```read``` (of more than zero bytes). @@ -70,6 +70,8 @@ public extension stat { set { st_birthtimespec = timespec(timeInterval: lastDataModificationDate.since1970) } } + #endif + var fileSize: Int { get { return Int(st_size) } @@ -123,5 +125,3 @@ public extension mode_t { } } } - -#endif diff --git a/Sources/SwiftFoundation/POSIXFileSystemStatus.swift b/Sources/SwiftFoundation/POSIXFileSystemStatus.swift index f277903..d6fc462 100644 --- a/Sources/SwiftFoundation/POSIXFileSystemStatus.swift +++ b/Sources/SwiftFoundation/POSIXFileSystemStatus.swift @@ -13,8 +13,6 @@ import CStatfs #endif -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - public extension statfs { // MARK: - Initialization @@ -31,5 +29,3 @@ public extension statfs { self = fileSystemStatus } } - -#endif From 3c1e1a4f7cb3e5039a400215fcc338d6e0e8a6cc Mon Sep 17 00:00:00 2001 From: yukiasai Date: Tue, 14 Jun 2016 15:48:01 +0000 Subject: [PATCH 43/68] update for Swift 3.0 swift-DEVELOPMENT-SNAPSHOT-2016-06-06 --- Sources/SwiftFoundation/JSONParse.swift | 6 +++--- Sources/SwiftFoundation/Thread.swift | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index 5a47e4d..5fa31f7 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -105,9 +105,9 @@ private extension JSON.Value { while entry != nil { - let keyPointer = entry.pointee.k + let keyPointer = entry!.pointee.k - let valuePointer = entry.pointee.v + let valuePointer = entry!.pointee.v let key = Swift.String.init(validatingUTF8: unsafeBitCast(keyPointer, to: UnsafeMutablePointer.self))! @@ -115,7 +115,7 @@ private extension JSON.Value { jsonDictionary[key] = JSON.Value(jsonObject: value) - entry = entry.pointee.next + entry = entry!.pointee.next } self = .Object(jsonDictionary) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 220c1d6..65daa42 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -25,7 +25,7 @@ public final class Thread { let holder = Unmanaged.passRetained(Closure(closure: closure)) - let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) + let pointer = UnsafeMutablePointer(holder.toOpaque()) #if os(Linux) var internalThread: pthread_t = 0 @@ -75,7 +75,7 @@ public final class Thread { private func ThreadPrivateMain(arg: UnsafeMutablePointer?) -> UnsafeMutablePointer? { - let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg!)) + let unmanaged = Unmanaged.fromOpaque(UnsafePointer(OpaquePointer(arg!))) unmanaged.takeUnretainedValue().closure() From 31fc9ececa4f55a22028d3e7f67597b627726c7d Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Tue, 14 Jun 2016 16:34:28 -0500 Subject: [PATCH 44/68] working on Xcode 8 support --- .../FoundationConvertible/HTTPClient.swift | 23 ++++++------ .../NSComparisonResult.swift | 4 +-- .../NSJSONSerialization.swift | 20 +++++------ Sources/FoundationConvertible/NSString.swift | 4 +-- .../FoundationConvertible/NSURLSession.swift | 16 ++++----- .../NSComparisonResultTests.swift | 4 +-- Sources/FoundationUnitTests/NSDateTests.swift | 18 +++++----- .../NSFileManagerTests.swift | 36 +++++++++---------- .../NSSortDescriptorTests.swift | 4 +-- Sources/FoundationUnitTests/NSUUIDTests.swift | 8 ++--- Sources/SwiftFoundation/JSONParse.swift | 6 ++-- Sources/SwiftFoundation/Thread.swift | 6 ++-- Sources/UnitTests/JSONTests.swift | 6 ++-- Sources/UnitTests/OrderTests.swift | 2 +- Sources/UnitTests/POSIXTimeTests.swift | 4 +-- Sources/UnitTests/UUIDTests.swift | 2 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 8 ++--- .../xcschemes/SwiftFoundation OS X.xcscheme | 2 +- .../SwiftFoundation WatchOS.xcscheme | 2 +- .../xcschemes/SwiftFoundation iOS.xcscheme | 2 +- 20 files changed, 86 insertions(+), 91 deletions(-) diff --git a/Sources/FoundationConvertible/HTTPClient.swift b/Sources/FoundationConvertible/HTTPClient.swift index f153027..9d8e428 100644 --- a/Sources/FoundationConvertible/HTTPClient.swift +++ b/Sources/FoundationConvertible/HTTPClient.swift @@ -16,55 +16,54 @@ public extension HTTP { /// Loads HTTP requests public final class Client: URLClient { - public init(session: NSURLSession = NSURLSession.shared()) { + public init(session: URLSession = URLSession.shared()) { self.session = session } /// The backing ```NSURLSession```. - public let session: NSURLSession + public let session: URLSession public func send(request: HTTP.Request) throws -> HTTP.Response { - var dataTask: NSURLSessionDataTask? + var dataTask: URLSessionDataTask? return try send(request: request, dataTask: &dataTask) } - public func send(request: HTTP.Request, dataTask: inout NSURLSessionDataTask?) throws -> HTTP.Response { + public func send(request: HTTP.Request, dataTask: inout URLSessionDataTask?) throws -> HTTP.Response { // build request... - guard let urlRequest = NSMutableURLRequest(request: request) + guard let urlRequest = Foundation.URLRequest(request: request) else { throw Error.BadRequest } // execute request - let semaphore = dispatch_semaphore_create(0)!; + let semaphore = DispatchSemaphore(value: 0); var error: NSError? var responseData: NSData? - var urlResponse: NSHTTPURLResponse? + var urlResponse: HTTPURLResponse? - dataTask = self.session.dataTask(with: urlRequest) { (data: NSData?, response: NSURLResponse?, responseError: NSError?) -> () in + dataTask = self.session.dataTask(with: urlRequest) { (data: Foundation.Data?, response: Foundation.URLResponse?, responseError: NSError?) -> () in responseData = data - urlResponse = response as? NSHTTPURLResponse + urlResponse = response as? Foundation.HTTPURLResponse error = responseError - dispatch_semaphore_signal(semaphore); - + semaphore.signal() } dataTask!.resume() // wait for task to finish - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); + let _ = semaphore.wait(timeout: DispatchTime.distantFuture); guard urlResponse != nil else { throw error! } diff --git a/Sources/FoundationConvertible/NSComparisonResult.swift b/Sources/FoundationConvertible/NSComparisonResult.swift index ba34358..9bd261d 100644 --- a/Sources/FoundationConvertible/NSComparisonResult.swift +++ b/Sources/FoundationConvertible/NSComparisonResult.swift @@ -14,7 +14,7 @@ import Foundation extension Order: FoundationConvertible { - public init(foundation: NSComparisonResult) { + public init(foundation: Foundation.ComparisonResult) { switch foundation { @@ -24,7 +24,7 @@ extension Order: FoundationConvertible { } } - public func toFoundation() -> NSComparisonResult { + public func toFoundation() -> Foundation.ComparisonResult { switch self { diff --git a/Sources/FoundationConvertible/NSJSONSerialization.swift b/Sources/FoundationConvertible/NSJSONSerialization.swift index 4d85401..7f1f615 100644 --- a/Sources/FoundationConvertible/NSJSONSerialization.swift +++ b/Sources/FoundationConvertible/NSJSONSerialization.swift @@ -10,7 +10,7 @@ import Foundation -public extension NSJSONSerialization { +public extension Foundation.JSONSerialization { public enum Value: RawRepresentable { @@ -44,7 +44,7 @@ public extension NSJSONSerialization { return } - if let rawArray = rawValue as? [AnyObject], let jsonArray: [NSJSONSerialization.Value] = NSJSONSerialization.Value.from(rawValues: rawArray) { + if let rawArray = rawValue as? [AnyObject], let jsonArray: [NSJSONSerialization.Value] = JSONSerialization.Value.from(rawValues: rawArray) { self = .Array(jsonArray) return @@ -58,7 +58,7 @@ public extension NSJSONSerialization { for (key, rawValue) in rawDictionary { - guard let jsonValue = NSJSONSerialization.Value(rawValue: rawValue) else { return nil } + guard let jsonValue = JSONSerialization.Value(rawValue: rawValue) else { return nil } jsonObject[key] = jsonValue } @@ -158,19 +158,19 @@ extension JSON.Value: FoundationConvertible { switch self { - case .Null: return NSJSONSerialization.Value.Null + case .Null: return JSONSerialization.Value.Null - case .String(let string): return NSJSONSerialization.Value.String(string as NSString) + case .String(let string): return JSONSerialization.Value.String(string as NSString) case .Number(let number): switch number { - case let .Integer(value): return NSJSONSerialization.Value.Number(NSNumber(value: value)) + case let .Integer(value): return JSONSerialization.Value.Number(NSNumber(value: value)) - case let .Double(value): return NSJSONSerialization.Value.Number(NSNumber(value: value)) + case let .Double(value): return JSONSerialization.Value.Number(NSNumber(value: value)) - case let .Boolean(value): return NSJSONSerialization.Value.Number(NSNumber(value: value)) + case let .Boolean(value): return JSONSerialization.Value.Number(NSNumber(value: value)) } case .Array(let array): @@ -215,8 +215,8 @@ extension NSNumber { var isBool:Bool { get { let objCType = String(validatingUTF8: self.objCType) - if (self.compare(trueNumber) == NSComparisonResult.orderedSame && objCType == trueObjCType) - || (self.compare(falseNumber) == NSComparisonResult.orderedSame && objCType == falseObjCType){ + if (self.compare(trueNumber) == Foundation.ComparisonResult.orderedSame && objCType == trueObjCType) + || (self.compare(falseNumber) == Foundation.ComparisonResult.orderedSame && objCType == falseObjCType){ return true } else { return false diff --git a/Sources/FoundationConvertible/NSString.swift b/Sources/FoundationConvertible/NSString.swift index 2c54272..adfc872 100644 --- a/Sources/FoundationConvertible/NSString.swift +++ b/Sources/FoundationConvertible/NSString.swift @@ -23,9 +23,9 @@ extension String: FoundationConvertible { let stringData = self.toUTF8Data() - guard let foundationString = NSString(bytes: stringData.byteValue, length: stringData.byteValue.count, encoding: NSUTF8StringEncoding) + guard let foundationString = NSString(bytes: stringData.byteValue, length: stringData.byteValue.count, encoding: String.Encoding.utf8.rawValue) else { fatalError("Could not convert String to NSString") } return foundationString } -} \ No newline at end of file +} diff --git a/Sources/FoundationConvertible/NSURLSession.swift b/Sources/FoundationConvertible/NSURLSession.swift index ec68718..914fc79 100644 --- a/Sources/FoundationConvertible/NSURLSession.swift +++ b/Sources/FoundationConvertible/NSURLSession.swift @@ -14,23 +14,19 @@ import Foundation -public extension NSMutableURLRequest { +public extension Foundation.URLRequest { - convenience init?(request: HTTP.Request) { - - self.init() - - guard request.version == HTTP.Version(1, 1) else { return nil } + init?(request: HTTP.Request) { guard let url = NSURL(string: request.URL) else { return nil } + + guard request.version == HTTP.Version(1, 1) else { return nil } - self.url = url - - self.timeoutInterval = request.timeoutInterval + self.init(url: url as Foundation.URL, timeoutInterval: request.timeoutInterval) if let data = request.body { - self.httpBody = data.toFoundation() + self.httpBody = data.toFoundation() as Foundation.Data } self.allHTTPHeaderFields = request.headers diff --git a/Sources/FoundationUnitTests/NSComparisonResultTests.swift b/Sources/FoundationUnitTests/NSComparisonResultTests.swift index 6bda9fa..e1cec26 100644 --- a/Sources/FoundationUnitTests/NSComparisonResultTests.swift +++ b/Sources/FoundationUnitTests/NSComparisonResultTests.swift @@ -44,7 +44,7 @@ class NSComparisonResultTests: XCTestCase { // dates - let now = Date() + let now = SwiftFoundation.Date() let later = now + 0.5 @@ -52,7 +52,7 @@ class NSComparisonResultTests: XCTestCase { let foundationLater = foundationNow.addingTimeInterval(0.5) - XCTAssert(now.compare(later) == Order(foundation: foundationNow.compare(foundationLater))) + XCTAssert(now.compare(later) == Order(foundation: foundationNow.compare(foundationLater as Foundation.Date))) XCTAssert(now < later) } diff --git a/Sources/FoundationUnitTests/NSDateTests.swift b/Sources/FoundationUnitTests/NSDateTests.swift index be9f364..cdd338e 100644 --- a/Sources/FoundationUnitTests/NSDateTests.swift +++ b/Sources/FoundationUnitTests/NSDateTests.swift @@ -12,9 +12,9 @@ import XCTest import Foundation import SwiftFoundation -class DateTests: XCTestCase { +final class DateTests: XCTestCase { - var date: Date! + var date: SwiftFoundation.Date! var foundationDate: NSDate! @@ -82,14 +82,14 @@ class DateTests: XCTestCase { let intervalSinceDate = date.timeIntervalSince(date: date2) - let foundationIntervalSinceDate = foundationDate.timeIntervalSince(foundationDate2) + let foundationIntervalSinceDate = foundationDate.timeIntervalSince(foundationDate2 as Foundation.Date) XCTAssert(intervalSinceDate == foundationIntervalSinceDate) } func testEquality() { - let date = Date() + let date = SwiftFoundation.Date() let date2 = Date(sinceReferenceDate: date.sinceReferenceDate) @@ -109,7 +109,7 @@ class DateTests: XCTestCase { func testGetTimeIntervalSince1970() { - let date = Date() + let date = SwiftFoundation.Date() let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.sinceReferenceDate) @@ -118,14 +118,14 @@ class DateTests: XCTestCase { func testCreateWithTimeIntervalSince1970() { - let date = Date() + let date = SwiftFoundation.Date() XCTAssert(Date(since1970: date.since1970) == date, "Date should be the same as original") } func testSetWithTimeIntervalSince1970() { - var date = Date() + var date = SwiftFoundation.Date() let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.sinceReferenceDate) @@ -157,7 +157,7 @@ class DateTests: XCTestCase { for _ in 0...1000000 { - _ = Date.init() + _ = SwiftFoundation.Date.init() } } } @@ -168,7 +168,7 @@ class DateTests: XCTestCase { for _ in 0...1000000 { - _ = NSDate.init() + _ = Foundation.Date() } } } diff --git a/Sources/FoundationUnitTests/NSFileManagerTests.swift b/Sources/FoundationUnitTests/NSFileManagerTests.swift index 1cd4343..eb57e52 100644 --- a/Sources/FoundationUnitTests/NSFileManagerTests.swift +++ b/Sources/FoundationUnitTests/NSFileManagerTests.swift @@ -26,16 +26,16 @@ class FileManagerTests: XCTestCase { func testGetCurrentDirectory() { - XCTAssert(FileManager.currentDirectory == NSFileManager.default().currentDirectoryPath) + XCTAssert(FileManager.currentDirectory == Foundation.FileManager.default().currentDirectoryPath) } func testFileExists() { - let fileName = "SwiftFoundationTestFileExists-\(UUID())" + let fileName = "SwiftFoundationTestFileExists-\(SwiftFoundation.UUID())" let path = NSTemporaryDirectory() + "/" + fileName - XCTAssert(NSFileManager.default().createFile(atPath: path, contents: NSData(), attributes: nil)) + XCTAssert(Foundation.FileManager.default().createFile(atPath: path, contents: Foundation.Data(), attributes: nil)) XCTAssert(FileManager.fileExists(at: path)) @@ -44,9 +44,9 @@ class FileManagerTests: XCTestCase { func testDirectoryExists() { - let path = try! NSFileManager.default().urlForDirectory( NSSearchPathDirectory.userDirectory, in: NSSearchPathDomainMask.allDomainsMask, appropriateFor: nil, create: false).path! + let path = try! Foundation.FileManager.default().urlForDirectory(.userDirectory, in: .allDomainsMask, appropriateFor: nil, create: false).path! - assert(NSFileManager.default().fileExists(atPath: path, isDirectory: nil), + assert(Foundation.FileManager.default().fileExists(atPath: path, isDirectory: nil), "Setting non existent directory as test parameter") XCTAssert(FileManager.directoryExists(at: path)) @@ -60,19 +60,19 @@ class FileManagerTests: XCTestCase { let bytes: [Byte] = "Test File: testReadFile 📱".utf8.map { (codeUnit) -> Byte in return codeUnit } - let data = Data(byteValue: bytes) + let data = SwiftFoundation.Data(byteValue: bytes) - let fileName = "SwiftFoundationTestReadFile-\(UUID())" + let fileName = "SwiftFoundationTestReadFile-\(SwiftFoundation.UUID())" let path = NSTemporaryDirectory() + "/" + fileName + ".txt" - XCTAssert(NSFileManager.default().createFile(atPath: path, contents: data.toFoundation(), attributes: nil)) + XCTAssert(Foundation.FileManager.default().createFile(atPath: path, contents: data.toFoundation() as Foundation.Data, attributes: nil)) // read file - var readData: Data + var readData: SwiftFoundation.Data - do { readData = try FileManager.contents(at: path) } + do { readData = try SwiftFoundation.FileManager.contents(at: path) } catch { XCTFail("\(error)"); return } @@ -87,21 +87,21 @@ class FileManagerTests: XCTestCase { let data = Data(byteValue: bytes) - let fileName = "SwiftFoundationTestWriteFile-\(UUID())" + let fileName = "SwiftFoundationTestWriteFile-\(SwiftFoundation.UUID())" let path = NSTemporaryDirectory() + fileName + ".txt" // create empty file - XCTAssert(NSFileManager.default().createFile(atPath: path, contents: NSData(), attributes: nil)) + XCTAssert(Foundation.FileManager.default().createFile(atPath: path, contents: Foundation.Data(), attributes: nil)) // write file - do { try FileManager.set(contents: data, at: path) } + do { try SwiftFoundation.FileManager.set(contents: data, at: path) } catch { XCTFail("\(error)"); return } // read file - var readData: Data + var readData: SwiftFoundation.Data do { readData = try FileManager.contents(at: path) } @@ -114,7 +114,7 @@ class FileManagerTests: XCTestCase { let data = "Test File: testCreateFile 📱".toUTF8Data() - let fileName = "SwiftFoundationTestCreateFile-\(UUID())" + let fileName = "SwiftFoundationTestCreateFile-\(SwiftFoundation.UUID())" let path = NSTemporaryDirectory() + fileName + ".txt" @@ -126,11 +126,11 @@ class FileManagerTests: XCTestCase { // read data - XCTAssert(NSFileManager.default().fileExists(atPath: path)) + XCTAssert(Foundation.FileManager.default().fileExists(atPath: path)) - NSFileManager.default() + Foundation.FileManager.default() - guard let readData = NSData(contentsOfFile: path) + guard let readData = try? Foundation.Data(contentsOf: Foundation.URL(string: path)!) else { XCTFail("Could not read data"); return } XCTAssert(data == Data(foundation: readData)) diff --git a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift index 34e221e..d3d799f 100644 --- a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift +++ b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift @@ -32,7 +32,7 @@ class NSSortDescriptorTests: XCTestCase { let sortedItems = items.sorted(ComparableSortDescriptor(ascending: ascending)) - let foundationSortedItems = (items as NSArray).sortedArray(using: [NSSortDescriptor(key: nil, ascending: ascending)]) + let foundationSortedItems = (items as NSArray).sortedArray(using: [SortDescriptor(key: nil, ascending: ascending)]) for (index, element) in sortedItems.enumerated() { @@ -69,7 +69,7 @@ class NSSortDescriptorTests: XCTestCase { return first.compare(second) })) - let foundationSortedItems = (items as NSArray).sortedArray(using: [NSSortDescriptor(key: nil, ascending: ascending)]) + let foundationSortedItems = (items as NSArray).sortedArray(using: [SortDescriptor(key: nil, ascending: ascending)]) for (index, element) in sortedItems.enumerated() { diff --git a/Sources/FoundationUnitTests/NSUUIDTests.swift b/Sources/FoundationUnitTests/NSUUIDTests.swift index e354159..a6045d9 100644 --- a/Sources/FoundationUnitTests/NSUUIDTests.swift +++ b/Sources/FoundationUnitTests/NSUUIDTests.swift @@ -32,7 +32,7 @@ class NSUUIDTests: XCTestCase { do { - _ = UUID() + let _ = SwiftFoundation.UUID() } } @@ -47,7 +47,7 @@ class NSUUIDTests: XCTestCase { func testUUIDValidBytes() { - let uuid = UUID() + let uuid = SwiftFoundation.UUID() let foundationUUID = NSUUID(byteValue: uuid.byteValue) @@ -71,7 +71,7 @@ class NSUUIDTests: XCTestCase { for _ in 0...1000000 { - _ = UUID() + _ = Foundation.UUID() } } } @@ -89,7 +89,7 @@ class NSUUIDTests: XCTestCase { func testStringPerformance() { - let uuid = UUID() + let uuid = SwiftFoundation.UUID() self.measure { diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index 5a47e4d..5fa31f7 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -105,9 +105,9 @@ private extension JSON.Value { while entry != nil { - let keyPointer = entry.pointee.k + let keyPointer = entry!.pointee.k - let valuePointer = entry.pointee.v + let valuePointer = entry!.pointee.v let key = Swift.String.init(validatingUTF8: unsafeBitCast(keyPointer, to: UnsafeMutablePointer.self))! @@ -115,7 +115,7 @@ private extension JSON.Value { jsonDictionary[key] = JSON.Value(jsonObject: value) - entry = entry.pointee.next + entry = entry!.pointee.next } self = .Object(jsonDictionary) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 220c1d6..0f8b71b 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -42,7 +42,7 @@ public final class Thread { self.internalThread = internalThread! #endif - pthread_detach(internalThread) + pthread_detach(internalThread!) } // MARK: - Class Methods @@ -73,9 +73,9 @@ public final class Thread { // MARK: - Private -private func ThreadPrivateMain(arg: UnsafeMutablePointer?) -> UnsafeMutablePointer? { +private func ThreadPrivateMain(arg: UnsafeMutablePointer) -> UnsafeMutablePointer? { - let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg!)) + let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) unmanaged.takeUnretainedValue().closure() diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 9bced20..5e34931 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -42,7 +42,7 @@ final class JSONTests: XCTestCase { // validate JSON string on Darwin do { - try NSJSONSerialization.jsonObject(with: jsonString.toUTF8Data().toFoundation(), options: NSJSONReadingOptions(rawValue: 0)) + try JSONSerialization.jsonObject(with: jsonString.toUTF8Data().toFoundation() as Foundation.Data, options: JSONSerialization.ReadingOptions(rawValue: 0)) } catch { XCTFail("Invalid JSON String"); return } @@ -88,9 +88,9 @@ final class JSONTests: XCTestCase { #if os(OSX) || os(iOS) - let foundationJSONOutput = try! NSJSONSerialization.data(withJSONObject: json.toFoundation().rawValue, options: NSJSONWritingOptions(rawValue: 0)) + let foundationJSONOutput = try! JSONSerialization.data(withJSONObject: json.toFoundation().rawValue, options: JSONSerialization.WritingOptions(rawValue: 0)) - let foundationJSONOutputString = NSString(data: foundationJSONOutput, encoding: NSUTF8StringEncoding)! + let foundationJSONOutputString = NSString(data: foundationJSONOutput, encoding: String.Encoding.utf8.rawValue)! XCTAssert(jsonString == foundationJSONOutputString as String, "Must match Foundation output. \(jsonString) == \(foundationJSONOutputString)") diff --git a/Sources/UnitTests/OrderTests.swift b/Sources/UnitTests/OrderTests.swift index 8c5cc71..ddaf881 100644 --- a/Sources/UnitTests/OrderTests.swift +++ b/Sources/UnitTests/OrderTests.swift @@ -33,7 +33,7 @@ final class OrderTests: XCTestCase { // dates - let now = Date() + let now = SwiftFoundation.Date() let later = now + 0.5 diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index 7860e0c..7c3f6fb 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -38,7 +38,7 @@ final class POSIXTimeTests: XCTestCase { func testTimeVal() { - let date = Date() + let date = SwiftFoundation.Date() let time = timeval(timeInterval: date.since1970) @@ -47,7 +47,7 @@ final class POSIXTimeTests: XCTestCase { func testTimeSpec() { - let date = Date() + let date = SwiftFoundation.Date() let time = timespec(timeInterval: date.since1970) diff --git a/Sources/UnitTests/UUIDTests.swift b/Sources/UnitTests/UUIDTests.swift index 583398f..1c57c09 100644 --- a/Sources/UnitTests/UUIDTests.swift +++ b/Sources/UnitTests/UUIDTests.swift @@ -23,7 +23,7 @@ final class UUIDTests: XCTestCase { func testCreateRandomUUID() { // try to create without crashing - let uuid = UUID() + let uuid = SwiftFoundation.UUID() print(uuid) } diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index d63b5f5..731e1bf 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -477,12 +477,12 @@ children = ( 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */, 6E2C2B0E1C20F6EB00B2C995 /* HTTPClient.swift */, + 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */, 6E2C2B0F1C20F6EB00B2C995 /* NSComparisonResult.swift */, 6E2C2B101C20F6EB00B2C995 /* NSData.swift */, 6E2C2B111C20F6EB00B2C995 /* NSDate.swift */, 6E2C2B121C20F6EB00B2C995 /* NSJSONSerialization.swift */, 6E2C2B131C20F6EB00B2C995 /* NSNull.swift */, - 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */, 6E2C2B151C20F6EB00B2C995 /* NSUUID.swift */, 6E2C2C311C212C2200B2C995 /* NSString.swift */, ); @@ -816,7 +816,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = PureSwift; TargetAttributes = { 6E30BA0C1B40F543009B1B49 = { @@ -1267,8 +1267,8 @@ 6E08F8551BBE7B8800548B1E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; COMBINE_HIDPI_IMAGES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SwiftFoundationTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.colemancda.SwiftFoundationTests; @@ -1280,8 +1280,8 @@ 6E08F8561BBE7B8800548B1E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; COMBINE_HIDPI_IMAGES = YES; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SwiftFoundationTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.colemancda.SwiftFoundationTests; diff --git a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme index 0b5edd9..bddaedb 100644 --- a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme +++ b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme @@ -1,6 +1,6 @@ Date: Thu, 30 Jun 2016 01:44:45 -0500 Subject: [PATCH 45/68] Implemented Data for #30 Also removed FoundationConvertible --- .../FoundationConvertible.swift | 21 -- .../FoundationConvertible/HTTPClient.swift | 97 -------- .../NSComparisonResult.swift | 36 --- Sources/FoundationConvertible/NSData.swift | 35 --- Sources/FoundationConvertible/NSDate.swift | 27 -- .../NSJSONSerialization.swift | 231 ----------------- Sources/FoundationConvertible/NSNull.swift | 20 -- Sources/FoundationConvertible/NSString.swift | 31 --- .../FoundationConvertible/NSURLSession.swift | 38 --- Sources/FoundationConvertible/NSUUID.swift | 76 ------ .../NSComparisonResultTests.swift | 61 ----- Sources/FoundationUnitTests/NSDateTests.swift | 177 ------------- .../NSFileManagerTests.swift | 147 ----------- .../NSSortDescriptorTests.swift | 102 -------- Sources/FoundationUnitTests/NSUUIDTests.swift | 118 --------- Sources/SwiftFoundation/Atomic.swift | 58 ----- Sources/SwiftFoundation/Base64.swift | 4 +- Sources/SwiftFoundation/BitMaskOption.swift | 4 +- Sources/SwiftFoundation/ByteValue.swift | 28 +++ Sources/SwiftFoundation/ByteValueType.swift | 20 -- .../ComparableSortDescriptor.swift | 23 -- .../ComparatorSortDescriptor.swift | 29 --- Sources/SwiftFoundation/Copying.swift | 30 --- Sources/SwiftFoundation/Data.swift | 235 +++++++++++++++--- Sources/SwiftFoundation/FileManager.swift | 4 +- Sources/SwiftFoundation/Hash.swift | 13 + Sources/SwiftFoundation/POSIXUUID.swift | 90 ------- .../SwiftFoundation/RawRepresentable.swift | 3 +- Sources/SwiftFoundation/String.swift | 6 +- Sources/SwiftFoundation/UUID.swift | 4 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 192 ++------------ 31 files changed, 273 insertions(+), 1687 deletions(-) delete mode 100644 Sources/FoundationConvertible/FoundationConvertible.swift delete mode 100644 Sources/FoundationConvertible/HTTPClient.swift delete mode 100644 Sources/FoundationConvertible/NSComparisonResult.swift delete mode 100644 Sources/FoundationConvertible/NSData.swift delete mode 100644 Sources/FoundationConvertible/NSDate.swift delete mode 100644 Sources/FoundationConvertible/NSJSONSerialization.swift delete mode 100644 Sources/FoundationConvertible/NSNull.swift delete mode 100644 Sources/FoundationConvertible/NSString.swift delete mode 100644 Sources/FoundationConvertible/NSURLSession.swift delete mode 100644 Sources/FoundationConvertible/NSUUID.swift delete mode 100644 Sources/FoundationUnitTests/NSComparisonResultTests.swift delete mode 100644 Sources/FoundationUnitTests/NSDateTests.swift delete mode 100644 Sources/FoundationUnitTests/NSFileManagerTests.swift delete mode 100644 Sources/FoundationUnitTests/NSSortDescriptorTests.swift delete mode 100644 Sources/FoundationUnitTests/NSUUIDTests.swift delete mode 100644 Sources/SwiftFoundation/Atomic.swift create mode 100644 Sources/SwiftFoundation/ByteValue.swift delete mode 100644 Sources/SwiftFoundation/ByteValueType.swift delete mode 100644 Sources/SwiftFoundation/ComparableSortDescriptor.swift delete mode 100644 Sources/SwiftFoundation/ComparatorSortDescriptor.swift delete mode 100644 Sources/SwiftFoundation/Copying.swift create mode 100644 Sources/SwiftFoundation/Hash.swift delete mode 100644 Sources/SwiftFoundation/POSIXUUID.swift diff --git a/Sources/FoundationConvertible/FoundationConvertible.swift b/Sources/FoundationConvertible/FoundationConvertible.swift deleted file mode 100644 index 7baa774..0000000 --- a/Sources/FoundationConvertible/FoundationConvertible.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// FoundationConvertible.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 8/22/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -import Foundation - -/// Type that can be converted to and from Apple's ***Foundation*** equivalent types. -public protocol FoundationConvertible { - - associatedtype FoundationType - - /// Initializes the type from Apple's **Foundation** equivalent type. - init(foundation: FoundationType) - - /// Converts the type to an equivalent type for use with Apple's **Foundation**. - func toFoundation() -> FoundationType -} diff --git a/Sources/FoundationConvertible/HTTPClient.swift b/Sources/FoundationConvertible/HTTPClient.swift deleted file mode 100644 index 9d8e428..0000000 --- a/Sources/FoundationConvertible/HTTPClient.swift +++ /dev/null @@ -1,97 +0,0 @@ -// -// HTTPClient.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 9/02/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import Foundation - -// Dot notation syntax for class -public extension HTTP { - - /// Loads HTTP requests - public final class Client: URLClient { - - public init(session: URLSession = URLSession.shared()) { - - self.session = session - } - - /// The backing ```NSURLSession```. - public let session: URLSession - - public func send(request: HTTP.Request) throws -> HTTP.Response { - - var dataTask: URLSessionDataTask? - - return try send(request: request, dataTask: &dataTask) - } - - public func send(request: HTTP.Request, dataTask: inout URLSessionDataTask?) throws -> HTTP.Response { - - // build request... - - guard let urlRequest = Foundation.URLRequest(request: request) - else { throw Error.BadRequest } - - // execute request - - let semaphore = DispatchSemaphore(value: 0); - - var error: NSError? - - var responseData: NSData? - - var urlResponse: HTTPURLResponse? - - dataTask = self.session.dataTask(with: urlRequest) { (data: Foundation.Data?, response: Foundation.URLResponse?, responseError: NSError?) -> () in - - responseData = data - - urlResponse = response as? Foundation.HTTPURLResponse - - error = responseError - - semaphore.signal() - } - - dataTask!.resume() - - // wait for task to finish - - let _ = semaphore.wait(timeout: DispatchTime.distantFuture); - - guard urlResponse != nil else { throw error! } - - var response = HTTP.Response() - - response.statusCode = urlResponse!.statusCode - - if let data = responseData where data.length > 0 { - - response.body = Data(foundation: data) - } - - response.headers = urlResponse!.allHeaderFields as! [String: String] - - return response - } - } -} - - -public extension HTTP.Client { - - public enum Error: ErrorProtocol { - - /// The provided request was malformed. - case BadRequest - } -} - -#endif - diff --git a/Sources/FoundationConvertible/NSComparisonResult.swift b/Sources/FoundationConvertible/NSComparisonResult.swift deleted file mode 100644 index 9bd261d..0000000 --- a/Sources/FoundationConvertible/NSComparisonResult.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Order.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/4/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(Linux) - import SwiftFoundation -#endif - -import Foundation - -extension Order: FoundationConvertible { - - public init(foundation: Foundation.ComparisonResult) { - - switch foundation { - - case .orderedAscending: self = .ascending - case .orderedDescending: self = .descending - case .orderedSame: self = .same - } - } - - public func toFoundation() -> Foundation.ComparisonResult { - - switch self { - - case .ascending: return .orderedAscending - case .descending: return .orderedDescending - case .same: return .orderedSame - } - } -} diff --git a/Sources/FoundationConvertible/NSData.swift b/Sources/FoundationConvertible/NSData.swift deleted file mode 100644 index 6297f24..0000000 --- a/Sources/FoundationConvertible/NSData.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// NSData.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/4/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - import Darwin.C -#elseif os(Linux) - import Glibc - import SwiftFoundation -#endif - -import Foundation - -extension Data: FoundationConvertible { - - public init(foundation: NSData) { - - let count = foundation.length / sizeof(UInt8) - - var bytesArray = [UInt8] (repeating: 0, count: count) - - foundation.getBytes(&bytesArray, length:count * sizeof(UInt8)) - - self.init(byteValue: bytesArray) - } - - public func toFoundation() -> NSData { - - return NSData(bytes: self.byteValue, length: self.byteValue.count) - } -} diff --git a/Sources/FoundationConvertible/NSDate.swift b/Sources/FoundationConvertible/NSDate.swift deleted file mode 100644 index 307a0de..0000000 --- a/Sources/FoundationConvertible/NSDate.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// Date.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/4/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(Linux) - import SwiftFoundation -#endif - -import Foundation - -extension Date: FoundationConvertible { - - public init(foundation: NSDate) { - - self.init(sinceReferenceDate: foundation.timeIntervalSinceReferenceDate) - } - - public func toFoundation() -> NSDate { - - return NSDate(timeIntervalSinceReferenceDate: sinceReferenceDate) - } -} - diff --git a/Sources/FoundationConvertible/NSJSONSerialization.swift b/Sources/FoundationConvertible/NSJSONSerialization.swift deleted file mode 100644 index 7f1f615..0000000 --- a/Sources/FoundationConvertible/NSJSONSerialization.swift +++ /dev/null @@ -1,231 +0,0 @@ -// -// NSJSONSerialization.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 8/22/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import Foundation - -public extension Foundation.JSONSerialization { - - public enum Value: RawRepresentable { - - case Null - - case String(NSString) - - case Number(NSNumber) - - case Array([NSJSONSerialization.Value]) - - case Dictionary([NSString: NSJSONSerialization.Value]) - - public init?(rawValue: AnyObject) { - - guard (rawValue as? NSNull) == nil else { - - self = .Null - return - } - - if let string = rawValue as? NSString { - - self = .String(string) - return - } - - if let number = rawValue as? NSNumber { - - self = .Number(number) - return - } - - if let rawArray = rawValue as? [AnyObject], let jsonArray: [NSJSONSerialization.Value] = JSONSerialization.Value.from(rawValues: rawArray) { - - self = .Array(jsonArray) - return - } - - if let rawDictionary = rawValue as? [NSString: AnyObject] { - - typealias FoundationValue = NSJSONSerialization.Value - - var jsonObject = [NSString: FoundationValue](minimumCapacity: rawDictionary.count) - - for (key, rawValue) in rawDictionary { - - guard let jsonValue = JSONSerialization.Value(rawValue: rawValue) else { return nil } - - jsonObject[key] = jsonValue - } - - self = .Dictionary(jsonObject) - return - } - - return nil - } - - public var rawValue: AnyObject { - - switch self { - - case .Null: return NSNull() - - case .String(let string): return string - - case .Number(let number): return number - - case .Array(let array): return array.rawValues as NSArray - - case .Dictionary(let dictionary): - - var dictionaryValue = [NSString: AnyObject](minimumCapacity: dictionary.count) - - for (key, value) in dictionary { - - dictionaryValue[key] = value.rawValue - } - - return dictionaryValue as NSDictionary - } - - } - } -} - -extension JSON.Value: FoundationConvertible { - - public init(foundation: NSJSONSerialization.Value) { - - switch foundation { - - case .Null: self = .Null - - case .String(let value): self = JSON.Value.String(value as Swift.String) - - case .Number(let value): - - if value.isBool { - - self = JSON.Value.Number(JSON.Number.Boolean(value as Bool)) - } - - else if Swift.String(validatingUTF8: value.objCType)! == intObjCType { - - self = JSON.Value.Number(.Integer(Int(value))) - } - else { - - self = JSON.Value.Number(.Double(Double(value))) - } - - case .Array(let foundationArray): - - var jsonArray = JSONArray() - - for foundationValue in foundationArray { - - let jsonValue = JSON.Value(foundation: foundationValue) - - jsonArray.append(jsonValue) - } - - self = .Array(jsonArray) - - case .Dictionary(let foundationDictionary): - - var jsonObject = JSONObject() - - for (key, foundationValue) in foundationDictionary { - - let jsonValue = JSON.Value(foundation: foundationValue) - - jsonObject[key as Swift.String] = jsonValue - } - - self = .Object(jsonObject) - } - } - - public func toFoundation() -> NSJSONSerialization.Value { - - typealias FoundationValue = NSJSONSerialization.Value - - switch self { - - case .Null: return JSONSerialization.Value.Null - - case .String(let string): return JSONSerialization.Value.String(string as NSString) - - case .Number(let number): - - switch number { - - case let .Integer(value): return JSONSerialization.Value.Number(NSNumber(value: value)) - - case let .Double(value): return JSONSerialization.Value.Number(NSNumber(value: value)) - - case let .Boolean(value): return JSONSerialization.Value.Number(NSNumber(value: value)) - } - - case .Array(let array): - - var foundationArray = [FoundationValue]() - - for jsonValue in array { - - let foundationValue = jsonValue.toFoundation() - - foundationArray.append(foundationValue) - } - - return .Array(foundationArray) - - case .Object(let dictionary): - - var foundationDictionary = [NSString: FoundationValue](minimumCapacity: dictionary.count) - - for (key, value) in dictionary { - - let foundationValue = value.toFoundation() - - foundationDictionary[key as NSString] = foundationValue - } - - return .Dictionary(foundationDictionary) - } - } -} - -private let trueNumber: NSNumber = true -private let falseNumber: NSNumber = false -private let trueObjCType = String(validatingUTF8: trueNumber.objCType) -private let falseObjCType = String(validatingUTF8: falseNumber.objCType) - -private let intNumber: NSNumber = NSNumber(value: Int(1)) -private let intObjCType = String(validatingUTF8: intNumber.objCType)! - - -extension NSNumber { - var isBool:Bool { - get { - let objCType = String(validatingUTF8: self.objCType) - if (self.compare(trueNumber) == Foundation.ComparisonResult.orderedSame && objCType == trueObjCType) - || (self.compare(falseNumber) == Foundation.ComparisonResult.orderedSame && objCType == falseObjCType){ - return true - } else { - return false - } - } - } -} - -#endif - - - diff --git a/Sources/FoundationConvertible/NSNull.swift b/Sources/FoundationConvertible/NSNull.swift deleted file mode 100644 index c9a50de..0000000 --- a/Sources/FoundationConvertible/NSNull.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// NSNull.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 8/22/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(Linux) - import SwiftFoundation -#endif - -import Foundation - -extension SwiftFoundation.Null: FoundationConvertible { - - public init(foundation: NSNull) { self.init() } - - public func toFoundation() -> NSNull { return NSNull() } -} diff --git a/Sources/FoundationConvertible/NSString.swift b/Sources/FoundationConvertible/NSString.swift deleted file mode 100644 index adfc872..0000000 --- a/Sources/FoundationConvertible/NSString.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// NSString.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 12/16/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(Linux) - import SwiftFoundation -#endif - -import Foundation - -extension String: FoundationConvertible { - - public init(foundation: NSString) { - - self.init("\(foundation)") - } - - public func toFoundation() -> NSString { - - let stringData = self.toUTF8Data() - - guard let foundationString = NSString(bytes: stringData.byteValue, length: stringData.byteValue.count, encoding: String.Encoding.utf8.rawValue) - else { fatalError("Could not convert String to NSString") } - - return foundationString - } -} diff --git a/Sources/FoundationConvertible/NSURLSession.swift b/Sources/FoundationConvertible/NSURLSession.swift deleted file mode 100644 index 914fc79..0000000 --- a/Sources/FoundationConvertible/NSURLSession.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// NSURLSession.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 10/2/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(Linux) - import SwiftFoundation -#endif - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import Foundation - -public extension Foundation.URLRequest { - - init?(request: HTTP.Request) { - - guard let url = NSURL(string: request.URL) else { return nil } - - guard request.version == HTTP.Version(1, 1) else { return nil } - - self.init(url: url as Foundation.URL, timeoutInterval: request.timeoutInterval) - - if let data = request.body { - - self.httpBody = data.toFoundation() as Foundation.Data - } - - self.allHTTPHeaderFields = request.headers - - self.httpMethod = request.method.rawValue - } -} - -#endif diff --git a/Sources/FoundationConvertible/NSUUID.swift b/Sources/FoundationConvertible/NSUUID.swift deleted file mode 100644 index a67867b..0000000 --- a/Sources/FoundationConvertible/NSUUID.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// NSUUID.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/4/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - import Darwin.C -#elseif os(Linux) - import Glibc - import SwiftFoundation - import CUUID -#endif - -import Foundation - -extension UUID: FoundationConvertible { - - public init(foundation: NSUUID) { - - self.init(byteValue: foundation.byteValue) - } - - public func toFoundation() -> NSUUID { - - return NSUUID(byteValue: byteValue) - } -} - -public extension NSUUID { - - convenience init(byteValue: uuid_t) { - - var value = byteValue - - let buffer = withUnsafeMutablePointer(&value, { (valuePointer: UnsafeMutablePointer) -> UnsafeMutablePointer in - - let bufferType = UnsafeMutablePointer.self - - return unsafeBitCast(valuePointer, to: bufferType) - }) - - self.init(uuidBytes: buffer) - } - - var byteValue: uuid_t { - - var uuid = uuid_t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) - - withUnsafeMutablePointer(&uuid, { (valuePointer: UnsafeMutablePointer) -> Void in - - let bufferType = UnsafeMutablePointer.self - - let buffer = unsafeBitCast(valuePointer, to: bufferType) - - self.getBytes(buffer) - }) - - return uuid - } - - var rawValue: String { - - return uuidString - } - - convenience init?(rawValue: String) { - - self.init(uuidString: rawValue) - } -} - - - diff --git a/Sources/FoundationUnitTests/NSComparisonResultTests.swift b/Sources/FoundationUnitTests/NSComparisonResultTests.swift deleted file mode 100644 index e1cec26..0000000 --- a/Sources/FoundationUnitTests/NSComparisonResultTests.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// NSComparisonResultTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import XCTest -import Foundation -import SwiftFoundation - -class NSComparisonResultTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testComparisonResult() { - - // number - - XCTAssert((1 as Int).compare(2) == Order(foundation: 1.compare(NSNumber(value: 2)))) - - XCTAssert((2 as Int).compare(1) == Order(foundation: 2.compare(NSNumber(value: 1)))) - - XCTAssert((1 as Int).compare(1) == Order(foundation: 1.compare(NSNumber(value: 1)))) - - // string - - XCTAssert("a".compare("b") == Order(foundation: ("a" as NSString).compare("b" as String))) - - XCTAssert("b".compare("a") == Order(foundation: ("b" as NSString).compare("a" as String))) - - XCTAssert("a".compare("a") == Order(foundation: ("a" as NSString).compare("a" as String))) - - // dates - - let now = SwiftFoundation.Date() - - let later = now + 0.5 - - let foundationNow = NSDate() - - let foundationLater = foundationNow.addingTimeInterval(0.5) - - XCTAssert(now.compare(later) == Order(foundation: foundationNow.compare(foundationLater as Foundation.Date))) - - XCTAssert(now < later) - } -} - -#endif diff --git a/Sources/FoundationUnitTests/NSDateTests.swift b/Sources/FoundationUnitTests/NSDateTests.swift deleted file mode 100644 index cdd338e..0000000 --- a/Sources/FoundationUnitTests/NSDateTests.swift +++ /dev/null @@ -1,177 +0,0 @@ -// -// DateTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import XCTest -import Foundation -import SwiftFoundation - -final class DateTests: XCTestCase { - - var date: SwiftFoundation.Date! - - var foundationDate: NSDate! - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - - let timeIntervalSinceReferenceDate = NSDate.timeIntervalSinceReferenceDate() - - date = Date(sinceReferenceDate: timeIntervalSinceReferenceDate) - - foundationDate = NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - - date = nil - - foundationDate = nil - } - - // MARK: - Functional Tests - - func testFoundationDateEquality() { - - let timeIntervalSinceReferenceDate = NSDate.timeIntervalSinceReferenceDate() - - let date = Date(sinceReferenceDate: timeIntervalSinceReferenceDate) - - let FoundationDate = NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) - - XCTAssert(date.sinceReferenceDate == FoundationDate.timeIntervalSinceReferenceDate, - "Date's internal values must be equal. (\(date.sinceReferenceDate) != \(FoundationDate.timeIntervalSinceReferenceDate))") - } - - func testTimeIntervalSinceReferenceDateSecondsPrecision() { - - let interval = UInt(TimeIntervalSinceReferenceDate()) - - let NSInterval = UInt(NSDate.timeIntervalSinceReferenceDate()) - - XCTAssert(interval == NSInterval, "\(interval) must equal \(NSInterval)") - } - - /* - func testTimeIntervalSinceReferenceDateMicroSecondsPrecision() { - - let interval = TimeIntervalSinceReferenceDate() - - let NSInterval = NSDate.timeIntervalSinceReferenceDate() - - XCTAssert(interval <= NSInterval, "\(interval) must lower than or equal \(NSInterval)") - } - */ - - func testTimeIntervalSinceDate() { - - let time2 = NSDate.timeIntervalSinceReferenceDate() - - let date2 = Date(sinceReferenceDate: time2) - - let foundationDate2 = NSDate(timeIntervalSinceReferenceDate: time2) - - let intervalSinceDate = date.timeIntervalSince(date: date2) - - let foundationIntervalSinceDate = foundationDate.timeIntervalSince(foundationDate2 as Foundation.Date) - - XCTAssert(intervalSinceDate == foundationIntervalSinceDate) - } - - func testEquality() { - - let date = SwiftFoundation.Date() - - let date2 = Date(sinceReferenceDate: date.sinceReferenceDate) - - let foundationDate = NSDate() - - let foundationDate2 = NSDate(timeIntervalSinceReferenceDate: foundationDate.timeIntervalSinceReferenceDate) - - XCTAssert(date == date2) - - XCTAssert(foundationDate == foundationDate2) - } - - func testTimeIntervalSince1970Constant() { - - XCTAssert(TimeIntervalBetween1970AndReferenceDate == NSTimeIntervalSince1970, "NSTimeIntervalSince1970 == \(NSTimeIntervalSince1970)") - } - - func testGetTimeIntervalSince1970() { - - let date = SwiftFoundation.Date() - - let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.sinceReferenceDate) - - XCTAssert(date.since1970 == foundationDate.timeIntervalSince1970) - } - - func testCreateWithTimeIntervalSince1970() { - - let date = SwiftFoundation.Date() - - XCTAssert(Date(since1970: date.since1970) == date, "Date should be the same as original") - } - - func testSetWithTimeIntervalSince1970() { - - var date = SwiftFoundation.Date() - - let foundationDate = NSDate(timeIntervalSinceReferenceDate: date.sinceReferenceDate) - - date.since1970 = foundationDate.timeIntervalSince1970 - - XCTAssert(date.sinceReferenceDate == foundationDate.timeIntervalSinceReferenceDate) - } - - /* - func testDescription() { - - let date = Date() - - let foundationFormatter = NSDateFormatter() - - foundationFormatter.dateFormat = "YYYY-MM-dd hh:mm:ss"; - - let foundationDescription = foundationFormatter.stringFromDate(NSDate(date: date)) - - XCTAssert(date.description == foundationDescription, "\(date.description) == \(foundationDescription)") - } - */ - - // MARK: - Performance Tests - - func testCreationPerformance() { - - self.measure { - - for _ in 0...1000000 { - - _ = SwiftFoundation.Date.init() - } - } - } - - func testFoundationCreationPerformance() { - - self.measure { - - for _ in 0...1000000 { - - _ = Foundation.Date() - } - } - } -} - -#endif diff --git a/Sources/FoundationUnitTests/NSFileManagerTests.swift b/Sources/FoundationUnitTests/NSFileManagerTests.swift deleted file mode 100644 index eb57e52..0000000 --- a/Sources/FoundationUnitTests/NSFileManagerTests.swift +++ /dev/null @@ -1,147 +0,0 @@ -// -// FileManagerTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/19/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import XCTest -import Foundation -import SwiftFoundation - -class FileManagerTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testGetCurrentDirectory() { - - XCTAssert(FileManager.currentDirectory == Foundation.FileManager.default().currentDirectoryPath) - } - - func testFileExists() { - - let fileName = "SwiftFoundationTestFileExists-\(SwiftFoundation.UUID())" - - let path = NSTemporaryDirectory() + "/" + fileName - - XCTAssert(Foundation.FileManager.default().createFile(atPath: path, contents: Foundation.Data(), attributes: nil)) - - XCTAssert(FileManager.fileExists(at: path)) - - XCTAssert(!FileManager.directoryExists(at: path)) - } - - func testDirectoryExists() { - - let path = try! Foundation.FileManager.default().urlForDirectory(.userDirectory, in: .allDomainsMask, appropriateFor: nil, create: false).path! - - assert(Foundation.FileManager.default().fileExists(atPath: path, isDirectory: nil), - "Setting non existent directory as test parameter") - - XCTAssert(FileManager.directoryExists(at: path)) - - XCTAssert(!FileManager.fileExists(at: path)) - } - - func testReadFile() { - - // create file - - let bytes: [Byte] = "Test File: testReadFile 📱".utf8.map { (codeUnit) -> Byte in return codeUnit } - - let data = SwiftFoundation.Data(byteValue: bytes) - - let fileName = "SwiftFoundationTestReadFile-\(SwiftFoundation.UUID())" - - let path = NSTemporaryDirectory() + "/" + fileName + ".txt" - - XCTAssert(Foundation.FileManager.default().createFile(atPath: path, contents: data.toFoundation() as Foundation.Data, attributes: nil)) - - // read file - - var readData: SwiftFoundation.Data - - do { readData = try SwiftFoundation.FileManager.contents(at: path) } - - catch { XCTFail("\(error)"); return } - - XCTAssert(data == readData) - } - - func testWriteFile() { - - // create file - - let bytes: [Byte] = "Test File: testWriteFile 📱".utf8.map { (codeUnit) -> Byte in return codeUnit } - - let data = Data(byteValue: bytes) - - let fileName = "SwiftFoundationTestWriteFile-\(SwiftFoundation.UUID())" - - let path = NSTemporaryDirectory() + fileName + ".txt" - - // create empty file - XCTAssert(Foundation.FileManager.default().createFile(atPath: path, contents: Foundation.Data(), attributes: nil)) - - // write file - do { try SwiftFoundation.FileManager.set(contents: data, at: path) } - - catch { XCTFail("\(error)"); return } - - // read file - - var readData: SwiftFoundation.Data - - do { readData = try FileManager.contents(at: path) } - - catch { XCTFail("\(error)"); return } - - XCTAssert(data == readData) - } - - func testCreateFile() { - - let data = "Test File: testCreateFile 📱".toUTF8Data() - - let fileName = "SwiftFoundationTestCreateFile-\(SwiftFoundation.UUID())" - - let path = NSTemporaryDirectory() + fileName + ".txt" - - // create file - - do { try FileManager.createFile(at: path, contents: data) } - - catch { XCTFail("\(error)"); return } - - // read data - - XCTAssert(Foundation.FileManager.default().fileExists(atPath: path)) - - Foundation.FileManager.default() - - guard let readData = try? Foundation.Data(contentsOf: Foundation.URL(string: path)!) - else { XCTFail("Could not read data"); return } - - XCTAssert(data == Data(foundation: readData)) - } -} - -#endif - -#if os(OSX) || os(iOS) - public let TemporaryDirectory = NSTemporaryDirectory() -#elseif os(Linux) - public let TemporaryDirectory = "/tmp/" -#endif - diff --git a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift b/Sources/FoundationUnitTests/NSSortDescriptorTests.swift deleted file mode 100644 index d3d799f..0000000 --- a/Sources/FoundationUnitTests/NSSortDescriptorTests.swift +++ /dev/null @@ -1,102 +0,0 @@ -// -// SortDescriptorTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import XCTest -import Foundation -import SwiftFoundation - -class NSSortDescriptorTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - // MARK: - Functional Tests - - func testComparableSorting() { - - func verifySort(_ items: [String], ascending: Bool = true) { - - let sortedItems = items.sorted(ComparableSortDescriptor(ascending: ascending)) - - let foundationSortedItems = (items as NSArray).sortedArray(using: [SortDescriptor(key: nil, ascending: ascending)]) - - for (index, element) in sortedItems.enumerated() { - - let foundationElement = foundationSortedItems[index] - - if foundationElement as! String != element { - - XCTFail("Elements to not match Swift: \(sortedItems) Foundation: \(foundationSortedItems)\n") - - return - } - } - } - - let names = ["coleman", "Coleman", "alsey", "miller", "Z", "A"] - - verifySort(names) - - verifySort(names, ascending: false) - - let places = ["Lima, Peru", "Brazil", "Florida", "San Diego", "Hong Kong"] - - verifySort(places) - - verifySort(places, ascending: false) - } - - func testComparatorSorting() { - - func verifySort(_ items: [String], ascending: Bool = true) { - - let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: ascending, comparator: { (first: String, second: String) -> Order in - - return first.compare(second) - })) - - let foundationSortedItems = (items as NSArray).sortedArray(using: [SortDescriptor(key: nil, ascending: ascending)]) - - for (index, element) in sortedItems.enumerated() { - - let foundationElement = foundationSortedItems[index] - - if foundationElement as! String != element { - - XCTFail("Elements to not match\nSwift:\n\(sortedItems)\nFoundation:\n\(foundationSortedItems)\n") - - return - } - } - } - - let names = ["coleman", "Coleman", "alsey", "miller", "Z", "A"] - - verifySort(names) - - verifySort(names, ascending: false) - - let places = ["Lima, Peru", "Brazil", "Florida", "San Diego", "Hong Kong"] - - verifySort(places) - - verifySort(places, ascending: false) - } -} - -#endif - diff --git a/Sources/FoundationUnitTests/NSUUIDTests.swift b/Sources/FoundationUnitTests/NSUUIDTests.swift deleted file mode 100644 index a6045d9..0000000 --- a/Sources/FoundationUnitTests/NSUUIDTests.swift +++ /dev/null @@ -1,118 +0,0 @@ -// -// UUIDTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/2/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - -import XCTest -import Foundation -import SwiftFoundation - -class NSUUIDTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - // MARK: - Functional Tests - - func testCreateRandomUUID() { - - // try to create without crashing - - do { - - let _ = SwiftFoundation.UUID() - } - } - - func testUUIDString() { - - let foundationUUID = NSUUID() - - let uuid = UUID(byteValue: foundationUUID.byteValue) - - XCTAssert(foundationUUID.uuidString == uuid.rawValue) - } - - func testUUIDValidBytes() { - - let uuid = SwiftFoundation.UUID() - - let foundationUUID = NSUUID(byteValue: uuid.byteValue) - - XCTAssert(uuid.rawValue == foundationUUID.uuidString) - } - - func testCreateFromString() { - - let stringValue = NSUUID().uuidString - - XCTAssert((UUID(rawValue: stringValue) != nil), "Could not create UUID with string \"\(stringValue)\"") - - XCTAssert((UUID(rawValue: "BadInput") == nil), "UUID should not be created") - } - - // MARK: - Performance Tests - - func testCreationPerformance() { - - self.measure { - - for _ in 0...1000000 { - - _ = Foundation.UUID() - } - } - } - - func testFoundationCreationPerformance() { - - self.measure { - - for _ in 0...1000000 { - - _ = NSUUID() - } - } - } - - func testStringPerformance() { - - let uuid = SwiftFoundation.UUID() - - self.measure { - - for _ in 0...10000 { - - _ = uuid.rawValue - } - } - } - - func testFoundationStringPerformance() { - - let uuid = NSUUID() - - self.measure { - - for _ in 0...10000 { - - _ = uuid.uuidString - } - } - } -} - -#endif - diff --git a/Sources/SwiftFoundation/Atomic.swift b/Sources/SwiftFoundation/Atomic.swift deleted file mode 100644 index 68a0020..0000000 --- a/Sources/SwiftFoundation/Atomic.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// Atomic.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 4/10/16. -// Copyright © 2016 PureSwift. All rights reserved. -// - -/// Encapsulates atomic values that are thread-safe. -public struct Atomic { - - // MARK: - Properties - - public var value: Value { - - get { - - let value: Value - - lock.lock() - value = internalValue - lock.unlock() - - return value - } - - mutating set { - - ensureUnique() - - lock.lock() - internalValue = newValue - lock.unlock() - } - } - - // MARK: - Private Properties - - private var internalValue: Value - - private var lock = Lock() - - // MARK: - Initialization - - public init(_ value: Value) { - - self.internalValue = value - } - - // MARK: - Private Methods - - private mutating func ensureUnique() { - - if !isUniquelyReferencedNonObjC(&lock) { - lock = Lock() - } - } -} diff --git a/Sources/SwiftFoundation/Base64.swift b/Sources/SwiftFoundation/Base64.swift index 3ed654d..1032ed8 100644 --- a/Sources/SwiftFoundation/Base64.swift +++ b/Sources/SwiftFoundation/Base64.swift @@ -24,7 +24,7 @@ public struct Base64 { */ public static func encode(data: Data, alphabet: Alphabet = .Standard) -> Data { - let bytes = data.byteValue + let bytes = data.bytes var encoded : [UInt8] = [] @@ -78,7 +78,7 @@ public struct Base64 { assert(i == count) } - return Data(byteValue: encoded) + return Data(bytes: encoded) } } diff --git a/Sources/SwiftFoundation/BitMaskOption.swift b/Sources/SwiftFoundation/BitMaskOption.swift index 1b742ef..2a24953 100644 --- a/Sources/SwiftFoundation/BitMaskOption.swift +++ b/Sources/SwiftFoundation/BitMaskOption.swift @@ -6,7 +6,7 @@ // Copyright © 2015 PureSwift. All rights reserved. // -/// Bit mask that represents various options +/// Bit mask that represents various options. public protocol BitMaskOption: RawRepresentable { static func bitmask(options: [Self]) -> Self.RawValue @@ -29,4 +29,4 @@ public extension Sequence where Self.Iterator.Element: BitMaskOption, Self.Itera return Self.Iterator.Element.bitmask(options: array) } -} \ No newline at end of file +} diff --git a/Sources/SwiftFoundation/ByteValue.swift b/Sources/SwiftFoundation/ByteValue.swift new file mode 100644 index 0000000..4e9e275 --- /dev/null +++ b/Sources/SwiftFoundation/ByteValue.swift @@ -0,0 +1,28 @@ +// +// ByteValueType.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 7/3/15. +// Copyright © 2015 PureSwift. All rights reserved. +// + +/// Stores a primitive value. +/// +/// Useful for Swift wrappers for primitive byte types. +public protocol ByteValue: Equatable { + + associatedtype ByteValue + + /// Returns the the primitive byte type. + var bytes: ByteValue { get } + + /// Initializes with the primitive the primitive byte type. + init(bytes: ByteValue) +} + +// MARK: - Equatable + +public func == (lhs: T, rhs: T) -> Bool { + + return lhs.bytes == rhs.bytes +} diff --git a/Sources/SwiftFoundation/ByteValueType.swift b/Sources/SwiftFoundation/ByteValueType.swift deleted file mode 100644 index 40be2c1..0000000 --- a/Sources/SwiftFoundation/ByteValueType.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// ByteValueType.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Stores a primitive value. -/// -/// Useful for Swift wrappers for C primitives. -public protocol ByteValueType { - - associatedtype ByteValue - - /// Returns the primitive type. - var byteValue: ByteValue { get } - - init(byteValue: ByteValue) -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/ComparableSortDescriptor.swift b/Sources/SwiftFoundation/ComparableSortDescriptor.swift deleted file mode 100644 index 4c1d608..0000000 --- a/Sources/SwiftFoundation/ComparableSortDescriptor.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// ComparableSortDescriptor.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/** Sorts ```Comparable``` types. */ -public struct ComparableSortDescriptor: SortDescriptor { - - public var ascending: Bool - - public func sort(first: T, second: T) -> Order { - - return first.compare(second) - } - - public init(ascending: Bool) { - - self.ascending = ascending - } -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/ComparatorSortDescriptor.swift b/Sources/SwiftFoundation/ComparatorSortDescriptor.swift deleted file mode 100644 index 24d7993..0000000 --- a/Sources/SwiftFoundation/ComparatorSortDescriptor.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// ComparatorSortDescriptor.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/** Sorts according to a given closure. */ -public struct ComparatorSortDescriptor: SortDescriptor { - - public typealias Comparator = (T, T) -> Order - - public var ascending: Bool - - /** The closure that will be used for sorting. */ - public var comparator: Comparator - - public func sort(first: T, second: T) -> Order { - - return self.comparator(first, second) - } - - public init(ascending: Bool, comparator: Comparator) { - - self.ascending = ascending - self.comparator = comparator - } -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/Copying.swift b/Sources/SwiftFoundation/Copying.swift deleted file mode 100644 index fd89950..0000000 --- a/Sources/SwiftFoundation/Copying.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copying.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/17/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Protocol for classes that can create equivalent duplicates of themselves. -/// -/// Duplicate is implied to be of the same mutablility as the reciever. -/// The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class. -/// -/// **Use Case:** Classes that incapsuate information that need to be passed by reference (can't be structs), but need copying for thread safety, immutablility etc. -public protocol Copying: class { - - /// Creates a copy of the reciever. - var copy: Self { get } -} - -/// Protocol for classes that have mutable and immutable types. -/// -/// Only classes that define an “immutable vs. mutable” distinction should adopt this protocol. Classes that don’t define such a distinction should adopt ```Copying``` instead. -public protocol MutableCopying: class, Copying { - - associatedtype MutableType - - /// Creates a mutable copy of the reciever. - var mutableCopy: MutableType { get } -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/Data.swift b/Sources/SwiftFoundation/Data.swift index 88faa82..769b704 100644 --- a/Sources/SwiftFoundation/Data.swift +++ b/Sources/SwiftFoundation/Data.swift @@ -12,50 +12,224 @@ import Glibc #endif -/// Encapsulates data. -public struct Data: ByteValueType, Equatable { - - public var byteValue: [Byte] +// MARK: - Linux + +#if os(Linux) || XcodeLinux - public init(byteValue: [Byte] = []) { + /// Encapsulates data. + public struct Data: ByteValue, Equatable, Hashable, CustomStringConvertible, RandomAccessCollection, MutableCollection { + + public typealias Index = Int + public typealias Indices = DefaultRandomAccessIndices + + // MARK: - Properties + + public var bytes: [Byte] + + // MARK: - Initialization + + /// Initialize a `Data` with the contents of an Array. + /// + /// - parameter bytes: An array of bytes to copy. + @inline(__always) + public init(bytes: [Byte] = []) { + + self.bytes = bytes + } + + /// Initialize a `Data` with the contents of an Array. + /// + /// - parameter bytes: An array of bytes to copy. + @inline(__always) + public init(bytes: ArraySlice) { + + self.bytes = Array(bytes) + } + + /// Initialize a `Data` with the specified size. + /// + /// - parameter capacity: The size of the data. + @inline(__always) + public init?(count: Int) { + + // Never fails on Linux + self.bytes = Array(repeating: 0, count: count) + } + + /// Initialize a `Data` with copied memory content. + /// + /// - parameter bytes: A pointer to the memory. It will be copied. + /// - parameter count: The number of bytes to copy. + @inline(__always) + public init(bytes pointer: UnsafePointer, count: Int) { + + self.bytes = [UInt8](repeating: 0, count: count) + + memcpy(&bytes, pointer, count) + } + + /// Initialize a `Data` with copied memory content. + /// + /// - parameter buffer: A buffer pointer to copy. The size is calculated from `SourceType` and `buffer.count`. + public init(buffer: UnsafeBufferPointer) { + + guard let pointer = buffer.baseAddress + else { self.init(); return } + + self.init(bytes: pointer, count: sizeof(SourceType) * buffer.count) + } + + // MARK: - Accessors + + public var hashValue: Int { + + /// Only hash first 80 bytes + let hashBytes = bytes.prefix(80) + + return Hash(Data(bytes: hashBytes)) + } + + public var description: String { + + let hexString = bytes.map({ $0.toHexadecimal() }).reduce("", combine: { $0.0 + $0.1 }) + + return "<" + hexString + ">" + } + + // MARK: - Methods + + /// Append data to the data. + /// + /// - parameter data: The data to append to this data. + @inline(__always) + public mutating func append(_ other: Data) { + + self.bytes += other.bytes + } + + /// Return a new copy of the data in a specified range. + /// + /// - parameter range: The range to copy. + @inline(__always) + public func subdata(in range: Range) -> Data { + + return Data(bytes: bytes[range]) + } + + // MARK: - Index and Subscript + + /// Sets or returns the byte at the specified index. + + public subscript(index: Index) -> Byte { + + @inline(__always) + get { return bytes[index] } + + @inline(__always) + set { bytes[index] = newValue } + } + + public subscript(bounds: Range) -> MutableRandomAccessSlice { + + @inline(__always) + get { return MutableRandomAccessSlice(base: self, bounds: bounds) } + + @inline(__always) + set { bytes.replaceSubrange(bounds, with: newValue) } + } + + /// The start `Index` in the data. + public var startIndex: Index { + + return 0 + } + + /// The end `Index` into the data. + /// + /// This is the "one-past-the-end" position, and will always be equal to the `count`. + public var endIndex: Index { + return count + } + + public func index(before i: Index) -> Index { + return i - 1 + } + + public func index(after i: Index) -> Index { + return i + 1 + } - self.byteValue = byteValue + /// An iterator over the contents of the data. + /// + /// The iterator will increment byte-by-byte. + public func makeIterator() -> Data.Iterator { + + return IndexingIterator(_elements: self) + } } -} - -public typealias Byte = UInt8 - -public extension Data { - /// Initializes ```Data``` from an unsafe byte pointer. - /// - /// - Precondition: The pointer points to a type exactly a byte long. - static func from(pointer: UnsafePointer, length: Int) -> Data { + // MARK: - Equatable + + public func == (lhs: Data, rhs: Data) -> Bool { - assert(sizeof(pointer.pointee.dynamicType) == sizeof(Byte.self), "Cannot create array of bytes from pointer to \(pointer.pointee.dynamicType) because the type is larger than a single byte.") + guard lhs.bytes.count == rhs.bytes.count else { return false } - var buffer: [UInt8] = [UInt8](repeating: 0, count: length) + var bytes1 = lhs.bytes - memcpy(&buffer, pointer, length) + var bytes2 = rhs.bytes - return Data(byteValue: buffer) + return memcmp(&bytes1, &bytes2, lhs.bytes.count) == 0 } -} - -// MARK: - Equatable -public func == (lhs: Data, rhs: Data) -> Bool { + // MARK: - Operators - guard lhs.byteValue.count == rhs.byteValue.count else { return false } + public func + (lhs: Data, rhs: Data) -> Data { + + return Data(bytes: lhs.bytes + rhs.bytes) + } - var bytes1 = lhs.byteValue +#endif + +// MARK: - Darwin Support + +#if (os(OSX) || os(iOS) || os(watchOS) || os(tvOS)) - var bytes2 = rhs.byteValue + extension Foundation.Data: ByteValue { + + public typealias ByteValue = [Byte] + + public var bytes: [Byte] { + + get { + + return withUnsafeBytes({ (pointer: UnsafePointer) in + + var bytes = [UInt8](repeating: 0, count: count) + + memcpy(&bytes, pointer, count) + + return bytes + }) + } + + set { self = Foundation.Data(bytes: newValue) } + } + } - return memcmp(&bytes1, &bytes2, lhs.byteValue.count) == 0 -} + public func + (lhs: Foundation.Data, rhs: Foundation.Data) -> Foundation.Data { + + var copy = lhs + + copy.append(rhs) + + return copy + } + +#endif + +// MARK: - Supporting Types -// MARK: - Protocol +public typealias Byte = UInt8 /// Protocol for converting types to and from data. public protocol DataConvertible { @@ -66,6 +240,3 @@ public protocol DataConvertible { /// Convert to data. func toData() -> Data } - - - \ No newline at end of file diff --git a/Sources/SwiftFoundation/FileManager.swift b/Sources/SwiftFoundation/FileManager.swift index aff2e8b..0e198d1 100644 --- a/Sources/SwiftFoundation/FileManager.swift +++ b/Sources/SwiftFoundation/FileManager.swift @@ -203,7 +203,7 @@ public struct FileManager { //guard readBytes == fileSize else { fatalError() } - let data = Data.from(pointer: memoryPointer, length: readBytes) + let data = Data(bytes: memoryPointer, count: readBytes) return data } @@ -219,7 +219,7 @@ public struct FileManager { // close file defer { guard close(file) != -1 else { fatalError("Could not close file: \(path)") } } - let writtenBytes = write(file, data.byteValue, data.byteValue.count) + let writtenBytes = write(file, data.bytes, data.count) guard writtenBytes != -1 else { throw POSIXError.fromErrorNumber! } } diff --git a/Sources/SwiftFoundation/Hash.swift b/Sources/SwiftFoundation/Hash.swift new file mode 100644 index 0000000..577551c --- /dev/null +++ b/Sources/SwiftFoundation/Hash.swift @@ -0,0 +1,13 @@ +// +// Hash.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 6/30/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +public func Hash(_ data: Data) -> Int { + + // more expensive than casting but that's not safe for large values. + return data.bytes.map({ Int($0) }).reduce(0, combine: { $0.0 ^ $0.1 }) +} diff --git a/Sources/SwiftFoundation/POSIXUUID.swift b/Sources/SwiftFoundation/POSIXUUID.swift deleted file mode 100644 index bd792e7..0000000 --- a/Sources/SwiftFoundation/POSIXUUID.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// POSIXUUID.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/22/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - import Darwin -#elseif os(Linux) - import Glibc - import CUUID -#endif - -// MARK: - POSIX UUID System Type Functions - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - internal typealias POSIXUUIDStringType = uuid_string_t -#elseif os(Linux) - internal typealias POSIXUUIDStringType = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8) -#endif - -internal func POSIXUUIDCreateRandom() -> uuid_t { - - var uuid = uuid_t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) - - withUnsafeMutablePointer(&uuid, { (valuePointer: UnsafeMutablePointer) -> Void in - - let bufferType = UnsafeMutablePointer.self - - let buffer = unsafeBitCast(valuePointer, to: bufferType) - - uuid_generate(buffer) - }) - - return uuid -} - -internal func POSIXUUIDConvertToString(_ uuid: uuid_t) -> String { - - let uuidString = POSIXUUIDConvertToUUIDString(uuid) - - return POSIXUUIDStringConvertToString(uuidString) -} - -internal func POSIXUUIDConvertToUUIDString(_ uuid: uuid_t) -> POSIXUUIDStringType { - - var uuidCopy = uuid - - var uuidString = POSIXUUIDStringType(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - - withUnsafeMutablePointers(&uuidCopy, &uuidString) { (uuidPointer: UnsafeMutablePointer, uuidStringPointer: UnsafeMutablePointer) -> Void in - - let stringBuffer = unsafeBitCast(uuidStringPointer, to: UnsafeMutablePointer.self) - - let uuidBuffer = unsafeBitCast(uuidPointer, to: UnsafeMutablePointer.self) - - uuid_unparse(unsafeBitCast(uuidBuffer, to: UnsafePointer.self), stringBuffer) - } - - return uuidString -} - -internal func POSIXUUIDStringConvertToString(_ uuidString: POSIXUUIDStringType) -> String { - - var uuidStringCopy = uuidString - - return withUnsafeMutablePointer(&uuidStringCopy, { (valuePointer: UnsafeMutablePointer) -> String in - - let bufferType = UnsafeMutablePointer.self - - let buffer = unsafeBitCast(valuePointer, to: bufferType) - - return String(validatingUTF8: unsafeBitCast(buffer, to: UnsafePointer.self))! - }) -} - -internal func POSIXUUIDConvertStringToUUID(_ string: String) -> uuid_t? { - - let uuidPointer = UnsafeMutablePointer(allocatingCapacity: 1) - defer { uuidPointer.deallocateCapacity(1) } - - guard uuid_parse(string, unsafeBitCast(uuidPointer, to: UnsafeMutablePointer.self)) != -1 else { - - return nil - } - - return uuidPointer.pointee -} diff --git a/Sources/SwiftFoundation/RawRepresentable.swift b/Sources/SwiftFoundation/RawRepresentable.swift index 76e9e7a..a532011 100644 --- a/Sources/SwiftFoundation/RawRepresentable.swift +++ b/Sources/SwiftFoundation/RawRepresentable.swift @@ -10,7 +10,8 @@ public extension RawRepresentable { - /// Creates a collection of ```RawRepresentable``` from a collection of raw values. Returns ```nil``` if an element in the array had an invalid raw value. + /// Creates a collection of ```RawRepresentable``` from a collection of raw values. + /// åReturns ```nil``` if an element in the array had an invalid raw value. static func from(rawValues: [RawValue]) -> [Self]? { var representables = [Self]() diff --git a/Sources/SwiftFoundation/String.swift b/Sources/SwiftFoundation/String.swift index cd9303c..e9624a2 100644 --- a/Sources/SwiftFoundation/String.swift +++ b/Sources/SwiftFoundation/String.swift @@ -14,7 +14,7 @@ public extension String { var string = "" - var generator = data.byteValue.makeIterator() + var generator = data.bytes.makeIterator() var encoding = UTF8() @@ -44,11 +44,11 @@ public extension String { func toUTF8Data() -> Data { - return Data(byteValue: [] + utf8) + return Data(bytes: [] + utf8) } func substring(range: Range) -> String? { let indexRange = utf8.index(utf8.startIndex, offsetBy: range.lowerBound) ..< utf8.index(utf8.startIndex, offsetBy: range.upperBound) return String(utf8[indexRange]) } -} \ No newline at end of file +} diff --git a/Sources/SwiftFoundation/UUID.swift b/Sources/SwiftFoundation/UUID.swift index 410db75..ce2912a 100644 --- a/Sources/SwiftFoundation/UUID.swift +++ b/Sources/SwiftFoundation/UUID.swift @@ -7,12 +7,12 @@ // /// A representation of a universally unique identifier (```UUID```). -public struct UUID: ByteValueType, RawRepresentable, CustomStringConvertible { +public struct UUID: ByteValue, Equatable, Hashable, RawRepresentable, CustomStringConvertible { /// Raw byte type for UUID public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) - // MARK: - Public Properties + // MARK: - Properties public var byteValue: ByteValue diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 731e1bf..613cc25 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -16,47 +16,9 @@ 6E08F85D1BBE7DE900548B1E /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */; }; 6E1ACD4B1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; 6E1ACD4C1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; }; - 6E2C2B581C20F6F500B2C995 /* FoundationConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */; }; - 6E2C2B591C20F6F500B2C995 /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0E1C20F6EB00B2C995 /* HTTPClient.swift */; }; - 6E2C2B5A1C20F6F500B2C995 /* NSComparisonResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0F1C20F6EB00B2C995 /* NSComparisonResult.swift */; }; - 6E2C2B5B1C20F6F500B2C995 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B101C20F6EB00B2C995 /* NSData.swift */; }; - 6E2C2B5C1C20F6F500B2C995 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B111C20F6EB00B2C995 /* NSDate.swift */; }; - 6E2C2B5D1C20F6F500B2C995 /* NSJSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B121C20F6EB00B2C995 /* NSJSONSerialization.swift */; }; - 6E2C2B5E1C20F6F500B2C995 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B131C20F6EB00B2C995 /* NSNull.swift */; }; - 6E2C2B5F1C20F6F500B2C995 /* NSURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */; }; - 6E2C2B601C20F6F500B2C995 /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B151C20F6EB00B2C995 /* NSUUID.swift */; }; - 6E2C2B611C20F6F600B2C995 /* FoundationConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */; }; - 6E2C2B621C20F6F600B2C995 /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0E1C20F6EB00B2C995 /* HTTPClient.swift */; }; - 6E2C2B631C20F6F600B2C995 /* NSComparisonResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0F1C20F6EB00B2C995 /* NSComparisonResult.swift */; }; - 6E2C2B641C20F6F600B2C995 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B101C20F6EB00B2C995 /* NSData.swift */; }; - 6E2C2B651C20F6F600B2C995 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B111C20F6EB00B2C995 /* NSDate.swift */; }; - 6E2C2B661C20F6F600B2C995 /* NSJSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B121C20F6EB00B2C995 /* NSJSONSerialization.swift */; }; - 6E2C2B671C20F6F600B2C995 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B131C20F6EB00B2C995 /* NSNull.swift */; }; - 6E2C2B681C20F6F600B2C995 /* NSURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */; }; - 6E2C2B691C20F6F600B2C995 /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B151C20F6EB00B2C995 /* NSUUID.swift */; }; - 6E2C2B6A1C20F6F700B2C995 /* FoundationConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */; }; - 6E2C2B6B1C20F6F700B2C995 /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0E1C20F6EB00B2C995 /* HTTPClient.swift */; }; - 6E2C2B6C1C20F6F700B2C995 /* NSComparisonResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B0F1C20F6EB00B2C995 /* NSComparisonResult.swift */; }; - 6E2C2B6D1C20F6F700B2C995 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B101C20F6EB00B2C995 /* NSData.swift */; }; - 6E2C2B6E1C20F6F700B2C995 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B111C20F6EB00B2C995 /* NSDate.swift */; }; - 6E2C2B6F1C20F6F700B2C995 /* NSJSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B121C20F6EB00B2C995 /* NSJSONSerialization.swift */; }; - 6E2C2B701C20F6F700B2C995 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B131C20F6EB00B2C995 /* NSNull.swift */; }; - 6E2C2B711C20F6F700B2C995 /* NSURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */; }; - 6E2C2B721C20F6F700B2C995 /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B151C20F6EB00B2C995 /* NSUUID.swift */; }; - 6E2C2B731C20F75F00B2C995 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B171C20F6EB00B2C995 /* NSDateTests.swift */; }; - 6E2C2B741C20F75F00B2C995 /* NSFileManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B181C20F6EB00B2C995 /* NSFileManagerTests.swift */; }; - 6E2C2B751C20F75F00B2C995 /* NSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B191C20F6EB00B2C995 /* NSUUIDTests.swift */; }; - 6E2C2B761C20F75F00B2C995 /* NSSortDescriptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1A1C20F6EB00B2C995 /* NSSortDescriptorTests.swift */; }; - 6E2C2B771C20F76000B2C995 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B171C20F6EB00B2C995 /* NSDateTests.swift */; }; - 6E2C2B781C20F76000B2C995 /* NSFileManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B181C20F6EB00B2C995 /* NSFileManagerTests.swift */; }; - 6E2C2B791C20F76000B2C995 /* NSUUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B191C20F6EB00B2C995 /* NSUUIDTests.swift */; }; - 6E2C2B7A1C20F76000B2C995 /* NSSortDescriptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1A1C20F6EB00B2C995 /* NSSortDescriptorTests.swift */; }; 6E2C2B7B1C20F76600B2C995 /* Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */; }; 6E2C2B7C1C20F76600B2C995 /* BitMaskOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */; }; - 6E2C2B7E1C20F76600B2C995 /* ByteValueType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1F1C20F6EB00B2C995 /* ByteValueType.swift */; }; - 6E2C2B801C20F76600B2C995 /* ComparableSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B211C20F6EB00B2C995 /* ComparableSortDescriptor.swift */; }; - 6E2C2B811C20F76600B2C995 /* ComparatorSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B221C20F6EB00B2C995 /* ComparatorSortDescriptor.swift */; }; - 6E2C2B821C20F76600B2C995 /* Copying.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B231C20F6EB00B2C995 /* Copying.swift */; }; + 6E2C2B7E1C20F76600B2C995 /* ByteValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1F1C20F6EB00B2C995 /* ByteValue.swift */; }; 6E2C2B831C20F76600B2C995 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B241C20F6EB00B2C995 /* Data.swift */; }; 6E2C2B841C20F76600B2C995 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B251C20F6EB00B2C995 /* Date.swift */; }; 6E2C2B851C20F76600B2C995 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */; }; @@ -82,7 +44,6 @@ 6E2C2B991C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */; }; 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */; }; 6E2C2B9B1C20F76600B2C995 /* POSIXTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */; }; - 6E2C2B9C1C20F76600B2C995 /* POSIXUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3D1C20F6EB00B2C995 /* POSIXUUID.swift */; }; 6E2C2B9D1C20F76600B2C995 /* Predicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */; }; 6E2C2B9E1C20F76600B2C995 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */; }; 6E2C2B9F1C20F76600B2C995 /* RegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */; }; @@ -103,10 +64,7 @@ 6E2C2BAE1C20F76600B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2BAF1C20F76600B2C995 /* Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */; }; 6E2C2BB01C20F76600B2C995 /* BitMaskOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */; }; - 6E2C2BB21C20F76600B2C995 /* ByteValueType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1F1C20F6EB00B2C995 /* ByteValueType.swift */; }; - 6E2C2BB41C20F76600B2C995 /* ComparableSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B211C20F6EB00B2C995 /* ComparableSortDescriptor.swift */; }; - 6E2C2BB51C20F76600B2C995 /* ComparatorSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B221C20F6EB00B2C995 /* ComparatorSortDescriptor.swift */; }; - 6E2C2BB61C20F76600B2C995 /* Copying.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B231C20F6EB00B2C995 /* Copying.swift */; }; + 6E2C2BB21C20F76600B2C995 /* ByteValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1F1C20F6EB00B2C995 /* ByteValue.swift */; }; 6E2C2BB71C20F76600B2C995 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B241C20F6EB00B2C995 /* Data.swift */; }; 6E2C2BB81C20F76600B2C995 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B251C20F6EB00B2C995 /* Date.swift */; }; 6E2C2BB91C20F76600B2C995 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */; }; @@ -132,7 +90,6 @@ 6E2C2BCD1C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */; }; 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */; }; 6E2C2BCF1C20F76600B2C995 /* POSIXTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */; }; - 6E2C2BD01C20F76600B2C995 /* POSIXUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3D1C20F6EB00B2C995 /* POSIXUUID.swift */; }; 6E2C2BD11C20F76600B2C995 /* Predicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */; }; 6E2C2BD21C20F76600B2C995 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */; }; 6E2C2BD31C20F76600B2C995 /* RegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */; }; @@ -153,10 +110,7 @@ 6E2C2BE21C20F76600B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2BE31C20F76700B2C995 /* Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */; }; 6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */; }; - 6E2C2BE61C20F76700B2C995 /* ByteValueType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1F1C20F6EB00B2C995 /* ByteValueType.swift */; }; - 6E2C2BE81C20F76700B2C995 /* ComparableSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B211C20F6EB00B2C995 /* ComparableSortDescriptor.swift */; }; - 6E2C2BE91C20F76700B2C995 /* ComparatorSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B221C20F6EB00B2C995 /* ComparatorSortDescriptor.swift */; }; - 6E2C2BEA1C20F76700B2C995 /* Copying.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B231C20F6EB00B2C995 /* Copying.swift */; }; + 6E2C2BE61C20F76700B2C995 /* ByteValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1F1C20F6EB00B2C995 /* ByteValue.swift */; }; 6E2C2BEB1C20F76700B2C995 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B241C20F6EB00B2C995 /* Data.swift */; }; 6E2C2BEC1C20F76700B2C995 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B251C20F6EB00B2C995 /* Date.swift */; }; 6E2C2BED1C20F76700B2C995 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */; }; @@ -182,7 +136,6 @@ 6E2C2C011C20F76700B2C995 /* POSIXFileSystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */; }; 6E2C2C021C20F76700B2C995 /* POSIXRegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */; }; 6E2C2C031C20F76700B2C995 /* POSIXTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */; }; - 6E2C2C041C20F76700B2C995 /* POSIXUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3D1C20F6EB00B2C995 /* POSIXUUID.swift */; }; 6E2C2C051C20F76700B2C995 /* Predicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */; }; 6E2C2C061C20F76700B2C995 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */; }; 6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */; }; @@ -198,7 +151,6 @@ 6E2C2C121C20F76700B2C995 /* URLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4B1C20F6EB00B2C995 /* URLProtocol.swift */; }; 6E2C2C131C20F76700B2C995 /* URLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4C1C20F6EB00B2C995 /* URLRequest.swift */; }; 6E2C2C141C20F76700B2C995 /* URLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4D1C20F6EB00B2C995 /* URLResponse.swift */; }; - 6E2C2C151C20F76700B2C995 /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */; }; 6E2C2C161C20F76700B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2C171C20F76B00B2C995 /* DateComponentsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */; }; 6E2C2C181C20F76B00B2C995 /* OrderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */; }; @@ -214,23 +166,17 @@ 6E2C2C221C20F76D00B2C995 /* SortDescriptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B551C20F6EB00B2C995 /* SortDescriptorTests.swift */; }; 6E2C2C231C20F76D00B2C995 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */; }; 6E2C2C241C20F76D00B2C995 /* UUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */; }; - 6E2C2C2C1C21115C00B2C995 /* NSComparisonResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C2B1C21115C00B2C995 /* NSComparisonResultTests.swift */; }; - 6E2C2C2D1C21115C00B2C995 /* NSComparisonResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C2B1C21115C00B2C995 /* NSComparisonResultTests.swift */; }; 6E2C2C2F1C2128C600B2C995 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C2E1C2128C600B2C995 /* main.swift */; }; 6E2C2C301C2128C600B2C995 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C2E1C2128C600B2C995 /* main.swift */; }; - 6E2C2C341C212C5600B2C995 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C311C212C2200B2C995 /* NSString.swift */; }; - 6E2C2C351C212C5600B2C995 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C311C212C2200B2C995 /* NSString.swift */; }; - 6E2C2C361C212C5700B2C995 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C311C212C2200B2C995 /* NSString.swift */; }; 6E30BA111B40F543009B1B49 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6E30BA181B40F543009B1B49 /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E30BA0D1B40F543009B1B49 /* SwiftFoundation.framework */; }; 6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; - 6E82FD761CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; - 6E82FD771CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; - 6E82FD781CBB61220049CD1B /* Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD751CBB61220049CD1B /* Atomic.swift */; }; 6E82FD7A1CBB70710049CD1B /* AtomicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD791CBB70710049CD1B /* AtomicTests.swift */; }; 6E82FD7B1CBB70710049CD1B /* AtomicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD791CBB70710049CD1B /* AtomicTests.swift */; }; + 6E8474CA1D24EC3A009CA7DB /* Hash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8474C91D24EC3A009CA7DB /* Hash.swift */; }; + 6E8474CB1D24F1A5009CA7DB /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */; }; 6E957C261C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; @@ -310,25 +256,9 @@ 6E04074D1CB3E07500BE3A79 /* Thread.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Thread.swift; sourceTree = ""; }; 6E08F8571BBE7B8800548B1E /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E1ACD4A1C435822005775FD /* DataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTests.swift; sourceTree = ""; }; - 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoundationConvertible.swift; sourceTree = ""; }; - 6E2C2B0E1C20F6EB00B2C995 /* HTTPClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPClient.swift; sourceTree = ""; }; - 6E2C2B0F1C20F6EB00B2C995 /* NSComparisonResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSComparisonResult.swift; sourceTree = ""; }; - 6E2C2B101C20F6EB00B2C995 /* NSData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = ""; }; - 6E2C2B111C20F6EB00B2C995 /* NSDate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSDate.swift; sourceTree = ""; }; - 6E2C2B121C20F6EB00B2C995 /* NSJSONSerialization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSJSONSerialization.swift; sourceTree = ""; }; - 6E2C2B131C20F6EB00B2C995 /* NSNull.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSNull.swift; sourceTree = ""; }; - 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLSession.swift; sourceTree = ""; }; - 6E2C2B151C20F6EB00B2C995 /* NSUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSUUID.swift; sourceTree = ""; }; - 6E2C2B171C20F6EB00B2C995 /* NSDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSDateTests.swift; sourceTree = ""; }; - 6E2C2B181C20F6EB00B2C995 /* NSFileManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSFileManagerTests.swift; sourceTree = ""; }; - 6E2C2B191C20F6EB00B2C995 /* NSUUIDTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSUUIDTests.swift; sourceTree = ""; }; - 6E2C2B1A1C20F6EB00B2C995 /* NSSortDescriptorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSSortDescriptorTests.swift; sourceTree = ""; }; 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base64.swift; sourceTree = ""; }; 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitMaskOption.swift; sourceTree = ""; }; - 6E2C2B1F1C20F6EB00B2C995 /* ByteValueType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ByteValueType.swift; sourceTree = ""; }; - 6E2C2B211C20F6EB00B2C995 /* ComparableSortDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparableSortDescriptor.swift; sourceTree = ""; }; - 6E2C2B221C20F6EB00B2C995 /* ComparatorSortDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparatorSortDescriptor.swift; sourceTree = ""; }; - 6E2C2B231C20F6EB00B2C995 /* Copying.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Copying.swift; sourceTree = ""; }; + 6E2C2B1F1C20F6EB00B2C995 /* ByteValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ByteValue.swift; sourceTree = ""; }; 6E2C2B241C20F6EB00B2C995 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 6E2C2B251C20F6EB00B2C995 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateComponents.swift; sourceTree = ""; }; @@ -354,7 +284,6 @@ 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXFileSystemStatus.swift; sourceTree = ""; }; 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXRegularExpression.swift; sourceTree = ""; }; 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXTime.swift; sourceTree = ""; }; - 6E2C2B3D1C20F6EB00B2C995 /* POSIXUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXUUID.swift; sourceTree = ""; }; 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Predicate.swift; sourceTree = ""; }; 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = ""; }; 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpression.swift; sourceTree = ""; }; @@ -381,17 +310,15 @@ 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UUIDTests.swift; sourceTree = ""; }; 6E2C2C2A1C21105000B2C995 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Package.swift; sourceTree = ""; }; - 6E2C2C2B1C21115C00B2C995 /* NSComparisonResultTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSComparisonResultTests.swift; sourceTree = ""; }; 6E2C2C2E1C2128C600B2C995 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; - 6E2C2C311C212C2200B2C995 /* NSString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSString.swift; sourceTree = ""; }; 6E30BA0D1B40F543009B1B49 /* SwiftFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftFoundation.h; sourceTree = ""; }; 6E30BA121B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6E30BA171B40F543009B1B49 /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E30BA1E1B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6E82FD711CBA06C10049CD1B /* Lock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = ""; }; - 6E82FD751CBB61220049CD1B /* Atomic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Atomic.swift; sourceTree = ""; }; 6E82FD791CBB70710049CD1B /* AtomicTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomicTests.swift; sourceTree = ""; }; + 6E8474C91D24EC3A009CA7DB /* Hash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = ""; }; 6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = ""; }; 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = ""; }; 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = ""; }; @@ -465,53 +392,19 @@ children = ( 6E2C2B1B1C20F6EB00B2C995 /* SwiftFoundation */, 6E2C2B501C20F6EB00B2C995 /* UnitTests */, - 6E2C2B0C1C20F6EB00B2C995 /* FoundationConvertible */, - 6E2C2B161C20F6EB00B2C995 /* FoundationUnitTests */, ); name = Sources; path = ../Sources; sourceTree = ""; }; - 6E2C2B0C1C20F6EB00B2C995 /* FoundationConvertible */ = { - isa = PBXGroup; - children = ( - 6E2C2B0D1C20F6EB00B2C995 /* FoundationConvertible.swift */, - 6E2C2B0E1C20F6EB00B2C995 /* HTTPClient.swift */, - 6E2C2B141C20F6EB00B2C995 /* NSURLSession.swift */, - 6E2C2B0F1C20F6EB00B2C995 /* NSComparisonResult.swift */, - 6E2C2B101C20F6EB00B2C995 /* NSData.swift */, - 6E2C2B111C20F6EB00B2C995 /* NSDate.swift */, - 6E2C2B121C20F6EB00B2C995 /* NSJSONSerialization.swift */, - 6E2C2B131C20F6EB00B2C995 /* NSNull.swift */, - 6E2C2B151C20F6EB00B2C995 /* NSUUID.swift */, - 6E2C2C311C212C2200B2C995 /* NSString.swift */, - ); - path = FoundationConvertible; - sourceTree = ""; - }; - 6E2C2B161C20F6EB00B2C995 /* FoundationUnitTests */ = { - isa = PBXGroup; - children = ( - 6E2C2C2B1C21115C00B2C995 /* NSComparisonResultTests.swift */, - 6E2C2B171C20F6EB00B2C995 /* NSDateTests.swift */, - 6E2C2B181C20F6EB00B2C995 /* NSFileManagerTests.swift */, - 6E2C2B191C20F6EB00B2C995 /* NSUUIDTests.swift */, - 6E2C2B1A1C20F6EB00B2C995 /* NSSortDescriptorTests.swift */, - ); - path = FoundationUnitTests; - sourceTree = ""; - }; 6E2C2B1B1C20F6EB00B2C995 /* SwiftFoundation */ = { isa = PBXGroup; children = ( 6E2C2C251C20FAED00B2C995 /* Standard Library Extensions */, - 6E82FD751CBB61220049CD1B /* Atomic.swift */, 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */, 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */, - 6E2C2B1F1C20F6EB00B2C995 /* ByteValueType.swift */, - 6E2C2B211C20F6EB00B2C995 /* ComparableSortDescriptor.swift */, - 6E2C2B221C20F6EB00B2C995 /* ComparatorSortDescriptor.swift */, - 6E2C2B231C20F6EB00B2C995 /* Copying.swift */, + 6E2C2B1F1C20F6EB00B2C995 /* ByteValue.swift */, + 6E8474C91D24EC3A009CA7DB /* Hash.swift */, 6E2C2B241C20F6EB00B2C995 /* Data.swift */, 6E2C2B251C20F6EB00B2C995 /* Date.swift */, 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */, @@ -585,7 +478,6 @@ 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */, 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */, 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */, - 6E2C2B3D1C20F6EB00B2C995 /* POSIXUUID.swift */, ); name = POSIX; sourceTree = ""; @@ -895,14 +787,10 @@ 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2BC01C20F76600B2C995 /* HTTP.swift in Sources */, 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */, - 6E82FD771CBB61220049CD1B /* Atomic.swift in Sources */, - 6E2C2B621C20F6F600B2C995 /* HTTPClient.swift in Sources */, - 6E2C2B661C20F6F600B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2BBE1C20F76600B2C995 /* FileType.swift in Sources */, 6E2C2BD61C20F76600B2C995 /* RegularExpressionMatchOption.swift in Sources */, 6E2C2BB91C20F76600B2C995 /* DateComponents.swift in Sources */, - 6E2C2BB21C20F76600B2C995 /* ByteValueType.swift in Sources */, - 6E2C2B631C20F6F600B2C995 /* NSComparisonResult.swift in Sources */, + 6E2C2BB21C20F76600B2C995 /* ByteValue.swift in Sources */, 6E2C2BC21C20F76600B2C995 /* HTTPRequest.swift in Sources */, 6E2C2BCD1C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */, 6E2C2BD11C20F76600B2C995 /* Predicate.swift in Sources */, @@ -914,7 +802,6 @@ 6E2C2BC61C20F76600B2C995 /* Integer.swift in Sources */, 6E2C2BDF1C20F76600B2C995 /* URLRequest.swift in Sources */, 6E2C2BBA1C20F76600B2C995 /* Decimal.swift in Sources */, - 6E2C2BB61C20F76600B2C995 /* Copying.swift in Sources */, 6E2C2BC91C20F76600B2C995 /* Null.swift in Sources */, 6E2C2BB01C20F76600B2C995 /* BitMaskOption.swift in Sources */, 6E2C2BD51C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */, @@ -924,8 +811,6 @@ 6E2C2BB71C20F76600B2C995 /* Data.swift in Sources */, 6E2C2BDC1C20F76600B2C995 /* URL.swift in Sources */, 6E2C2BCF1C20F76600B2C995 /* POSIXTime.swift in Sources */, - 6E2C2B641C20F6F600B2C995 /* NSData.swift in Sources */, - 6E2C2B611C20F6F600B2C995 /* FoundationConvertible.swift in Sources */, 6E2C2BBF1C20F76600B2C995 /* Formatter.swift in Sources */, 6EE84DDE1CAF667E00A40C4D /* Hexadecimal.swift in Sources */, 6E2C2BDE1C20F76600B2C995 /* URLProtocol.swift in Sources */, @@ -933,12 +818,9 @@ 6E2C2BC51C20F76600B2C995 /* HTTPVersion.swift in Sources */, 6E2C2BC11C20F76600B2C995 /* HTTPMethod.swift in Sources */, 6E2C2BE11C20F76600B2C995 /* UUID.swift in Sources */, - 6E2C2C351C212C5600B2C995 /* NSString.swift in Sources */, 6E2C2BBB1C20F76600B2C995 /* FileDescriptor.swift in Sources */, 6E2C2BDA1C20F76600B2C995 /* Task.swift in Sources */, - 6E2C2BB51C20F76600B2C995 /* ComparatorSortDescriptor.swift in Sources */, 6E2C2BDD1C20F76600B2C995 /* URLClient.swift in Sources */, - 6E2C2B681C20F6F600B2C995 /* NSURLSession.swift in Sources */, 6E2C2BC41C20F76600B2C995 /* HTTPStatusCode.swift in Sources */, 6E2C2BDB1C20F76600B2C995 /* Transformer.swift in Sources */, 6E2C2BD41C20F76600B2C995 /* RegularExpressionCompileError.swift in Sources */, @@ -948,16 +830,11 @@ 6E957C2C1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6EE84DDA1CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2BCB1C20F76600B2C995 /* POSIXError.swift in Sources */, - 6E2C2BD01C20F76600B2C995 /* POSIXUUID.swift in Sources */, - 6E2C2B671C20F6F600B2C995 /* NSNull.swift in Sources */, - 6E2C2B691C20F6F600B2C995 /* NSUUID.swift in Sources */, 6E2C2BCA1C20F76600B2C995 /* Order.swift in Sources */, - 6E2C2BB41C20F76600B2C995 /* ComparableSortDescriptor.swift in Sources */, 6E957C2F1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2BB81C20F76600B2C995 /* Date.swift in Sources */, 6E2C2BC71C20F76600B2C995 /* JSON.swift in Sources */, 6E2C2BAF1C20F76600B2C995 /* Base64.swift in Sources */, - 6E2C2B651C20F6F600B2C995 /* NSDate.swift in Sources */, 6E2C2BD81C20F76600B2C995 /* SortDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -970,14 +847,10 @@ 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2B8C1C20F76600B2C995 /* HTTP.swift in Sources */, 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */, - 6E82FD781CBB61220049CD1B /* Atomic.swift in Sources */, - 6E2C2B591C20F6F500B2C995 /* HTTPClient.swift in Sources */, - 6E2C2B5D1C20F6F500B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2B8A1C20F76600B2C995 /* FileType.swift in Sources */, 6E2C2BA21C20F76600B2C995 /* RegularExpressionMatchOption.swift in Sources */, 6E2C2B851C20F76600B2C995 /* DateComponents.swift in Sources */, - 6E2C2B7E1C20F76600B2C995 /* ByteValueType.swift in Sources */, - 6E2C2B5A1C20F6F500B2C995 /* NSComparisonResult.swift in Sources */, + 6E2C2B7E1C20F76600B2C995 /* ByteValue.swift in Sources */, 6E2C2B8E1C20F76600B2C995 /* HTTPRequest.swift in Sources */, 6E2C2B991C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */, 6E2C2B9D1C20F76600B2C995 /* Predicate.swift in Sources */, @@ -989,7 +862,6 @@ 6E2C2B921C20F76600B2C995 /* Integer.swift in Sources */, 6E2C2BAB1C20F76600B2C995 /* URLRequest.swift in Sources */, 6E2C2B861C20F76600B2C995 /* Decimal.swift in Sources */, - 6E2C2B821C20F76600B2C995 /* Copying.swift in Sources */, 6E2C2B951C20F76600B2C995 /* Null.swift in Sources */, 6E2C2B7C1C20F76600B2C995 /* BitMaskOption.swift in Sources */, 6E2C2BA11C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */, @@ -999,8 +871,6 @@ 6E2C2B831C20F76600B2C995 /* Data.swift in Sources */, 6E2C2BA81C20F76600B2C995 /* URL.swift in Sources */, 6E2C2B9B1C20F76600B2C995 /* POSIXTime.swift in Sources */, - 6E2C2B5B1C20F6F500B2C995 /* NSData.swift in Sources */, - 6E2C2B581C20F6F500B2C995 /* FoundationConvertible.swift in Sources */, 6E2C2B8B1C20F76600B2C995 /* Formatter.swift in Sources */, 6EE84DDF1CAF667E00A40C4D /* Hexadecimal.swift in Sources */, 6E2C2BAA1C20F76600B2C995 /* URLProtocol.swift in Sources */, @@ -1008,12 +878,9 @@ 6E2C2B911C20F76600B2C995 /* HTTPVersion.swift in Sources */, 6E2C2B8D1C20F76600B2C995 /* HTTPMethod.swift in Sources */, 6E2C2BAD1C20F76600B2C995 /* UUID.swift in Sources */, - 6E2C2C361C212C5700B2C995 /* NSString.swift in Sources */, 6E2C2B871C20F76600B2C995 /* FileDescriptor.swift in Sources */, 6E2C2BA61C20F76600B2C995 /* Task.swift in Sources */, - 6E2C2B811C20F76600B2C995 /* ComparatorSortDescriptor.swift in Sources */, 6E2C2BA91C20F76600B2C995 /* URLClient.swift in Sources */, - 6E2C2B5F1C20F6F500B2C995 /* NSURLSession.swift in Sources */, 6E2C2B901C20F76600B2C995 /* HTTPStatusCode.swift in Sources */, 6E2C2BA71C20F76600B2C995 /* Transformer.swift in Sources */, 6E2C2BA01C20F76600B2C995 /* RegularExpressionCompileError.swift in Sources */, @@ -1023,16 +890,11 @@ 6E957C2D1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6EE84DDB1CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2B971C20F76600B2C995 /* POSIXError.swift in Sources */, - 6E2C2B9C1C20F76600B2C995 /* POSIXUUID.swift in Sources */, - 6E2C2B5E1C20F6F500B2C995 /* NSNull.swift in Sources */, - 6E2C2B601C20F6F500B2C995 /* NSUUID.swift in Sources */, 6E2C2B961C20F76600B2C995 /* Order.swift in Sources */, - 6E2C2B801C20F76600B2C995 /* ComparableSortDescriptor.swift in Sources */, 6E957C301C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2B841C20F76600B2C995 /* Date.swift in Sources */, 6E2C2B931C20F76600B2C995 /* JSON.swift in Sources */, 6E2C2B7B1C20F76600B2C995 /* Base64.swift in Sources */, - 6E2C2B5C1C20F6F500B2C995 /* NSDate.swift in Sources */, 6E2C2BA41C20F76600B2C995 /* SortDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1046,9 +908,7 @@ 6E82FD7B1CBB70710049CD1B /* AtomicTests.swift in Sources */, 6EFF9A1F1CAD11F600917CB3 /* Range.swift in Sources */, 6E2C2C1D1C20F76B00B2C995 /* UUIDTests.swift in Sources */, - 6E2C2C2D1C21115C00B2C995 /* NSComparisonResultTests.swift in Sources */, 6E957C581C442E3E003F3C51 /* JSONTests.swift in Sources */, - 6E2C2B741C20F75F00B2C995 /* NSFileManagerTests.swift in Sources */, 6E2C2C1B1C20F76B00B2C995 /* SortDescriptorTests.swift in Sources */, 6E2C2C171C20F76B00B2C995 /* DateComponentsTest.swift in Sources */, 6E2C2C191C20F76B00B2C995 /* POSIXTimeTests.swift in Sources */, @@ -1056,9 +916,6 @@ 6E1ACD4C1C435822005775FD /* DataTests.swift in Sources */, 6EFF9A1E1CAD108400917CB3 /* RangeTests.swift in Sources */, 6E2C2C1C1C20F76B00B2C995 /* StringTests.swift in Sources */, - 6E2C2B731C20F75F00B2C995 /* NSDateTests.swift in Sources */, - 6E2C2B761C20F75F00B2C995 /* NSSortDescriptorTests.swift in Sources */, - 6E2C2B751C20F75F00B2C995 /* NSUUIDTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1066,19 +923,18 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6E8474CA1D24EC3A009CA7DB /* Hash.swift in Sources */, 6E2C2C001C20F76700B2C995 /* POSIXFileStatus.swift in Sources */, 6E957C261C43A7C8003F3C51 /* JSONParse.swift in Sources */, 6E2C2BF41C20F76700B2C995 /* HTTP.swift in Sources */, 6EE84DDD1CAF667E00A40C4D /* Hexadecimal.swift in Sources */, - 6E2C2B6B1C20F6F700B2C995 /* HTTPClient.swift in Sources */, - 6E2C2B6F1C20F6F700B2C995 /* NSJSONSerialization.swift in Sources */, 6E2C2BF21C20F76700B2C995 /* FileType.swift in Sources */, 6E2C2C0A1C20F76700B2C995 /* RegularExpressionMatchOption.swift in Sources */, 6E2C2BED1C20F76700B2C995 /* DateComponents.swift in Sources */, - 6E2C2BE61C20F76700B2C995 /* ByteValueType.swift in Sources */, - 6E2C2B6C1C20F6F700B2C995 /* NSComparisonResult.swift in Sources */, + 6E2C2BE61C20F76700B2C995 /* ByteValue.swift in Sources */, 6E2C2BF61C20F76700B2C995 /* HTTPRequest.swift in Sources */, 6E2C2C011C20F76700B2C995 /* POSIXFileSystemStatus.swift in Sources */, + 6E8474CB1D24F1A5009CA7DB /* UUID.swift in Sources */, 6E2C2C051C20F76700B2C995 /* Predicate.swift in Sources */, 6E041D3D1CB404CD004E080B /* String.swift in Sources */, 6E2C2C061C20F76700B2C995 /* RawRepresentable.swift in Sources */, @@ -1088,8 +944,6 @@ 6E2C2C131C20F76700B2C995 /* URLRequest.swift in Sources */, 6EFF9A1B1CAD0C6B00917CB3 /* Range.swift in Sources */, 6E2C2BEE1C20F76700B2C995 /* Decimal.swift in Sources */, - 6E82FD761CBB61220049CD1B /* Atomic.swift in Sources */, - 6E2C2BEA1C20F76700B2C995 /* Copying.swift in Sources */, 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */, 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */, 6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */, @@ -1101,20 +955,14 @@ 6E2C2BEB1C20F76700B2C995 /* Data.swift in Sources */, 6E2C2C101C20F76700B2C995 /* URL.swift in Sources */, 6E2C2C031C20F76700B2C995 /* POSIXTime.swift in Sources */, - 6E2C2B6D1C20F6F700B2C995 /* NSData.swift in Sources */, - 6E2C2B6A1C20F6F700B2C995 /* FoundationConvertible.swift in Sources */, 6E2C2BF31C20F76700B2C995 /* Formatter.swift in Sources */, 6E2C2C121C20F76700B2C995 /* URLProtocol.swift in Sources */, 6E2C2BFC1C20F76700B2C995 /* JSONExtensions.swift in Sources */, 6E2C2BF91C20F76700B2C995 /* HTTPVersion.swift in Sources */, 6E2C2BF51C20F76700B2C995 /* HTTPMethod.swift in Sources */, - 6E2C2C151C20F76700B2C995 /* UUID.swift in Sources */, - 6E2C2C341C212C5600B2C995 /* NSString.swift in Sources */, 6E2C2BEF1C20F76700B2C995 /* FileDescriptor.swift in Sources */, 6E2C2C0E1C20F76700B2C995 /* Task.swift in Sources */, - 6E2C2BE91C20F76700B2C995 /* ComparatorSortDescriptor.swift in Sources */, 6E2C2C111C20F76700B2C995 /* URLClient.swift in Sources */, - 6E2C2B711C20F6F700B2C995 /* NSURLSession.swift in Sources */, 6E2C2BF81C20F76700B2C995 /* HTTPStatusCode.swift in Sources */, 6E2C2C0F1C20F76700B2C995 /* Transformer.swift in Sources */, 6E2C2C081C20F76700B2C995 /* RegularExpressionCompileError.swift in Sources */, @@ -1123,17 +971,12 @@ 6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */, 6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6E2C2BFF1C20F76700B2C995 /* POSIXError.swift in Sources */, - 6E2C2C041C20F76700B2C995 /* POSIXUUID.swift in Sources */, - 6E2C2B701C20F6F700B2C995 /* NSNull.swift in Sources */, - 6E2C2B721C20F6F700B2C995 /* NSUUID.swift in Sources */, 6E2C2BFE1C20F76700B2C995 /* Order.swift in Sources */, - 6E2C2BE81C20F76700B2C995 /* ComparableSortDescriptor.swift in Sources */, 6E957C2E1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2BEC1C20F76700B2C995 /* Date.swift in Sources */, 6E2C2BFB1C20F76700B2C995 /* JSON.swift in Sources */, 6EE84DD91CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2BE31C20F76700B2C995 /* Base64.swift in Sources */, - 6E2C2B6E1C20F6F700B2C995 /* NSDate.swift in Sources */, 6E2C2C0C1C20F76700B2C995 /* SortDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1146,9 +989,7 @@ 6E82FD7A1CBB70710049CD1B /* AtomicTests.swift in Sources */, 6E2C2C2F1C2128C600B2C995 /* main.swift in Sources */, 6E2C2C241C20F76D00B2C995 /* UUIDTests.swift in Sources */, - 6E2C2C2C1C21115C00B2C995 /* NSComparisonResultTests.swift in Sources */, 6E957C571C442E3E003F3C51 /* JSONTests.swift in Sources */, - 6E2C2B781C20F76000B2C995 /* NSFileManagerTests.swift in Sources */, 6E2C2C221C20F76D00B2C995 /* SortDescriptorTests.swift in Sources */, 6E2C2C1E1C20F76D00B2C995 /* DateComponentsTest.swift in Sources */, 6E2C2C201C20F76D00B2C995 /* POSIXTimeTests.swift in Sources */, @@ -1156,9 +997,6 @@ 6E1ACD4B1C435822005775FD /* DataTests.swift in Sources */, 6EFF9A1D1CAD108400917CB3 /* RangeTests.swift in Sources */, 6E2C2C231C20F76D00B2C995 /* StringTests.swift in Sources */, - 6E2C2B771C20F76000B2C995 /* NSDateTests.swift in Sources */, - 6E2C2B7A1C20F76000B2C995 /* NSSortDescriptorTests.swift in Sources */, - 6E2C2B791C20F76000B2C995 /* NSUUIDTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1399,6 +1237,7 @@ INFOPLIST_FILE = SwiftFoundation/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + OTHER_SWIFT_FLAGS = "-DXcodeLinux"; PRODUCT_BUNDLE_IDENTIFIER = org.pureswift.SwiftFoundation; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -1420,6 +1259,7 @@ INFOPLIST_FILE = SwiftFoundation/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + OTHER_SWIFT_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = org.pureswift.SwiftFoundation; SKIP_INSTALL = YES; }; From ac0a0d1b649c8105d0e537f554b621ae892fcce7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 30 Jun 2016 03:01:02 -0500 Subject: [PATCH 46/68] Implemented Date and UUID for #30 --- .../SwiftFoundation/ComparisonResult.swift | 35 ++ Sources/SwiftFoundation/Data.swift | 4 +- Sources/SwiftFoundation/Date.swift | 232 +++++--- Sources/SwiftFoundation/FileManager.swift | 16 +- Sources/SwiftFoundation/HTTP.swift | 523 +++++++++++++++++- Sources/SwiftFoundation/HTTPMethod.swift | 27 - Sources/SwiftFoundation/HTTPRequest.swift | 32 -- Sources/SwiftFoundation/HTTPResponse.swift | 26 - Sources/SwiftFoundation/HTTPStatusCode.swift | 517 ----------------- Sources/SwiftFoundation/HTTPVersion.swift | 35 -- Sources/SwiftFoundation/Hash.swift | 1 + Sources/SwiftFoundation/Null.swift | 6 +- Sources/SwiftFoundation/Order.swift | 37 -- Sources/SwiftFoundation/POSIXError.swift | 5 +- Sources/SwiftFoundation/POSIXFileStatus.swift | 2 +- .../POSIXFileSystemStatus.swift | 2 +- Sources/SwiftFoundation/POSIXTime.swift | 10 +- Sources/SwiftFoundation/Predicate.swift | 40 -- Sources/SwiftFoundation/SemanticVersion.swift | 63 +-- Sources/SwiftFoundation/SortDescriptor.swift | 42 -- Sources/SwiftFoundation/Task.swift | 14 - Sources/SwiftFoundation/Thread.swift | 2 +- Sources/SwiftFoundation/URL.swift | 174 ------ Sources/SwiftFoundation/URLClient.swift | 16 - Sources/SwiftFoundation/URLProtocol.swift | 13 - Sources/SwiftFoundation/URLRequest.swift | 14 - Sources/SwiftFoundation/URLResponse.swift | 13 - Sources/SwiftFoundation/UUID.swift | 165 ++++-- Sources/SwiftFoundation/Version.swift | 4 +- Sources/UnitTests/AtomicTests.swift | 52 -- Sources/UnitTests/SortDescriptorTests.swift | 129 ----- .../SwiftFoundation.xcodeproj/project.pbxproj | 152 +---- .../xcschemes/SwiftFoundation OS X.xcscheme | 2 +- .../xcschemes/SwiftFoundation iOS.xcscheme | 2 +- 34 files changed, 875 insertions(+), 1532 deletions(-) create mode 100644 Sources/SwiftFoundation/ComparisonResult.swift delete mode 100644 Sources/SwiftFoundation/HTTPMethod.swift delete mode 100644 Sources/SwiftFoundation/HTTPRequest.swift delete mode 100644 Sources/SwiftFoundation/HTTPResponse.swift delete mode 100644 Sources/SwiftFoundation/HTTPStatusCode.swift delete mode 100644 Sources/SwiftFoundation/HTTPVersion.swift delete mode 100644 Sources/SwiftFoundation/Order.swift delete mode 100644 Sources/SwiftFoundation/Predicate.swift delete mode 100644 Sources/SwiftFoundation/SortDescriptor.swift delete mode 100644 Sources/SwiftFoundation/Task.swift delete mode 100644 Sources/SwiftFoundation/URL.swift delete mode 100644 Sources/SwiftFoundation/URLClient.swift delete mode 100644 Sources/SwiftFoundation/URLProtocol.swift delete mode 100644 Sources/SwiftFoundation/URLRequest.swift delete mode 100644 Sources/SwiftFoundation/URLResponse.swift delete mode 100644 Sources/UnitTests/AtomicTests.swift delete mode 100644 Sources/UnitTests/SortDescriptorTests.swift diff --git a/Sources/SwiftFoundation/ComparisonResult.swift b/Sources/SwiftFoundation/ComparisonResult.swift new file mode 100644 index 0000000..97085aa --- /dev/null +++ b/Sources/SwiftFoundation/ComparisonResult.swift @@ -0,0 +1,35 @@ +// +// ComparisonResult.swift +// SwiftFoundation +// +// Created by Alsey Coleman Miller on 6/30/16. +// Copyright © 2016 PureSwift. All rights reserved. +// + +public enum ComparisonResult: Int { + + case orderedAscending = -1 + case orderedSame + case orderedDescending +} + +// MARK: - Implementation + +public extension Comparable { + + /// Compares the reciever with another and returns their order. + func compare(_ other: Self) -> ComparisonResult { + + if self < other { + + return .orderedAscending + } + + if self > other { + + return .orderedDescending + } + + return .orderedSame + } +} diff --git a/Sources/SwiftFoundation/Data.swift b/Sources/SwiftFoundation/Data.swift index 769b704..94d2cac 100644 --- a/Sources/SwiftFoundation/Data.swift +++ b/Sources/SwiftFoundation/Data.swift @@ -190,9 +190,9 @@ #endif -// MARK: - Darwin Support +// MARK: - Darwin -#if (os(OSX) || os(iOS) || os(watchOS) || os(tvOS)) +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) extension Foundation.Data: ByteValue { diff --git a/Sources/SwiftFoundation/Date.swift b/Sources/SwiftFoundation/Date.swift index 43cc2d1..138c933 100644 --- a/Sources/SwiftFoundation/Date.swift +++ b/Sources/SwiftFoundation/Date.swift @@ -12,131 +12,181 @@ import Glibc #endif -/// Represents a point in time. -public struct Date: Equatable, Comparable, CustomStringConvertible { +#if os(Linux) || XcodeLinux - // MARK: - Properties - - /// The time interval between the date and the reference date (1 January 2001, GMT). - public var sinceReferenceDate: TimeInterval - - /// The time interval between the current date and 1 January 1970, GMT. - public var since1970: TimeInterval { + /// `Date` structs represent a single point in time. + public struct Date: Equatable, Hashable, Comparable, CustomStringConvertible { - get { return sinceReferenceDate + TimeIntervalBetween1970AndReferenceDate } + // MARK: - Static Properties and Methods - set { sinceReferenceDate = since1970 - TimeIntervalBetween1970AndReferenceDate } - } - - /// Returns the difference between two dates. - public func timeIntervalSince(date: Date) -> TimeInterval { + /// The number of seconds from 1 January 1970 to the reference date, 1 January 2001. + public static let timeIntervalBetween1970AndReferenceDate = 978307200.0 - return self - date - } - - public var description: String { + /** + Creates and returns a Date value representing a date in the distant future. + + The distant future is in terms of centuries. + */ + public static let distantFuture = Date(timeIntervalSinceReferenceDate: 63113904000.0) - return "\(sinceReferenceDate)" - } - - // MARK: - Initialization - - /// Creates the date with the current time. - public init() { + /** + Creates and returns a Date value representing a date in the distant past. + + The distant past is in terms of centuries. + */ + public static let distantPast = Date(timeIntervalSinceReferenceDate: -63114076800.0) - sinceReferenceDate = TimeIntervalSinceReferenceDate() - } - - /// Creates the date with the specified time interval since the reference date (1 January 2001, GMT). - public init(sinceReferenceDate timeInterval: TimeInterval) { + /// The interval between 00:00:00 UTC on 1 January 2001 and the current date and time. + public static var timeIntervalSinceReferenceDate: TimeInterval { + + return try! timeval.timeOfDay().timeInterval - Date.timeIntervalBetween1970AndReferenceDate + } - sinceReferenceDate = timeInterval - } - - /// Creates the date with the specified time interval since 1 January 1970, GMT. - public init(since1970 timeInterval: TimeInterval) { + // MARK: - Properties + + /// The time interval between the date and the reference date (1 January 2001, GMT). + public var timeIntervalSinceReferenceDate: TimeInterval + + /// The time interval between the current date and 1 January 1970, GMT. + public var timeIntervalsince1970: TimeInterval { + + get { return timeIntervalSinceReferenceDate + Date.timeIntervalBetween1970AndReferenceDate } + + set { timeIntervalSinceReferenceDate = timeIntervalsince1970 - Date.timeIntervalBetween1970AndReferenceDate } + } - sinceReferenceDate = timeInterval - TimeIntervalBetween1970AndReferenceDate + /** + The time interval between the date and the current date and time. + + If the date is earlier than the current date and time, the this property’s value is negative. + + - SeeAlso: `timeIntervalSince(_:)` + - SeeAlso: `timeIntervalSince1970` + - SeeAlso: `timeIntervalSinceReferenceDate` + */ + public var timeIntervalSinceNow: TimeInterval { + return timeIntervalSinceReferenceDate - Date.timeIntervalSinceReferenceDate + } + + /** + The interval between the date object and 00:00:00 UTC on 1 January 1970. + + This property’s value is negative if the date object is earlier than 00:00:00 UTC on 1 January 1970. + + - SeeAlso: `timeIntervalSince(_:)` + - SeeAlso: `timeIntervalSinceNow` + - SeeAlso: `timeIntervalSinceReferenceDate` + */ + public var timeIntervalSince1970: TimeInterval { + return timeIntervalSinceReferenceDate + Date.timeIntervalBetween1970AndReferenceDate + } + + public var description: String { + + return "\(timeIntervalSinceReferenceDate)" + } + + public var hashValue: Int { + + return timeIntervalSinceReferenceDate.hashValue + } + + // MARK: - Initialization + + /// Returns a `Date` initialized to the current date and time. + public init() { + + self.timeIntervalSinceReferenceDate = Date.timeIntervalSinceReferenceDate + } + + /// Returns an `Date` initialized relative to 00:00:00 UTC on 1 January 2001 by a given number of seconds. + public init(timeIntervalSinceReferenceDate timeInterval: TimeInterval) { + + self.timeIntervalSinceReferenceDate = timeInterval + } + + /// Returns a `Date` initialized relative to the current date and time by a given number of seconds. + public init(timeIntervalSinceNow: TimeInterval) { + + self.timeIntervalSinceReferenceDate = timeIntervalSinceNow + Date.timeIntervalSinceReferenceDate + } + + /// Returns a `Date` initialized relative to 00:00:00 UTC on 1 January 1970 by a given number of seconds. + public init(timeIntervalSince1970: TimeInterval) { + + self.timeIntervalSinceReferenceDate = timeIntervalSince1970 - Date.timeIntervalBetween1970AndReferenceDate + } + + /** + Returns a `Date` initialized relative to another given date by a given number of seconds. + + - Parameter timeInterval: The number of seconds to add to `date`. A negative value means the receiver will be earlier than `date`. + - Parameter date: The reference date. + */ + public init(timeInterval: TimeInterval, since date: Date) { + + self.timeIntervalSinceReferenceDate = date.timeIntervalSinceReferenceDate + timeInterval + } + + // MARK: - Methods + + /** + Returns the interval between the receiver and another given date. + + - Parameter another: The date with which to compare the receiver. + + - Returns: The interval between the receiver and the `another` parameter. If the receiver is earlier than `anotherDate`, the return value is negative. If `anotherDate` is `nil`, the results are undefined. + + - SeeAlso: `timeIntervalSince1970` + - SeeAlso: `timeIntervalSinceNow` + - SeeAlso: `timeIntervalSinceReferenceDate` + */ + public func timeIntervalSince(_ date: Date) -> TimeInterval { + + return timeIntervalSinceReferenceDate - date.timeIntervalSinceReferenceDate + } } -} - -// MARK: - Operator Overloading - -public func == (lhs: Date, rhs: Date) -> Bool { - return lhs.sinceReferenceDate == rhs.sinceReferenceDate -} - -public func < (lhs: Date, rhs: Date) -> Bool { + // MARK: - Supporting Types - return lhs.sinceReferenceDate < rhs.sinceReferenceDate -} + /// Time interval difference between two dates, in seconds. + public typealias TimeInterval = Double -public func <= (lhs: Date, rhs: Date) -> Bool { - - return lhs.sinceReferenceDate <= rhs.sinceReferenceDate -} +#endif + +// MARK: - Operators -public func >= (lhs: Date, rhs: Date) -> Bool { +public func == (lhs: Date, rhs: Date) -> Bool { - return lhs.sinceReferenceDate >= rhs.sinceReferenceDate + return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate } -public func > (lhs: Date, rhs: Date) -> Bool { +public func < (lhs: Date, rhs: Date) -> Bool { - return lhs.sinceReferenceDate > rhs.sinceReferenceDate + return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate } public func - (lhs: Date, rhs: Date) -> TimeInterval { - return lhs.sinceReferenceDate - rhs.sinceReferenceDate + return lhs.timeIntervalSinceReferenceDate - rhs.timeIntervalSinceReferenceDate } public func + (lhs: Date, rhs: TimeInterval) -> Date { - return Date(sinceReferenceDate: lhs.sinceReferenceDate + rhs) + return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate + rhs) } -public func += (lhs: inout Date, rhs: TimeInterval) { +public func - (lhs: Date, rhs: TimeInterval) -> Date { - lhs = lhs + rhs + return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate - rhs) } -public func - (lhs: Date, rhs: TimeInterval) -> Date { +public func += (lhs: inout Date, rhs: TimeInterval) { - return Date(sinceReferenceDate: lhs.sinceReferenceDate - rhs) + lhs = lhs + rhs } public func -= (lhs: inout Date, rhs: TimeInterval) { lhs = lhs - rhs } - -// MARK: - Functions - -/// Returns the time interval between the current date and the reference date (1 January 2001, GMT). -public func TimeIntervalSinceReferenceDate() -> TimeInterval { - - return TimeIntervalSince1970() - TimeIntervalBetween1970AndReferenceDate -} - -/// Returns the time interval between the current date and 1 January 1970, GMT -public func TimeIntervalSince1970() -> TimeInterval { - - return try! timeval.timeOfDay().timeIntervalValue -} - -// MARK: - Constants - -/// Time interval difference between two dates, in seconds. -public typealias TimeInterval = Double - -/// -/// Time interval between the Unix standard reference date of 1 January 1970 and the OpenStep reference date of 1 January 2001 -/// This number comes from: -/// -/// ```(((31 years * 365 days) + 8 *(days for leap years)* */) = /* total number of days */ * 24 hours * 60 minutes * 60 seconds)``` -/// -/// - note: This ignores leap-seconds -public let TimeIntervalBetween1970AndReferenceDate: TimeInterval = 978307200.0 - diff --git a/Sources/SwiftFoundation/FileManager.swift b/Sources/SwiftFoundation/FileManager.swift index 0e198d1..3b07060 100644 --- a/Sources/SwiftFoundation/FileManager.swift +++ b/Sources/SwiftFoundation/FileManager.swift @@ -67,7 +67,7 @@ public struct FileManager { public static func changeCurrentDirectory(_ newCurrentDirectory: String) throws { guard chdir(newCurrentDirectory) == 0 - else { throw POSIXError.fromErrorNumber! } + else { throw POSIXError.fromErrno! } } /// Gets the current directory @@ -91,7 +91,7 @@ public struct FileManager { // get file descriptor for path (open file) let file = open(path, O_CREAT, DefaultFileMode) - guard file != -1 else { throw POSIXError.fromErrorNumber! } + guard file != -1 else { throw POSIXError.fromErrno! } // close file defer { guard close(file) != -1 else { fatalError("Could not close file: \(path)") } } @@ -113,12 +113,12 @@ public struct FileManager { fatalError("Create Intermediate Directories Not Implemented") } - guard mkdir(path, attributes.st_mode) == 0 else { throw POSIXError.fromErrorNumber! } + guard mkdir(path, attributes.st_mode) == 0 else { throw POSIXError.fromErrno! } } public static func removeItem(path: String) throws { - guard remove(path) == 0 else { throw POSIXError.fromErrorNumber! } + guard remove(path) == 0 else { throw POSIXError.fromErrno! } } // MARK: - Creating Symbolic and Hard Links @@ -177,7 +177,7 @@ public struct FileManager { // get file descriptor for path (open file) let file = open(path, O_RDONLY) - guard file != -1 else { throw POSIXError.fromErrorNumber! } + guard file != -1 else { throw POSIXError.fromErrno! } // close file defer { guard close(file) != -1 else { fatalError("Could not close file: \(path)") } } @@ -199,7 +199,7 @@ public struct FileManager { let readBytes = read(file, memoryPointer, fileSize) - guard readBytes != -1 else { throw POSIXError.fromErrorNumber! } + guard readBytes != -1 else { throw POSIXError.fromErrno! } //guard readBytes == fileSize else { fatalError() } @@ -214,14 +214,14 @@ public struct FileManager { // get file descriptor for path (open file) let file = open(path, O_WRONLY) - guard file != -1 else { throw POSIXError.fromErrorNumber! } + guard file != -1 else { throw POSIXError.fromErrno! } // close file defer { guard close(file) != -1 else { fatalError("Could not close file: \(path)") } } let writtenBytes = write(file, data.bytes, data.count) - guard writtenBytes != -1 else { throw POSIXError.fromErrorNumber! } + guard writtenBytes != -1 else { throw POSIXError.fromErrno! } } } diff --git a/Sources/SwiftFoundation/HTTP.swift b/Sources/SwiftFoundation/HTTP.swift index fc156a3..7d96f75 100644 --- a/Sources/SwiftFoundation/HTTP.swift +++ b/Sources/SwiftFoundation/HTTP.swift @@ -6,12 +6,527 @@ // Copyright © 2015 PureSwift. All rights reserved. // -public struct HTTP: URLProtocol { +public struct HTTP { + + /// HTTP Method. + public enum Method: String { - public static func validURL(URL: SwiftFoundation.URL) -> Bool { + case GET + case PUT + case DELETE + case POST + case OPTIONS + case HEAD + case TRACE + case CONNECT + case PATCH - guard (URL.scheme == "http" || URL.scheme == "https") else { return false } + init() { self = .GET } + } + + /// The standard status codes used with the [HTTP](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) protocol. + public enum StatusCode: Int { + + /// Initializes to 200 (OK). + public init() { self = .OK } + + // MARK: - 1xx Informational + + /// Continue + /// + /// This means that the server has received the request headers, + /// and that the client should proceed to send the request body + /// (in the case of a request for which a body needs to be sent; for example, a POST request). + /// If the request body is large, sending it to a server when a request has already been rejected + /// based upon inappropriate headers is inefficient. + /// To have a server check if the request could be accepted based on the request's headers alone, + /// a client must send Expect: 100-continue as a header in its initial request and check if a 100 + /// Continue status code is received in response before continuing + /// (or receive 417 Expectation Failed and not continue). + case Continue = 100 + + /// Switching Protocols + /// + /// This means the requester has asked the server to switch protocols and the server + /// is acknowledging that it will do so. + case SwitchingProtocols = 101 + + /// Processing (WebDAV; RFC 2518) + /// + /// As a WebDAV request may contain many sub-requests involving file operations, + /// it may take a long time to complete the request. + /// This code indicates that the server has received and is processing the request, + /// but no response is available yet. + /// This prevents the client from timing out and assuming the request was lost. + case Processing = 102 + + // MARK: - 2xx Success + + /// OK + /// + /// Standard response for successful HTTP requests. + /// The actual response will depend on the request method used. + /// In a GET request, the response will contain an entity corresponding to the requested resource. + /// In a POST request, the response will contain an entity describing or containing + /// the result of the action. + case OK = 200 + + /// Created + /// + /// The request has been fulfilled and resulted in a new resource being created. + case Created = 201 + + /// Accepted + /// + /// The request has been accepted for processing, but the processing has not been completed. + /// The request might or might not eventually be acted upon, + /// as it might be disallowed when processing actually takes place. + case Accepted = 202 + + /// Non-Authoritative Information (since HTTP/1.1) + /// + /// The server successfully processed the request, + /// but is returning information that may be from another source. + case NonAuthoritativeInformation = 203 + + /// No Content + /// + /// The server successfully processed the request, but is not returning any content. + case NoContent = 204 + + /// Reset Content + /// + /// The server successfully processed the request, but is not returning any content. + /// Unlike a 204 response, this response requires that the requester reset the document view. + case ResetContent = 205 + + /// Partial Content ([RFC 7233](https://tools.ietf.org/html/rfc7233)) + /// + /// The server is delivering only part of the resource + /// ([byte serving](https://en.wikipedia.org/wiki/Byte_serving)) due to a range header sent + /// by the client. The range header is used by HTTP clients to enable resuming of interrupted + /// downloads, or split a download into multiple simultaneous streams. + case PartialContent = 206 + + /// Multi-Status (WebDAV; RFC 4918) + /// + /// The message body that follows is an XML message and can contain a number of separate response + /// codes, depending on how many sub-requests were made. + case MultiStatus = 207 + + /// Already Reported (WebDAV; RFC 5842) + /// + /// The members of a DAV binding have already been enumerated in a previous reply to this request, + /// and are not being included again. + case AlreadyReported = 208 + + /// IM Used (RFC 3229) + /// + /// The server has fulfilled a request for the resource, and the response is a representation of the + /// result of one or more instance-manipulations applied to the current instance. + case IMUsed = 226 + + // MARK: - 3xx Redirection + + /// Multiple Choices + /// + /// Indicates multiple options for the resource that the client may follow. + /// It, for instance, could be used to present different format options for video, + /// list files with different extensions, or word sense disambiguation. + case MultipleChoices = 300 + + /// [Moved Permanently](https://en.wikipedia.org/wiki/HTTP_301) + /// + /// This and all future requests should be directed to the given URI. + case MovedPermanently = 301 + + /// [Found](https://en.wikipedia.org/wiki/HTTP_302) + /// + /// This is an example of industry practice contradicting the standard. + /// The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect + /// (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 + /// with the functionality of a 303. + /// + /// Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. + /// However, some Web applications and frameworks use the 302 status code as if it were the 303. + case Found = 302 + + /// See Other (since HTTP/1.1) + /// + /// The response to the request can be found under another URI using a GET method. + /// When received in response to a POST (or PUT/DELETE), it should be assumed that the server + /// has received the data and the redirect should be issued with a separate GET message. + case SeeOther = 303 + + /// Not Modified ([RFC 7232](https://tools.ietf.org/html/rfc7232)) + /// + /// Indicates that the resource has not been modified since the version specified by the request + /// headers If-Modified-Since or If-None-Match. + /// This means that there is no need to retransmit the resource, + /// since the client still has a previously-downloaded copy. + case NotModified = 304 + + /// Use Proxy (since HTTP/1.1) + /// + /// The requested resource is only available through a proxy, whose address is provided in the + /// response. Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle + /// responses with this status code, primarily for security reasons + case UseProxy = 305 + + /// Switch Proxy + /// + /// No longer used. Originally meant "Subsequent requests should use the specified proxy." + case SwitchProxy = 306 + + /// Temporary Redirect (since HTTP/1.1) + /// + /// In this case, the request should be repeated with another URI; + /// however, future requests should still use the original URI. + /// + /// In contrast to how 302 was historically implemented, the request method is not allowed to be + /// changed when reissuing the original request. + /// For instance, a POST request should be repeated using another POST request. + case TemporaryRedirect = 307 + + /// Permanent Redirect (RFC 7538) + /// + /// The request, and all future requests should be repeated using another URI. 307 and 308 + /// (as proposed) parallel the behaviours of 302 and 301, but do not allow the HTTP method to change. + /// So, for example, submitting a form to a permanently redirected resource may continue smoothly. + case PermanentRedirect = 308 + + // MARK: - 4xx Client Error + + /// Bad Request + /// + /// The server cannot or will not process the request due to something that is perceived to be a client + /// error (e.g., malformed request syntax, invalid request message framing, + /// or deceptive request routing) + case BadRequest = 400 + + /// Unauthorized ([RFC 7235](https://tools.ietf.org/html/rfc7235)) + /// + /// Similar to **403 Forbidden**, but specifically for use when authentication is required and has + /// failed or has not yet been provided. + /// The response must include a WWW-Authenticate header field containing + /// a challenge applicable to the requested resource. + case Unauthorized = 401 + + /// Payment Required + /// + /// Reserved for future use. + /// The original intention was that this code might be used as part of some form of digital cash or + /// micropayment scheme, but that has not happened, and this code is not usually used. + /// + /// [YouTube](youtube.com) uses this status if a particular IP address has made excessive requests, + /// and requires the person to enter a CAPTCHA. + case PaymentRequired = 402 + + /// [Forbidden](https://en.wikipedia.org/wiki/HTTP_403) + /// + /// The request was a valid request, but the server is refusing to respond to it. + /// Unlike a 401 Unauthorized response, authenticating will make no difference. + case Forbidden = 403 + + /// [Not Found](https://en.wikipedia.org/wiki/HTTP_404) + /// + /// The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible. + case NotFound = 404 + + /// Method Not Allowed + /// + /// A request was made of a resource using a request method not supported by that resource; + /// for example, using GET on a form which requires data to be presented via POST, + /// or using PUT on a read-only resource. + case MethodNotAllowed = 405 + + /// Not Acceptable + /// + /// The requested resource is only capable of generating content not acceptable according to the + /// **Accept** headers sent in the request. + case NotAcceptable = 406 + + /// Proxy Authentication Required ([RFC 7235](https://tools.ietf.org/html/rfc7235)) + /// + /// The client must first authenticate itself with the proxy. + case ProxyAuthenticationRequired = 407 + + /// Request Timeout + /// + /// The server timed out waiting for the request. According to HTTP specifications: + /// + /// "The client did not produce a request within the time that the server was prepared to wait. + /// The client MAY repeat the request without modifications at any later time." + case RequestTimeout = 408 + + /// Conflict + /// + /// Indicates that the request could not be processed because of conflict in the request, + /// such as an [edit conflict](https://en.wikipedia.org/wiki/Edit_conflict) + /// in the case of multiple updates. + case Conflict = 409 + + /// Gone + /// + /// Indicates that the resource requested is no longer available and will not be available again. + /// This should be used when a resource has been intentionally removed and the resource should be + /// purged. Upon receiving a 410 status code, the client should not request the resource again in the + /// future. Clients such as search engines should remove the resource from their indices. + /// Most use cases do not require clients and search engines to purge the resource, + /// and a **404 Not Found** may be used instead. + case Gone = 410 + + /// Length Required + /// + /// The request did not specify the length of its content, which is required by the requested resource. + case LengthRequired = 411 + + /// Precondition Failed ([RFC 7232](https://tools.ietf.org/html/rfc7232)) + /// + /// The server does not meet one of the preconditions that the requester put on the request. + case PreconditionFailed = 412 + + /// Payload Too Large ([RFC 7231](https://tools.ietf.org/html/rfc7231)) + /// + /// The request is larger than the server is willing or able to process. + /// + /// Called "Request Entity Too Large " previously. + case PayloadTooLarge = 413 + + /// Request-URI Too Long + /// + /// The URI provided was too long for the server to process. + /// Often the result of too much data being encoded as a query-string of a GET request, + /// in which case it should be converted to a POST request. + case RequestURITooLong = 414 + + /// Unsupported Media Type + /// + /// The request entity has a [media type](https://en.wikipedia.org/wiki/Internet_media_type) + /// which the server or resource does not support. + /// + /// For example, the client uploads an image as image/svg+xml, + /// but the server requires that images use a different format. + case UnsupportedMediaType = 415 + + /// Requested Range Not Satisfiable ([RFC 7233](https://tools.ietf.org/html/rfc7233)) + /// + /// The client has asked for a portion of the file + /// ([byte serving](https://en.wikipedia.org/wiki/Byte_serving)), + /// but the server cannot supply that portion. + /// + /// For example, if the client asked for a part of the file that lies beyond the end of the file. + case RequestedRangeNotSatisfiable = 416 + + /// Expectation Failed + /// + /// The server cannot meet the requirements of the **Expect** request-header field. + case ExpectationFailed = 417 + + /// I'm a teapot (RFC 2324) + /// + /// This code was defined in 1998 as one of the traditional IETF April Fools' jokes, + /// in [RFC 2324](https://tools.ietf.org/html/rfc2324), + /// [Hyper Text Coffee Pot Control Protocol](https://en.wikipedia.org/wiki/Hyper_Text_Coffee_Pot_Control_Protocol), + /// and is not expected to be implemented by actual HTTP servers. + /// + /// The RFC specifies this code should be returned by tea pots requested to brew coffee. + case Teapot = 418 + + /// Authentication Timeout (not in [RFC 2616](https://tools.ietf.org/html/rfc2616)) + /// + /// Not a part of the HTTP standard, **419 Authentication Timeout** denotes that previously valid + /// authentication has expired. It is used as an alternative to **401 Unauthorized** + /// in order to differentiate from otherwise authenticated clients being denied access to + /// specific server resources. + case AuthenticationTimeout = 419 + + /// Enhance Your Calm ([Twitter](https://en.wikipedia.org/wiki/Twitter)) + /// + /// Not part of the HTTP standard, but returned by version 1 of the Twitter Search and + /// Trends API when the client is being rate limited. + /// Other services may wish to implement the + /// [429 Too Many Requests](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#429) + /// response code instead. + case EnhanceYourCalm = 420 + + /// Misdirected Request ([HTTP/2](https://en.wikipedia.org/wiki/HTTP/2)) + /// + /// The request was directed at a server that is not able to produce a response + /// (for example because a connection reuse). + case MisdirectedRequest = 421 + + /// Unprocessable Entity (WebDAV; RFC 4918) + /// + /// The request was well-formed but was unable to be followed due to semantic errors. + case UnprocessableEntity = 422 + + /// Locked (WebDAV; RFC 4918) + /// + /// The resource that is being accessed is locked. + case Locked = 423 + + /// Failed Dependency (WebDAV; RFC 4918) + /// + /// The request failed due to failure of a previous request (e.g., a PROPPATCH). + case FailedDependency = 424 + + /// Upgrade Required + /// + /// The client should switch to a different protocol such as + /// [TLS/1.0](https://en.wikipedia.org/wiki/Transport_Layer_Security), + /// given in the [Upgrade](https://en.wikipedia.org/wiki/Upgrade_header) header field. + case UpgradeRequired = 426 + + /// Precondition Required ([RFC 6585](https://tools.ietf.org/html/rfc6585)) + /// + /// The origin server requires the request to be conditional. + /// Intended to prevent "the 'lost update' problem, where a client GETs a resource's state, + /// modifies it, and PUTs it back to the server, + /// when meanwhile a third party has modified the state on the server, leading to a conflict." + case PreconditionRequired = 428 + + /// Too Many Requests ([RFC 6585](https://tools.ietf.org/html/rfc6585)) + /// + /// The user has sent too many requests in a given amount of time. + /// Intended for use with rate limiting schemes. + case TooManyRequests + + /// Request Header Fields Too Large ([RFC 6585](https://tools.ietf.org/html/rfc6585)) + /// + /// The server is unwilling to process the request because either an individual header field, + /// or all the header fields collectively, are too large. + case RequestHeaderFieldsTooLarge = 431 + + /// Login Timeout (Microsoft) + /// + /// A Microsoft extension. Indicates that your session has expired. + case LoginTimeout = 440 + + /// No Response (Nginx) + /// + /// Used in Nginx logs to indicate that the server has returned no information to the client + /// and closed the connection (useful as a deterrent for malware). + case NoResponse = 444 + + /// Retry With (Microsoft) + /// + /// A Microsoft extension. The request should be retried after performing the appropriate action. + case RetryWith = 449 + + /// Blocked by Windows Parental Controls (Microsoft) + /// + /// A Microsoft extension. + /// This error is given when Windows Parental Controls are turned on and are + /// blocking access to the given webpage. + case BlockedByParentalControls = 450 + + /// [Unavailable For Legal Reasons](https://en.wikipedia.org/wiki/HTTP_451) (Internet draft) + /// + /// Defined in the internet draft "A New HTTP Status Code for Legally-restricted Resources". + /// Intended to be used when resource access is denied for legal reasons, + /// e.g. censorship or government-mandated blocked access. + /// A reference to the 1953 dystopian novel Fahrenheit 451, where books are outlawed. + case UnavailableForLegalReasons = 451 + + /// Request Header Too Large (Nginx) + /// + /// Nginx internal code similar to 431 but it was introduced earlier in version 0.9.4 + /// (on January 21, 2011). + case RequestHeaderTooLarge = 494 + + /// Cert Error (Nginx) + /// + /// Nginx internal code used when SSL client certificate error occurred to distinguish it + /// from 4XX in a log and an error page redirection. + case CertError = 495 + + // MARK: - 5xx Server Error + + /// Internal Server Error + /// + /// A generic error message, given when an unexpected condition was encountered and + /// no more specific message is suitable. + case InternalServerError = 500 + + /// Not Implemented + /// + /// The server either does not recognize the request method, + /// or it lacks the ability to fulfill the request. + /// Usually this implies future availability (e.g., a new feature of a web-service API). + case NotImplemented = 501 + + /// Bad Gateway + /// + /// The server was acting as a gateway or proxy and received an invalid response + /// from the upstream server. + case BadGateway = 502 + + /// Service Unavailable + /// + /// The server is currently unavailable (because it is overloaded or down for maintenance). + /// Generally, this is a temporary state. + case ServiceUnavailable = 503 + + /// Gateway Timeout + /// + /// The server was acting as a gateway or proxy and did not receive a timely response + /// from the upstream server. + case GatewayTimeout = 504 + + /// Version Not Supported + /// + /// The server does not support the HTTP protocol version used in the request. + case VersionNotSupported = 505 + + /// Variant Also Negotiates (RFC 2295) + /// + /// Transparent content negotiation for the request results in a circular reference. + case VariantAlsoNegotiates = 506 + + /// Insufficient Storage (WebDAV; RFC 4918) + /// + /// The server is unable to store the representation needed to complete the request. + case InsufficientStorage = 507 + + /// Loop Detected (WebDAV; RFC 5842) + /// + /// The server detected an infinite loop while processing the request (sent in lieu of + /// [208 Already Reported](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#208)). + case LoopDetected = 508 + + /// Bandwidth Limit Exceeded (Apache bw/limited extension) + /// + /// This status code is not specified in any RFCs. Its use is unknown. + case BandwidthLimitExceeded = 509 + + /// Not Extended (RFC 2774) + /// + /// Further extensions to the request are required for the server to fulfil it. + case NotExtended = 510 + + /// Network Authentication Required ([RFC 6585](https://tools.ietf.org/html/rfc6585)) + /// + /// The client needs to authenticate to gain network access. + /// Intended for use by intercepting proxies used to control access to the network + /// (e.g., "captive portals" used to require agreement to Terms of Service before granting + /// full Internet access via a Wi-Fi hotspot). + case NetworkAuthenticationRequired = 511 + + /// Unknown Error + /// + /// This status code is not specified in any RFC and is returned by certain services, + /// for instance Microsoft Azure and CloudFlare servers: + /// + /// "The 520 error is essentially a “catch-all” response for when the origin server returns something + /// unexpected or something that is not tolerated/interpreted (protocol violation or empty response)." + case UnknownError = 520 + + /// Origin Connection Time-out + /// + /// This status code is not specified in any RFCs, + /// but is used by CloudFlare's reverse proxies to signal that a server connection timed out. + case OriginConnectionTimeOut = 522 - return true } } diff --git a/Sources/SwiftFoundation/HTTPMethod.swift b/Sources/SwiftFoundation/HTTPMethod.swift deleted file mode 100644 index 5b47f53..0000000 --- a/Sources/SwiftFoundation/HTTPMethod.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// HTTPMethod.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public extension HTTP { - - /// HTTP Method. - public enum Method: String { - - case GET - case PUT - case DELETE - case POST - case OPTIONS - case HEAD - case TRACE - case CONNECT - case PATCH - - init() { self = .GET } - } -} - diff --git a/Sources/SwiftFoundation/HTTPRequest.swift b/Sources/SwiftFoundation/HTTPRequest.swift deleted file mode 100644 index cd15c15..0000000 --- a/Sources/SwiftFoundation/HTTPRequest.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// HTTPRequest.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public extension HTTP { - - /// HTTP request. - public struct Request: URLRequest { - - public var URL: String - - public var timeoutInterval: TimeInterval = 30 - - public var body: Data? - - public var headers = [String: String]() - - public var method: HTTP.Method = .GET - - public var version: HTTP.Version = HTTP.Version() - - public init(URL: String) { - - self.URL = URL - } - } -} - diff --git a/Sources/SwiftFoundation/HTTPResponse.swift b/Sources/SwiftFoundation/HTTPResponse.swift deleted file mode 100644 index 4131380..0000000 --- a/Sources/SwiftFoundation/HTTPResponse.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// HTTPResponse.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public extension HTTP { - - /// HTTP URL response. - public struct Response: URLResponse { - - /// Returns a dictionary containing all the HTTP header fields. - public var headers = [String: String]() - - /// Returns the HTTP status code for the response. - public var statusCode: Int = HTTP.StatusCode.OK.rawValue - - /// The HTTP response body. - public var body = Data() - - public init() { } - } -} - diff --git a/Sources/SwiftFoundation/HTTPStatusCode.swift b/Sources/SwiftFoundation/HTTPStatusCode.swift deleted file mode 100644 index d3293c9..0000000 --- a/Sources/SwiftFoundation/HTTPStatusCode.swift +++ /dev/null @@ -1,517 +0,0 @@ -// -// HTTPStatusCode.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public extension HTTP { - - /// The standard status codes used with the [HTTP](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) protocol. - public enum StatusCode: Int { - - /// Initializes to 200. - public init() { self = .OK } - - // MARK: - 1xx Informational - - /// Continue - /// - /// This means that the server has received the request headers, - /// and that the client should proceed to send the request body - /// (in the case of a request for which a body needs to be sent; for example, a POST request). - /// If the request body is large, sending it to a server when a request has already been rejected - /// based upon inappropriate headers is inefficient. - /// To have a server check if the request could be accepted based on the request's headers alone, - /// a client must send Expect: 100-continue as a header in its initial request and check if a 100 - /// Continue status code is received in response before continuing - /// (or receive 417 Expectation Failed and not continue). - case Continue = 100 - - /// Switching Protocols - /// - /// This means the requester has asked the server to switch protocols and the server - /// is acknowledging that it will do so. - case SwitchingProtocols = 101 - - /// Processing (WebDAV; RFC 2518) - /// - /// As a WebDAV request may contain many sub-requests involving file operations, - /// it may take a long time to complete the request. - /// This code indicates that the server has received and is processing the request, - /// but no response is available yet. - /// This prevents the client from timing out and assuming the request was lost. - case Processing = 102 - - // MARK: - 2xx Success - - /// OK - /// - /// Standard response for successful HTTP requests. - /// The actual response will depend on the request method used. - /// In a GET request, the response will contain an entity corresponding to the requested resource. - /// In a POST request, the response will contain an entity describing or containing - /// the result of the action. - case OK = 200 - - /// Created - /// - /// The request has been fulfilled and resulted in a new resource being created. - case Created = 201 - - /// Accepted - /// - /// The request has been accepted for processing, but the processing has not been completed. - /// The request might or might not eventually be acted upon, - /// as it might be disallowed when processing actually takes place. - case Accepted = 202 - - /// Non-Authoritative Information (since HTTP/1.1) - /// - /// The server successfully processed the request, - /// but is returning information that may be from another source. - case NonAuthoritativeInformation = 203 - - /// No Content - /// - /// The server successfully processed the request, but is not returning any content. - case NoContent = 204 - - /// Reset Content - /// - /// The server successfully processed the request, but is not returning any content. - /// Unlike a 204 response, this response requires that the requester reset the document view. - case ResetContent = 205 - - /// Partial Content ([RFC 7233](https://tools.ietf.org/html/rfc7233)) - /// - /// The server is delivering only part of the resource - /// ([byte serving](https://en.wikipedia.org/wiki/Byte_serving)) due to a range header sent - /// by the client. The range header is used by HTTP clients to enable resuming of interrupted - /// downloads, or split a download into multiple simultaneous streams. - case PartialContent = 206 - - /// Multi-Status (WebDAV; RFC 4918) - /// - /// The message body that follows is an XML message and can contain a number of separate response - /// codes, depending on how many sub-requests were made. - case MultiStatus = 207 - - /// Already Reported (WebDAV; RFC 5842) - /// - /// The members of a DAV binding have already been enumerated in a previous reply to this request, - /// and are not being included again. - case AlreadyReported = 208 - - /// IM Used (RFC 3229) - /// - /// The server has fulfilled a request for the resource, and the response is a representation of the - /// result of one or more instance-manipulations applied to the current instance. - case IMUsed = 226 - - // MARK: - 3xx Redirection - - /// Multiple Choices - /// - /// Indicates multiple options for the resource that the client may follow. - /// It, for instance, could be used to present different format options for video, - /// list files with different extensions, or word sense disambiguation. - case MultipleChoices = 300 - - /// [Moved Permanently](https://en.wikipedia.org/wiki/HTTP_301) - /// - /// This and all future requests should be directed to the given URI. - case MovedPermanently = 301 - - /// [Found](https://en.wikipedia.org/wiki/HTTP_302) - /// - /// This is an example of industry practice contradicting the standard. - /// The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect - /// (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 - /// with the functionality of a 303. - /// - /// Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. - /// However, some Web applications and frameworks use the 302 status code as if it were the 303. - case Found = 302 - - /// See Other (since HTTP/1.1) - /// - /// The response to the request can be found under another URI using a GET method. - /// When received in response to a POST (or PUT/DELETE), it should be assumed that the server - /// has received the data and the redirect should be issued with a separate GET message. - case SeeOther = 303 - - /// Not Modified ([RFC 7232](https://tools.ietf.org/html/rfc7232)) - /// - /// Indicates that the resource has not been modified since the version specified by the request - /// headers If-Modified-Since or If-None-Match. - /// This means that there is no need to retransmit the resource, - /// since the client still has a previously-downloaded copy. - case NotModified = 304 - - /// Use Proxy (since HTTP/1.1) - /// - /// The requested resource is only available through a proxy, whose address is provided in the - /// response. Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle - /// responses with this status code, primarily for security reasons - case UseProxy = 305 - - /// Switch Proxy - /// - /// No longer used. Originally meant "Subsequent requests should use the specified proxy." - case SwitchProxy = 306 - - /// Temporary Redirect (since HTTP/1.1) - /// - /// In this case, the request should be repeated with another URI; - /// however, future requests should still use the original URI. - /// - /// In contrast to how 302 was historically implemented, the request method is not allowed to be - /// changed when reissuing the original request. - /// For instance, a POST request should be repeated using another POST request. - case TemporaryRedirect = 307 - - /// Permanent Redirect (RFC 7538) - /// - /// The request, and all future requests should be repeated using another URI. 307 and 308 - /// (as proposed) parallel the behaviours of 302 and 301, but do not allow the HTTP method to change. - /// So, for example, submitting a form to a permanently redirected resource may continue smoothly. - case PermanentRedirect = 308 - - // MARK: - 4xx Client Error - - /// Bad Request - /// - /// The server cannot or will not process the request due to something that is perceived to be a client - /// error (e.g., malformed request syntax, invalid request message framing, - /// or deceptive request routing) - case BadRequest = 400 - - /// Unauthorized ([RFC 7235](https://tools.ietf.org/html/rfc7235)) - /// - /// Similar to **403 Forbidden**, but specifically for use when authentication is required and has - /// failed or has not yet been provided. - /// The response must include a WWW-Authenticate header field containing - /// a challenge applicable to the requested resource. - case Unauthorized = 401 - - /// Payment Required - /// - /// Reserved for future use. - /// The original intention was that this code might be used as part of some form of digital cash or - /// micropayment scheme, but that has not happened, and this code is not usually used. - /// - /// [YouTube](youtube.com) uses this status if a particular IP address has made excessive requests, - /// and requires the person to enter a CAPTCHA. - case PaymentRequired = 402 - - /// [Forbidden](https://en.wikipedia.org/wiki/HTTP_403) - /// - /// The request was a valid request, but the server is refusing to respond to it. - /// Unlike a 401 Unauthorized response, authenticating will make no difference. - case Forbidden = 403 - - /// [Not Found](https://en.wikipedia.org/wiki/HTTP_404) - /// - /// The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible. - case NotFound = 404 - - /// Method Not Allowed - /// - /// A request was made of a resource using a request method not supported by that resource; - /// for example, using GET on a form which requires data to be presented via POST, - /// or using PUT on a read-only resource. - case MethodNotAllowed = 405 - - /// Not Acceptable - /// - /// The requested resource is only capable of generating content not acceptable according to the - /// **Accept** headers sent in the request. - case NotAcceptable = 406 - - /// Proxy Authentication Required ([RFC 7235](https://tools.ietf.org/html/rfc7235)) - /// - /// The client must first authenticate itself with the proxy. - case ProxyAuthenticationRequired = 407 - - /// Request Timeout - /// - /// The server timed out waiting for the request. According to HTTP specifications: - /// - /// "The client did not produce a request within the time that the server was prepared to wait. - /// The client MAY repeat the request without modifications at any later time." - case RequestTimeout = 408 - - /// Conflict - /// - /// Indicates that the request could not be processed because of conflict in the request, - /// such as an [edit conflict](https://en.wikipedia.org/wiki/Edit_conflict) - /// in the case of multiple updates. - case Conflict = 409 - - /// Gone - /// - /// Indicates that the resource requested is no longer available and will not be available again. - /// This should be used when a resource has been intentionally removed and the resource should be - /// purged. Upon receiving a 410 status code, the client should not request the resource again in the - /// future. Clients such as search engines should remove the resource from their indices. - /// Most use cases do not require clients and search engines to purge the resource, - /// and a **404 Not Found** may be used instead. - case Gone = 410 - - /// Length Required - /// - /// The request did not specify the length of its content, which is required by the requested resource. - case LengthRequired = 411 - - /// Precondition Failed ([RFC 7232](https://tools.ietf.org/html/rfc7232)) - /// - /// The server does not meet one of the preconditions that the requester put on the request. - case PreconditionFailed = 412 - - /// Payload Too Large ([RFC 7231](https://tools.ietf.org/html/rfc7231)) - /// - /// The request is larger than the server is willing or able to process. - /// - /// Called "Request Entity Too Large " previously. - case PayloadTooLarge = 413 - - /// Request-URI Too Long - /// - /// The URI provided was too long for the server to process. - /// Often the result of too much data being encoded as a query-string of a GET request, - /// in which case it should be converted to a POST request. - case RequestURITooLong = 414 - - /// Unsupported Media Type - /// - /// The request entity has a [media type](https://en.wikipedia.org/wiki/Internet_media_type) - /// which the server or resource does not support. - /// - /// For example, the client uploads an image as image/svg+xml, - /// but the server requires that images use a different format. - case UnsupportedMediaType = 415 - - /// Requested Range Not Satisfiable ([RFC 7233](https://tools.ietf.org/html/rfc7233)) - /// - /// The client has asked for a portion of the file - /// ([byte serving](https://en.wikipedia.org/wiki/Byte_serving)), - /// but the server cannot supply that portion. - /// - /// For example, if the client asked for a part of the file that lies beyond the end of the file. - case RequestedRangeNotSatisfiable = 416 - - /// Expectation Failed - /// - /// The server cannot meet the requirements of the **Expect** request-header field. - case ExpectationFailed = 417 - - /// I'm a teapot (RFC 2324) - /// - /// This code was defined in 1998 as one of the traditional IETF April Fools' jokes, - /// in [RFC 2324](https://tools.ietf.org/html/rfc2324), - /// [Hyper Text Coffee Pot Control Protocol](https://en.wikipedia.org/wiki/Hyper_Text_Coffee_Pot_Control_Protocol), - /// and is not expected to be implemented by actual HTTP servers. - /// - /// The RFC specifies this code should be returned by tea pots requested to brew coffee. - case Teapot = 418 - - /// Authentication Timeout (not in [RFC 2616](https://tools.ietf.org/html/rfc2616)) - /// - /// Not a part of the HTTP standard, **419 Authentication Timeout** denotes that previously valid - /// authentication has expired. It is used as an alternative to **401 Unauthorized** - /// in order to differentiate from otherwise authenticated clients being denied access to - /// specific server resources. - case AuthenticationTimeout = 419 - - /// Enhance Your Calm ([Twitter](https://en.wikipedia.org/wiki/Twitter)) - /// - /// Not part of the HTTP standard, but returned by version 1 of the Twitter Search and - /// Trends API when the client is being rate limited. - /// Other services may wish to implement the - /// [429 Too Many Requests](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#429) - /// response code instead. - case EnhanceYourCalm = 420 - - /// Misdirected Request ([HTTP/2](https://en.wikipedia.org/wiki/HTTP/2)) - /// - /// The request was directed at a server that is not able to produce a response - /// (for example because a connection reuse). - case MisdirectedRequest = 421 - - /// Unprocessable Entity (WebDAV; RFC 4918) - /// - /// The request was well-formed but was unable to be followed due to semantic errors. - case UnprocessableEntity = 422 - - /// Locked (WebDAV; RFC 4918) - /// - /// The resource that is being accessed is locked. - case Locked = 423 - - /// Failed Dependency (WebDAV; RFC 4918) - /// - /// The request failed due to failure of a previous request (e.g., a PROPPATCH). - case FailedDependency = 424 - - /// Upgrade Required - /// - /// The client should switch to a different protocol such as - /// [TLS/1.0](https://en.wikipedia.org/wiki/Transport_Layer_Security), - /// given in the [Upgrade](https://en.wikipedia.org/wiki/Upgrade_header) header field. - case UpgradeRequired = 426 - - /// Precondition Required ([RFC 6585](https://tools.ietf.org/html/rfc6585)) - /// - /// The origin server requires the request to be conditional. - /// Intended to prevent "the 'lost update' problem, where a client GETs a resource's state, - /// modifies it, and PUTs it back to the server, - /// when meanwhile a third party has modified the state on the server, leading to a conflict." - case PreconditionRequired = 428 - - /// Too Many Requests ([RFC 6585](https://tools.ietf.org/html/rfc6585)) - /// - /// The user has sent too many requests in a given amount of time. - /// Intended for use with rate limiting schemes. - case TooManyRequests - - /// Request Header Fields Too Large ([RFC 6585](https://tools.ietf.org/html/rfc6585)) - /// - /// The server is unwilling to process the request because either an individual header field, - /// or all the header fields collectively, are too large. - case RequestHeaderFieldsTooLarge = 431 - - /// Login Timeout (Microsoft) - /// - /// A Microsoft extension. Indicates that your session has expired. - case LoginTimeout = 440 - - /// No Response (Nginx) - /// - /// Used in Nginx logs to indicate that the server has returned no information to the client - /// and closed the connection (useful as a deterrent for malware). - case NoResponse = 444 - - /// Retry With (Microsoft) - /// - /// A Microsoft extension. The request should be retried after performing the appropriate action. - case RetryWith = 449 - - /// Blocked by Windows Parental Controls (Microsoft) - /// - /// A Microsoft extension. - /// This error is given when Windows Parental Controls are turned on and are - /// blocking access to the given webpage. - case BlockedByParentalControls = 450 - - /// [Unavailable For Legal Reasons](https://en.wikipedia.org/wiki/HTTP_451) (Internet draft) - /// - /// Defined in the internet draft "A New HTTP Status Code for Legally-restricted Resources". - /// Intended to be used when resource access is denied for legal reasons, - /// e.g. censorship or government-mandated blocked access. - /// A reference to the 1953 dystopian novel Fahrenheit 451, where books are outlawed. - case UnavailableForLegalReasons = 451 - - /// Request Header Too Large (Nginx) - /// - /// Nginx internal code similar to 431 but it was introduced earlier in version 0.9.4 - /// (on January 21, 2011). - case RequestHeaderTooLarge = 494 - - /// Cert Error (Nginx) - /// - /// Nginx internal code used when SSL client certificate error occurred to distinguish it - /// from 4XX in a log and an error page redirection. - case CertError = 495 - - // MARK: - 5xx Server Error - - /// Internal Server Error - /// - /// A generic error message, given when an unexpected condition was encountered and - /// no more specific message is suitable. - case InternalServerError = 500 - - /// Not Implemented - /// - /// The server either does not recognize the request method, - /// or it lacks the ability to fulfill the request. - /// Usually this implies future availability (e.g., a new feature of a web-service API). - case NotImplemented = 501 - - /// Bad Gateway - /// - /// The server was acting as a gateway or proxy and received an invalid response - /// from the upstream server. - case BadGateway = 502 - - /// Service Unavailable - /// - /// The server is currently unavailable (because it is overloaded or down for maintenance). - /// Generally, this is a temporary state. - case ServiceUnavailable = 503 - - /// Gateway Timeout - /// - /// The server was acting as a gateway or proxy and did not receive a timely response - /// from the upstream server. - case GatewayTimeout = 504 - - /// Version Not Supported - /// - /// The server does not support the HTTP protocol version used in the request. - case VersionNotSupported = 505 - - /// Variant Also Negotiates (RFC 2295) - /// - /// Transparent content negotiation for the request results in a circular reference. - case VariantAlsoNegotiates = 506 - - /// Insufficient Storage (WebDAV; RFC 4918) - /// - /// The server is unable to store the representation needed to complete the request. - case InsufficientStorage = 507 - - /// Loop Detected (WebDAV; RFC 5842) - /// - /// The server detected an infinite loop while processing the request (sent in lieu of - /// [208 Already Reported](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#208)). - case LoopDetected = 508 - - /// Bandwidth Limit Exceeded (Apache bw/limited extension) - /// - /// This status code is not specified in any RFCs. Its use is unknown. - case BandwidthLimitExceeded = 509 - - /// Not Extended (RFC 2774) - /// - /// Further extensions to the request are required for the server to fulfil it. - case NotExtended = 510 - - /// Network Authentication Required ([RFC 6585](https://tools.ietf.org/html/rfc6585)) - /// - /// The client needs to authenticate to gain network access. - /// Intended for use by intercepting proxies used to control access to the network - /// (e.g., "captive portals" used to require agreement to Terms of Service before granting - /// full Internet access via a Wi-Fi hotspot). - case NetworkAuthenticationRequired = 511 - - /// Unknown Error - /// - /// This status code is not specified in any RFC and is returned by certain services, - /// for instance Microsoft Azure and CloudFlare servers: - /// - /// "The 520 error is essentially a “catch-all” response for when the origin server returns something - /// unexpected or something that is not tolerated/interpreted (protocol violation or empty response)." - case UnknownError = 520 - - /// Origin Connection Time-out - /// - /// This status code is not specified in any RFCs, - /// but is used by CloudFlare's reverse proxies to signal that a server connection timed out. - case OriginConnectionTimeOut = 522 - - } -} - diff --git a/Sources/SwiftFoundation/HTTPVersion.swift b/Sources/SwiftFoundation/HTTPVersion.swift deleted file mode 100644 index d9c9b56..0000000 --- a/Sources/SwiftFoundation/HTTPVersion.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// HTTPVersion.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public extension HTTP { - - /// Defines the HTTP protocol version. - public struct Version { - - public typealias ValueType = UInt8 - - /// Major version number. - public var major: ValueType - - /// Minor version number. - public var minor: ValueType - - /// Defualts to HTTP 1.1 - public init(_ major: ValueType = 1, _ minor: ValueType = 1) { - - self.major = major - self.minor = minor - } - } -} - -public func == (lhs: HTTP.Version, rhs: HTTP.Version) -> Bool { - - return lhs.major == rhs.major && lhs.minor == rhs.minor -} - diff --git a/Sources/SwiftFoundation/Hash.swift b/Sources/SwiftFoundation/Hash.swift index 577551c..83d5796 100644 --- a/Sources/SwiftFoundation/Hash.swift +++ b/Sources/SwiftFoundation/Hash.swift @@ -6,6 +6,7 @@ // Copyright © 2016 PureSwift. All rights reserved. // +/// Function for hashing data. public func Hash(_ data: Data) -> Int { // more expensive than casting but that's not safe for large values. diff --git a/Sources/SwiftFoundation/Null.swift b/Sources/SwiftFoundation/Null.swift index c063ce2..6bf8861 100644 --- a/Sources/SwiftFoundation/Null.swift +++ b/Sources/SwiftFoundation/Null.swift @@ -6,7 +6,7 @@ // Copyright © 2015 PureSwift. All rights reserved. // -/** An OOP placeholder for ```nil```. */ +/// An OOP placeholder for ```nil``` in collections. public struct Null: CustomStringConvertible, Equatable { public var description: String { return "Null" } @@ -16,7 +16,7 @@ public struct Null: CustomStringConvertible, Equatable { // MARK: - Operator Overloading -public func ==(lhs: Null, rhs: Null) -> Bool { +public func == (lhs: Null, rhs: Null) -> Bool { return true -} \ No newline at end of file +} diff --git a/Sources/SwiftFoundation/Order.swift b/Sources/SwiftFoundation/Order.swift deleted file mode 100644 index 731270b..0000000 --- a/Sources/SwiftFoundation/Order.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// Order.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Indicates how items are ordered. -public enum Order: Int { - - case ascending = -1 - case same = 0 - case descending = 1 -} - -// MARK: - Implementation - -public extension Comparable { - - /** Compares the reciever with another and returns their order. */ - func compare(_ other: Self) -> Order { - - if self < other { - - return .ascending - } - - if self > other { - - return .descending - } - - return .same - } -} - diff --git a/Sources/SwiftFoundation/POSIXError.swift b/Sources/SwiftFoundation/POSIXError.swift index eff8a7d..adaf7aa 100644 --- a/Sources/SwiftFoundation/POSIXError.swift +++ b/Sources/SwiftFoundation/POSIXError.swift @@ -15,7 +15,7 @@ public extension POSIXError { /// Creates error from C ```errno```. - static var fromErrorNumber: POSIXError? { return self.init(rawValue: errno) } + static var fromErrno: POSIXError? { return self.init(rawValue: errno) } } #if os(Linux) @@ -27,6 +27,9 @@ public extension POSIXError { public init?(rawValue: CInt) { + guard rawValue != 0 + else { return nil } + self = .Value(rawValue) } diff --git a/Sources/SwiftFoundation/POSIXFileStatus.swift b/Sources/SwiftFoundation/POSIXFileStatus.swift index ff5c697..79a3de4 100644 --- a/Sources/SwiftFoundation/POSIXFileStatus.swift +++ b/Sources/SwiftFoundation/POSIXFileStatus.swift @@ -23,7 +23,7 @@ public extension stat { guard stat(path, &fileStatus) == 0 else { - throw POSIXError.fromErrorNumber! + throw POSIXError.fromErrno! } self = fileStatus diff --git a/Sources/SwiftFoundation/POSIXFileSystemStatus.swift b/Sources/SwiftFoundation/POSIXFileSystemStatus.swift index d6fc462..c48c5b9 100644 --- a/Sources/SwiftFoundation/POSIXFileSystemStatus.swift +++ b/Sources/SwiftFoundation/POSIXFileSystemStatus.swift @@ -23,7 +23,7 @@ public extension statfs { guard statfs(path, &fileSystemStatus) == 0 else { - throw POSIXError.fromErrorNumber! + throw POSIXError.fromErrno! } self = fileSystemStatus diff --git a/Sources/SwiftFoundation/POSIXTime.swift b/Sources/SwiftFoundation/POSIXTime.swift index 8610a3b..8828012 100644 --- a/Sources/SwiftFoundation/POSIXTime.swift +++ b/Sources/SwiftFoundation/POSIXTime.swift @@ -18,10 +18,8 @@ public extension timeval { var timeStamp = timeval() - guard gettimeofday(&timeStamp, nil) == 0 else { - - throw POSIXError.fromErrorNumber! - } + guard gettimeofday(&timeStamp, nil) == 0 + else { throw POSIXError.fromErrno! } return timeStamp } @@ -37,7 +35,7 @@ public extension timeval { self.init(tv_sec: Int(integerValue), tv_usec: POSIXMicroseconds(microseconds)) } - var timeIntervalValue: TimeInterval { + var timeInterval: TimeInterval { let secondsSince1970 = TimeInterval(self.tv_sec) @@ -62,7 +60,7 @@ public extension timespec { self.init(tv_sec: Int(integerValue), tv_nsec: Int(nanoseconds)) } - var timeIntervalValue: TimeInterval { + var timeInterval: TimeInterval { let secondsSince1970 = TimeInterval(self.tv_sec) diff --git a/Sources/SwiftFoundation/Predicate.swift b/Sources/SwiftFoundation/Predicate.swift deleted file mode 100644 index c07b18a..0000000 --- a/Sources/SwiftFoundation/Predicate.swift +++ /dev/null @@ -1,40 +0,0 @@ -// -// Predicate.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Defines logical conditions used to constrain a search either for a fetch or for in-memory filtering. -/// -public protocol Predicate { - - /// Returns a Boolean value that indicates whether a given object matches the conditions specified by the predicate. - /// - func evaluate(_ object: T) -> Bool -} - -public extension Collection { - - func filter(predicate: Predicate) -> [Self.Iterator.Element] { - - return self.filter({ (element: Self.Iterator.Element) -> Bool in - - return predicate.evaluate(element) - }) - } -} - -/* -public extension Sequence { - - public func contains(predicate: Predicate -> Bool) -> Bool { - - return self.contains({ (element: Self.Iterator.Element) -> Bool in - - return predicate.evaluate(element) - }) - } -} -*/ \ No newline at end of file diff --git a/Sources/SwiftFoundation/SemanticVersion.swift b/Sources/SwiftFoundation/SemanticVersion.swift index 5ea7324..5670951 100644 --- a/Sources/SwiftFoundation/SemanticVersion.swift +++ b/Sources/SwiftFoundation/SemanticVersion.swift @@ -6,32 +6,28 @@ // Copyright © 2015 PureSwift. All rights reserved. // -// MARK: - Protocol +// MARK: - Implementation -public protocol SemanticVersionType: RawRepresentable, CustomStringConvertible { +public struct SemanticVersion: Equatable, RawRepresentable, CustomStringConvertible { - var mayor: UInt { get } + // MARK: - Properties - var minor: UInt { get } + public var major: UInt - var patch: UInt { get } -} - -// MARK: - Protocol Implementation - -public extension SemanticVersionType { + public var minor: UInt - var rawValue: String { - - return "\(mayor).\(minor).\(patch)" - } + public var patch: UInt - var description: String { + // MARK: - Initialization + + public init(major: UInt, minor: UInt, patch: UInt) { - return rawValue + self.major = major + self.minor = minor + self.patch = patch } - init?(rawValue: String) { + public init?(rawValue: String) { // TODO: Implement RawRespresentable Initializer @@ -39,24 +35,25 @@ public extension SemanticVersionType { return nil } -} - -// MARK: - Implementation - -public struct SemanticVersion: SemanticVersionType { - - // MARK: - Properties - - public let mayor: UInt - public let minor: UInt + // MARK: - Accessors - public let patch: UInt + public var rawValue: String { + + return "\(major).\(minor).\(patch)" + } - public init(mayor: UInt, minor: UInt, patch: UInt) { + public var description: String { - self.mayor = mayor - self.minor = minor - self.patch = patch + return rawValue } -} \ No newline at end of file +} + +// MARK: - Equatable + +public func == (lhs: SemanticVersion, rhs: SemanticVersion) -> Bool { + + return lhs.major == rhs.major + && lhs.minor == rhs.minor + && lhs.patch == rhs.patch +} diff --git a/Sources/SwiftFoundation/SortDescriptor.swift b/Sources/SwiftFoundation/SortDescriptor.swift deleted file mode 100644 index 73640cf..0000000 --- a/Sources/SwiftFoundation/SortDescriptor.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// SortDescriptor.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -// MARK: - Protocol - -/// Describes a basis for ordering types. -public protocol SortDescriptor { - - associatedtype Sorted - - var ascending: Bool { get } - - /** Compares two types and gets their order. */ - func sort(first: Sorted, second: Sorted) -> Order -} - -public extension Collection { - - /// Returns a sorted array of the collection as specified by the sort descriptor. - func sorted(_ sortDescriptor: S) -> [Iterator.Element] { - - return self.sorted { (first: Iterator.Element, second: Iterator.Element) -> Bool in - - let order = sortDescriptor.sort(first: first, second: second) - - switch order { - - case .ascending: return sortDescriptor.ascending - - case .descending: return !sortDescriptor.ascending - - case .same: return true - - } - } - } -} diff --git a/Sources/SwiftFoundation/Task.swift b/Sources/SwiftFoundation/Task.swift deleted file mode 100644 index dff809b..0000000 --- a/Sources/SwiftFoundation/Task.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// Task.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Class for executing a process. -@available (OSX 10.9, *) // Not Availible on iOS -final public class Task { - - -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 0f8b71b..e8d4fe7 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -34,7 +34,7 @@ public final class Thread { #endif guard pthread_create(&internalThread, nil, ThreadPrivateMain, pointer) == 0 - else { throw POSIXError.fromErrorNumber! } + else { throw POSIXError.fromErrno! } #if os(Linux) self.internalThread = internalThread diff --git a/Sources/SwiftFoundation/URL.swift b/Sources/SwiftFoundation/URL.swift deleted file mode 100644 index 0f72cfd..0000000 --- a/Sources/SwiftFoundation/URL.swift +++ /dev/null @@ -1,174 +0,0 @@ -// -// URL.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Encapsulates the components of an URL. -public struct URL: CustomStringConvertible { - - // MARK: - Properties - - public var scheme: String - - public var user: String? - - public var password: String? - - /// The host URL subcomponent (e.g. domain name, IP address) - public var host: String? - - public var port: UInt? - - public var path: String? - - public var query: [(String, String)]? - - /// The fragment URL component (the part after a # symbol) - public var fragment: String? - - // MARK: - Initialization - - public init(scheme: String) { - - self.scheme = scheme - } - - /// Creates an instance from the string. String must be a valid URL. - public init?(stringValue: String) { - - // parse string - - debugPrint("URL parsing from string is not implemented yet!") - - return nil - } - - // MARK: - Generated Properties - - /// Whether the URL components form a valid URL - public var valid: Bool { - - // validate scheme - - // host must exist for port to be specified - if port != nil { guard host != nil else { return false } } - - // user and password must both be nil or non-nil - guard !((user != nil || password != nil) && (user == nil || password == nil)) else { return false } - - // query must have at least one item - if query != nil { guard query!.count > 0 else { return false } } - - return true - } - - /// Returns a valid URL string or ```nil``` - public var URLString: String? { - - guard self.valid else { return nil } - - var stringValue = scheme + "://" - - if let user = user { stringValue += user } - - if let password = password { stringValue += ":\(password)"} - - if user != nil { stringValue += "@" } - - if let host = host { stringValue += host } - - if let port = port { stringValue += ":\(port)" } - - if let path = path { stringValue += "/\(path)" } - - if let query = query { - - stringValue += "?" - - for (index, queryItem) in query.enumerated() { - - let (name, value) = queryItem - - stringValue += name + "=" + value - - if index != query.count - 1 { - - stringValue += "&" - } - } - } - - if let fragment = fragment { stringValue += "#\(fragment)" } - - return stringValue - } - - public var description: String { - - let separator = " " - - var description = "" - - if let URLString = URLString { - - description += "URL: " + URLString + separator - } - - description += "Scheme: " + scheme - - if let user = user { - - description += separator + "User: " + user - } - - if let password = password { - - description += separator + "Password: " + password - } - - if let host = host { - - description += separator + "Host: " + host - } - - if let port = port { - - description += separator + "Port: " + "\(port)" - } - - if let path = path { - - description += separator + "Path: " + path - } - - if let query = query { - - var stringValue = "" - - for (index, queryItem) in query.enumerated() { - - let (name, value) = queryItem - - stringValue += name + "=" + value - - if index != query.count - 1 { - - stringValue += "&" - } - } - - description += separator + "Query: " + stringValue - } - - if let fragment = fragment { - - description += separator + "Fragment: " + fragment - } - - return description - } -} - diff --git a/Sources/SwiftFoundation/URLClient.swift b/Sources/SwiftFoundation/URLClient.swift deleted file mode 100644 index 2beff9b..0000000 --- a/Sources/SwiftFoundation/URLClient.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// URLClient.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/20/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public protocol URLClient { - - associatedtype Request: URLRequest - - associatedtype Response: URLResponse - - func send(request: Request) throws -> Response -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/URLProtocol.swift b/Sources/SwiftFoundation/URLProtocol.swift deleted file mode 100644 index 179643f..0000000 --- a/Sources/SwiftFoundation/URLProtocol.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// URLProtocol.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 8/9/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public protocol URLProtocol { - - /// Checks whether the URL is valid for the protocol - static func validURL(URL: URL) -> Bool -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/URLRequest.swift b/Sources/SwiftFoundation/URLRequest.swift deleted file mode 100644 index 91d0f41..0000000 --- a/Sources/SwiftFoundation/URLRequest.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// URLRequest.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -public protocol URLRequest { - - var URL: String { get } - - var timeoutInterval: TimeInterval { get } -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/URLResponse.swift b/Sources/SwiftFoundation/URLResponse.swift deleted file mode 100644 index 5380942..0000000 --- a/Sources/SwiftFoundation/URLResponse.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// URLResponse.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 6/29/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Encapsulates the metadata associated with the response to a a URL load request in a manner independent of protocol and URL scheme. -public protocol URLResponse { - - -} \ No newline at end of file diff --git a/Sources/SwiftFoundation/UUID.swift b/Sources/SwiftFoundation/UUID.swift index ce2912a..721bcda 100644 --- a/Sources/SwiftFoundation/UUID.swift +++ b/Sources/SwiftFoundation/UUID.swift @@ -6,67 +6,127 @@ // Copyright © 2015 PureSwift. All rights reserved. // -/// A representation of a universally unique identifier (```UUID```). -public struct UUID: ByteValue, Equatable, Hashable, RawRepresentable, CustomStringConvertible { - - /// Raw byte type for UUID - public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) - - // MARK: - Properties - - public var byteValue: ByteValue - - // MARK: - Initialization +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + import Darwin + import Foundation +#elseif os(Linux) + import Glibc + import CUUID +#endif + +// MARK: - Linux + +#if os(Linux) || XcodeLinux - /// Creates a random UUID. - public init() { + /// A representation of a universally unique identifier (```UUID```). + public struct UUID: ByteValue, Equatable, Hashable, RawRepresentable, CustomStringConvertible { - self.byteValue = POSIXUUIDCreateRandom() - } - - /// Initializes a UUID with the specified bytes. - public init(byteValue: ByteValue) { + // MARK: - Static Properties + + public static let length = 16 + public static let stringLength = 36 + public static let unformattedStringLength = 32 + + // MARK: - Properties + + public var bytes: uuid_t + + // MARK: - Initialization - self.byteValue = byteValue + /// Create a new UUID with RFC 4122 version 4 random bytes + public init() { + + var uuid = uuid_t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) + + withUnsafeMutablePointer(&uuid, { (valuePointer: UnsafeMutablePointer) in + + uuid_generate(unsafeBitCast(valuePointer, to: UnsafeMutablePointer.self)) + }) + + self.bytes = uuid + } + + /// Initializes a UUID with the specified bytes. + public init(bytes: uuid_t) { + + self.bytes = bytes + } } -} - -// MARK: - RawRepresentable - -public extension UUID { - init?(rawValue: String) { + // MARK: - RawRepresentable + + public extension UUID { - guard let uuid = POSIXUUIDConvertStringToUUID(rawValue) - else { return nil } + init?(rawValue: String) { + + let uuidPointer = UnsafeMutablePointer(allocatingCapacity: 1) + + defer { uuidPointer.deallocateCapacity(1) } + + guard uuid_parse(rawValue, unsafeBitCast(uuidPointer, to: UnsafeMutablePointer.self)) != -1 + else { return nil } + + self.bytes = uuidPointer.pointee + } - self.byteValue = uuid + var rawValue: String { + + var uuidCopy = bytes + + var uuidString = POSIXUUIDStringType(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + withUnsafeMutablePointers(&uuidCopy, &uuidString) { (uuidPointer: UnsafeMutablePointer, uuidStringPointer: UnsafeMutablePointer) -> Void in + + let stringBuffer = unsafeBitCast(uuidStringPointer, to: UnsafeMutablePointer.self) + + let uuidBuffer = unsafeBitCast(uuidPointer, to: UnsafeMutablePointer.self) + + uuid_unparse(unsafeBitCast(uuidBuffer, to: UnsafePointer.self), stringBuffer) + } + + return withUnsafeMutablePointer(&uuidString, { (valuePointer: UnsafeMutablePointer) -> String in + + let buffer = unsafeBitCast(valuePointer, to: UnsafeMutablePointer.self) + + return String(validatingUTF8: unsafeBitCast(buffer, to: UnsafePointer.self))! + }) + } } - var rawValue: String { + // MARK: - Hashable + + public extension UUID { - return POSIXUUIDConvertToString(byteValue) + var hashValue: Int { + + return toData().hashValue + } } -} -// MARK: - Hashable +#endif + +// MARK: - Darwin -extension UUID: Hashable { +#if (os(OSX) || os(iOS) || os(watchOS) || os(tvOS)) && !XcodeLinux - public var hashValue: Int { - - // more expensive than casting but that's not safe - let integerArray = self.toData().byteValue.map { Int($0) } - var hash = 0 + public typealias UUID = Foundation.UUID + + extension Foundation.UUID: ByteValue { - for integer in integerArray { + public init(bytes: uuid_t) { - hash ^= integer + self.init(uuid: bytes) } - return hash + public var bytes: uuid_t { + + get { return uuid } + + set { self = Foundation.UUID(uuid: newValue) } + } } -} + +#endif // MARK: - DataConvertible @@ -74,24 +134,21 @@ extension UUID: DataConvertible { public init?(data: Data) { - let byteValue = data.byteValue + guard data.count == UUID.length else { return nil } - guard byteValue.count == UUID.ByteCount else { return nil } - - self.init(byteValue: (byteValue[0], byteValue[1], byteValue[2], byteValue[3], byteValue[4], byteValue[5], byteValue[6], byteValue[7], byteValue[8], byteValue[9], byteValue[10], byteValue[11], byteValue[12], byteValue[13], byteValue[14], byteValue[15])) + self.init(bytes: (data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15])) } public func toData() -> Data { - return Data(byteValue: [byteValue.0, byteValue.1, byteValue.2, byteValue.3, byteValue.4, byteValue.5, byteValue.6, byteValue.7, byteValue.8, byteValue.9, byteValue.10, byteValue.11, byteValue.12, byteValue.13, byteValue.14, byteValue.15]) + return Data(bytes: [bytes.0, bytes.1, bytes.2, bytes.3, bytes.4, bytes.5, bytes.6, bytes.7, bytes.8, bytes.9, bytes.10, bytes.11, bytes.12, bytes.13, bytes.14, bytes.15]) } } -// MARK: - Private Constants +// MARK: - Private -private extension UUID { - - private static var StringLength: Int { return 36 } - private static var UnformattedUUIDStringLength: Int { return 32 } - private static var ByteCount: Int { return 16 } -} +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + private typealias POSIXUUIDStringType = uuid_string_t +#elseif os(Linux) + private typealias POSIXUUIDStringType = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8) +#endif diff --git a/Sources/SwiftFoundation/Version.swift b/Sources/SwiftFoundation/Version.swift index 5aa94e6..b6c6368 100644 --- a/Sources/SwiftFoundation/Version.swift +++ b/Sources/SwiftFoundation/Version.swift @@ -6,5 +6,5 @@ // Copyright © 2015 PureSwift. All rights reserved. // -/** The semantic versioning of the SwiftFoundation library. */ -public let SwiftFoundationVersion = SemanticVersion(mayor: 0, minor: 1, patch: 0) \ No newline at end of file +/// The semantic versioning of the SwiftFoundation library. +public let SwiftFoundationVersion = SemanticVersion(major: 2, minor: 0, patch: 0) diff --git a/Sources/UnitTests/AtomicTests.swift b/Sources/UnitTests/AtomicTests.swift deleted file mode 100644 index aafde80..0000000 --- a/Sources/UnitTests/AtomicTests.swift +++ /dev/null @@ -1,52 +0,0 @@ -// -// AtomicTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 4/11/16. -// Copyright © 2016 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - import Darwin.C -#elseif os(Linux) - import Glibc -#endif - -import XCTest -import SwiftFoundation - -final class AtomicTests: XCTestCase { - - static let allTests: [(String, (AtomicTests) -> () throws -> Void)] = [("testAtomic", testAtomic)] - - func testAtomic() { - - var atomic = Atomic(0) - - // main thread - for i in 0 ..< 10 { - - let _ = try! Thread { - - let oldValue = atomic.value - - atomic.value += 1 - - print("\(oldValue) -> \(atomic.value) (Thread \(i))") - } - } - - let finalValue = 10 - - print("Waiting for threads to finish") - - while atomic.value != finalValue { - - sleep(1) - } - - XCTAssert(atomic.value == finalValue, "Value is \(atomic.value), should be \(finalValue)") - - print("Final value \(atomic.value)") - } -} diff --git a/Sources/UnitTests/SortDescriptorTests.swift b/Sources/UnitTests/SortDescriptorTests.swift deleted file mode 100644 index c7e402f..0000000 --- a/Sources/UnitTests/SortDescriptorTests.swift +++ /dev/null @@ -1,129 +0,0 @@ -// -// SortDescriptorTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -import XCTest -import SwiftFoundation - -final class SortDescriptorTests: XCTestCase { - - static let allTests: [(String, (SortDescriptorTests) -> () throws -> Void)] = - [("testComparableSorting", testComparableSorting), - ("testComparatorSorting", testComparatorSorting)] - - // MARK: - Functional Tests - - func testComparableSorting() { - - let names = ["coleman", "Coleman", "alsey", "miller", "Z", "A"] - - do { - - let items = names - - let sortedItems = items.sorted(ComparableSortDescriptor(ascending: true)) - - let expected = items.sorted() - - XCTAssert(expected == sortedItems, "Ascending: \(expected) == \(sortedItems)") - } - - do { - - let items = names - - let sortedItems = items.sorted(ComparableSortDescriptor(ascending: false)) - - let expected = Array(items.sorted().reversed()) - - XCTAssert(expected == sortedItems, "Descending: \(expected) == \(sortedItems)") - } - - let places = ["Lima, Peru", "Brazil", "Florida", "San Diego", "Hong Kong"] - - do { - - let items = places - - let sortedItems = items.sorted(ComparableSortDescriptor(ascending: true)) - - let expected = items.sorted() - - XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") - } - - do { - - let items = places - - let sortedItems = items.sorted(ComparableSortDescriptor(ascending: false)) - - let expected = Array(items.sorted().reversed()) - - XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") - } - } - - func testComparatorSorting() { - - let names = ["coleman", "Coleman", "alsey", "miller", "Z", "A"] - - do { - - let items = names - - let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: true, comparator: { (first: String, second: String) -> Order in - - return first.compare(second) - })) - - let expected = items.sorted() - - XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") - } - - do { - - let items = names - - let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: false, comparator: { (first: String, second: String) -> Order in - - return first.compare(second) - })) - - let expected = Array(items.sorted().reversed()) - - XCTAssert(expected == sortedItems, "\(expected) == \(sortedItems)") - } - - let places = ["Lima, Peru", "Brazil", "Florida", "San Diego", "Hong Kong"] - - do { - - let items = places - - let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: true, comparator: { (first: String, second: String) -> Order in - - return first.compare(second) - })) - - XCTAssert(["Brazil", "Florida", "Hong Kong", "Lima, Peru", "San Diego"] == sortedItems) - } - - do { - - let items = places - - let sortedItems = items.sorted(ComparatorSortDescriptor(ascending: false, comparator: { (first: String, second: String) -> Order in - - return first.compare(second) - })) - - XCTAssert(["San Diego", "Lima, Peru", "Hong Kong", "Florida", "Brazil"] == sortedItems) - } - } -} diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 613cc25..93f7342 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -29,37 +29,23 @@ 6E2C2B8A1C20F76600B2C995 /* FileType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2B1C20F6EB00B2C995 /* FileType.swift */; }; 6E2C2B8B1C20F76600B2C995 /* Formatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2C1C20F6EB00B2C995 /* Formatter.swift */; }; 6E2C2B8C1C20F76600B2C995 /* HTTP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */; }; - 6E2C2B8D1C20F76600B2C995 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2E1C20F6EB00B2C995 /* HTTPMethod.swift */; }; - 6E2C2B8E1C20F76600B2C995 /* HTTPRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2F1C20F6EB00B2C995 /* HTTPRequest.swift */; }; - 6E2C2B8F1C20F76600B2C995 /* HTTPResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B301C20F6EB00B2C995 /* HTTPResponse.swift */; }; - 6E2C2B901C20F76600B2C995 /* HTTPStatusCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B311C20F6EB00B2C995 /* HTTPStatusCode.swift */; }; - 6E2C2B911C20F76600B2C995 /* HTTPVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B321C20F6EB00B2C995 /* HTTPVersion.swift */; }; 6E2C2B921C20F76600B2C995 /* Integer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B331C20F6EB00B2C995 /* Integer.swift */; }; 6E2C2B931C20F76600B2C995 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B341C20F6EB00B2C995 /* JSON.swift */; }; 6E2C2B941C20F76600B2C995 /* JSONExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */; }; 6E2C2B951C20F76600B2C995 /* Null.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B361C20F6EB00B2C995 /* Null.swift */; }; - 6E2C2B961C20F76600B2C995 /* Order.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B371C20F6EB00B2C995 /* Order.swift */; }; 6E2C2B971C20F76600B2C995 /* POSIXError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B381C20F6EB00B2C995 /* POSIXError.swift */; }; 6E2C2B981C20F76600B2C995 /* POSIXFileStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B391C20F6EB00B2C995 /* POSIXFileStatus.swift */; }; 6E2C2B991C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */; }; 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */; }; 6E2C2B9B1C20F76600B2C995 /* POSIXTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */; }; - 6E2C2B9D1C20F76600B2C995 /* Predicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */; }; 6E2C2B9E1C20F76600B2C995 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */; }; 6E2C2B9F1C20F76600B2C995 /* RegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */; }; 6E2C2BA01C20F76600B2C995 /* RegularExpressionCompileError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B411C20F6EB00B2C995 /* RegularExpressionCompileError.swift */; }; 6E2C2BA11C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B421C20F6EB00B2C995 /* RegularExpressionCompileOption.swift */; }; 6E2C2BA21C20F76600B2C995 /* RegularExpressionMatchOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B431C20F6EB00B2C995 /* RegularExpressionMatchOption.swift */; }; 6E2C2BA31C20F76600B2C995 /* SemanticVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */; }; - 6E2C2BA41C20F76600B2C995 /* SortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */; }; 6E2C2BA51C20F76600B2C995 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B461C20F6EB00B2C995 /* String.swift */; }; - 6E2C2BA61C20F76600B2C995 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B471C20F6EB00B2C995 /* Task.swift */; }; 6E2C2BA71C20F76600B2C995 /* Transformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */; }; - 6E2C2BA81C20F76600B2C995 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B491C20F6EB00B2C995 /* URL.swift */; }; - 6E2C2BA91C20F76600B2C995 /* URLClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4A1C20F6EB00B2C995 /* URLClient.swift */; }; - 6E2C2BAA1C20F76600B2C995 /* URLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4B1C20F6EB00B2C995 /* URLProtocol.swift */; }; - 6E2C2BAB1C20F76600B2C995 /* URLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4C1C20F6EB00B2C995 /* URLRequest.swift */; }; - 6E2C2BAC1C20F76600B2C995 /* URLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4D1C20F6EB00B2C995 /* URLResponse.swift */; }; 6E2C2BAD1C20F76600B2C995 /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */; }; 6E2C2BAE1C20F76600B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2BAF1C20F76600B2C995 /* Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */; }; @@ -75,37 +61,23 @@ 6E2C2BBE1C20F76600B2C995 /* FileType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2B1C20F6EB00B2C995 /* FileType.swift */; }; 6E2C2BBF1C20F76600B2C995 /* Formatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2C1C20F6EB00B2C995 /* Formatter.swift */; }; 6E2C2BC01C20F76600B2C995 /* HTTP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */; }; - 6E2C2BC11C20F76600B2C995 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2E1C20F6EB00B2C995 /* HTTPMethod.swift */; }; - 6E2C2BC21C20F76600B2C995 /* HTTPRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2F1C20F6EB00B2C995 /* HTTPRequest.swift */; }; - 6E2C2BC31C20F76600B2C995 /* HTTPResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B301C20F6EB00B2C995 /* HTTPResponse.swift */; }; - 6E2C2BC41C20F76600B2C995 /* HTTPStatusCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B311C20F6EB00B2C995 /* HTTPStatusCode.swift */; }; - 6E2C2BC51C20F76600B2C995 /* HTTPVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B321C20F6EB00B2C995 /* HTTPVersion.swift */; }; 6E2C2BC61C20F76600B2C995 /* Integer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B331C20F6EB00B2C995 /* Integer.swift */; }; 6E2C2BC71C20F76600B2C995 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B341C20F6EB00B2C995 /* JSON.swift */; }; 6E2C2BC81C20F76600B2C995 /* JSONExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */; }; 6E2C2BC91C20F76600B2C995 /* Null.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B361C20F6EB00B2C995 /* Null.swift */; }; - 6E2C2BCA1C20F76600B2C995 /* Order.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B371C20F6EB00B2C995 /* Order.swift */; }; 6E2C2BCB1C20F76600B2C995 /* POSIXError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B381C20F6EB00B2C995 /* POSIXError.swift */; }; 6E2C2BCC1C20F76600B2C995 /* POSIXFileStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B391C20F6EB00B2C995 /* POSIXFileStatus.swift */; }; 6E2C2BCD1C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */; }; 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */; }; 6E2C2BCF1C20F76600B2C995 /* POSIXTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */; }; - 6E2C2BD11C20F76600B2C995 /* Predicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */; }; 6E2C2BD21C20F76600B2C995 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */; }; 6E2C2BD31C20F76600B2C995 /* RegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */; }; 6E2C2BD41C20F76600B2C995 /* RegularExpressionCompileError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B411C20F6EB00B2C995 /* RegularExpressionCompileError.swift */; }; 6E2C2BD51C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B421C20F6EB00B2C995 /* RegularExpressionCompileOption.swift */; }; 6E2C2BD61C20F76600B2C995 /* RegularExpressionMatchOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B431C20F6EB00B2C995 /* RegularExpressionMatchOption.swift */; }; 6E2C2BD71C20F76600B2C995 /* SemanticVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */; }; - 6E2C2BD81C20F76600B2C995 /* SortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */; }; 6E2C2BD91C20F76600B2C995 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B461C20F6EB00B2C995 /* String.swift */; }; - 6E2C2BDA1C20F76600B2C995 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B471C20F6EB00B2C995 /* Task.swift */; }; 6E2C2BDB1C20F76600B2C995 /* Transformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */; }; - 6E2C2BDC1C20F76600B2C995 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B491C20F6EB00B2C995 /* URL.swift */; }; - 6E2C2BDD1C20F76600B2C995 /* URLClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4A1C20F6EB00B2C995 /* URLClient.swift */; }; - 6E2C2BDE1C20F76600B2C995 /* URLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4B1C20F6EB00B2C995 /* URLProtocol.swift */; }; - 6E2C2BDF1C20F76600B2C995 /* URLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4C1C20F6EB00B2C995 /* URLRequest.swift */; }; - 6E2C2BE01C20F76600B2C995 /* URLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4D1C20F6EB00B2C995 /* URLResponse.swift */; }; 6E2C2BE11C20F76600B2C995 /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */; }; 6E2C2BE21C20F76600B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2BE31C20F76700B2C995 /* Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */; }; @@ -121,49 +93,33 @@ 6E2C2BF21C20F76700B2C995 /* FileType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2B1C20F6EB00B2C995 /* FileType.swift */; }; 6E2C2BF31C20F76700B2C995 /* Formatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2C1C20F6EB00B2C995 /* Formatter.swift */; }; 6E2C2BF41C20F76700B2C995 /* HTTP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */; }; - 6E2C2BF51C20F76700B2C995 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2E1C20F6EB00B2C995 /* HTTPMethod.swift */; }; - 6E2C2BF61C20F76700B2C995 /* HTTPRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2F1C20F6EB00B2C995 /* HTTPRequest.swift */; }; - 6E2C2BF71C20F76700B2C995 /* HTTPResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B301C20F6EB00B2C995 /* HTTPResponse.swift */; }; - 6E2C2BF81C20F76700B2C995 /* HTTPStatusCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B311C20F6EB00B2C995 /* HTTPStatusCode.swift */; }; - 6E2C2BF91C20F76700B2C995 /* HTTPVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B321C20F6EB00B2C995 /* HTTPVersion.swift */; }; 6E2C2BFA1C20F76700B2C995 /* Integer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B331C20F6EB00B2C995 /* Integer.swift */; }; 6E2C2BFB1C20F76700B2C995 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B341C20F6EB00B2C995 /* JSON.swift */; }; 6E2C2BFC1C20F76700B2C995 /* JSONExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */; }; 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B361C20F6EB00B2C995 /* Null.swift */; }; - 6E2C2BFE1C20F76700B2C995 /* Order.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B371C20F6EB00B2C995 /* Order.swift */; }; 6E2C2BFF1C20F76700B2C995 /* POSIXError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B381C20F6EB00B2C995 /* POSIXError.swift */; }; 6E2C2C001C20F76700B2C995 /* POSIXFileStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B391C20F6EB00B2C995 /* POSIXFileStatus.swift */; }; 6E2C2C011C20F76700B2C995 /* POSIXFileSystemStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */; }; 6E2C2C021C20F76700B2C995 /* POSIXRegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */; }; 6E2C2C031C20F76700B2C995 /* POSIXTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */; }; - 6E2C2C051C20F76700B2C995 /* Predicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */; }; 6E2C2C061C20F76700B2C995 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */; }; 6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */; }; 6E2C2C081C20F76700B2C995 /* RegularExpressionCompileError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B411C20F6EB00B2C995 /* RegularExpressionCompileError.swift */; }; 6E2C2C091C20F76700B2C995 /* RegularExpressionCompileOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B421C20F6EB00B2C995 /* RegularExpressionCompileOption.swift */; }; 6E2C2C0A1C20F76700B2C995 /* RegularExpressionMatchOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B431C20F6EB00B2C995 /* RegularExpressionMatchOption.swift */; }; 6E2C2C0B1C20F76700B2C995 /* SemanticVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */; }; - 6E2C2C0C1C20F76700B2C995 /* SortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */; }; - 6E2C2C0E1C20F76700B2C995 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B471C20F6EB00B2C995 /* Task.swift */; }; 6E2C2C0F1C20F76700B2C995 /* Transformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */; }; - 6E2C2C101C20F76700B2C995 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B491C20F6EB00B2C995 /* URL.swift */; }; - 6E2C2C111C20F76700B2C995 /* URLClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4A1C20F6EB00B2C995 /* URLClient.swift */; }; - 6E2C2C121C20F76700B2C995 /* URLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4B1C20F6EB00B2C995 /* URLProtocol.swift */; }; - 6E2C2C131C20F76700B2C995 /* URLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4C1C20F6EB00B2C995 /* URLRequest.swift */; }; - 6E2C2C141C20F76700B2C995 /* URLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4D1C20F6EB00B2C995 /* URLResponse.swift */; }; 6E2C2C161C20F76700B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2C171C20F76B00B2C995 /* DateComponentsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */; }; 6E2C2C181C20F76B00B2C995 /* OrderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */; }; 6E2C2C191C20F76B00B2C995 /* POSIXTimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */; }; 6E2C2C1A1C20F76B00B2C995 /* RegularExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */; }; - 6E2C2C1B1C20F76B00B2C995 /* SortDescriptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B551C20F6EB00B2C995 /* SortDescriptorTests.swift */; }; 6E2C2C1C1C20F76B00B2C995 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */; }; 6E2C2C1D1C20F76B00B2C995 /* UUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */; }; 6E2C2C1E1C20F76D00B2C995 /* DateComponentsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */; }; 6E2C2C1F1C20F76D00B2C995 /* OrderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */; }; 6E2C2C201C20F76D00B2C995 /* POSIXTimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */; }; 6E2C2C211C20F76D00B2C995 /* RegularExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */; }; - 6E2C2C221C20F76D00B2C995 /* SortDescriptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B551C20F6EB00B2C995 /* SortDescriptorTests.swift */; }; 6E2C2C231C20F76D00B2C995 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */; }; 6E2C2C241C20F76D00B2C995 /* UUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */; }; 6E2C2C2F1C2128C600B2C995 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2C2E1C2128C600B2C995 /* main.swift */; }; @@ -173,10 +129,11 @@ 6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E82FD731CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; 6E82FD741CBA06C10049CD1B /* Lock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD711CBA06C10049CD1B /* Lock.swift */; }; - 6E82FD7A1CBB70710049CD1B /* AtomicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD791CBB70710049CD1B /* AtomicTests.swift */; }; - 6E82FD7B1CBB70710049CD1B /* AtomicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E82FD791CBB70710049CD1B /* AtomicTests.swift */; }; 6E8474CA1D24EC3A009CA7DB /* Hash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8474C91D24EC3A009CA7DB /* Hash.swift */; }; 6E8474CB1D24F1A5009CA7DB /* UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */; }; + 6E8474CD1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */; }; + 6E8474CE1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */; }; + 6E8474CF1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */; }; 6E957C261C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C271C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; 6E957C281C43A7C8003F3C51 /* JSONParse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C251C43A7C8003F3C51 /* JSONParse.swift */; }; @@ -269,44 +226,29 @@ 6E2C2B2B1C20F6EB00B2C995 /* FileType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileType.swift; sourceTree = ""; }; 6E2C2B2C1C20F6EB00B2C995 /* Formatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Formatter.swift; sourceTree = ""; }; 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTP.swift; sourceTree = ""; }; - 6E2C2B2E1C20F6EB00B2C995 /* HTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = ""; }; - 6E2C2B2F1C20F6EB00B2C995 /* HTTPRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPRequest.swift; sourceTree = ""; }; - 6E2C2B301C20F6EB00B2C995 /* HTTPResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPResponse.swift; sourceTree = ""; }; - 6E2C2B311C20F6EB00B2C995 /* HTTPStatusCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPStatusCode.swift; sourceTree = ""; }; - 6E2C2B321C20F6EB00B2C995 /* HTTPVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPVersion.swift; sourceTree = ""; }; 6E2C2B331C20F6EB00B2C995 /* Integer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Integer.swift; sourceTree = ""; }; 6E2C2B341C20F6EB00B2C995 /* JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; }; 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONExtensions.swift; sourceTree = ""; }; 6E2C2B361C20F6EB00B2C995 /* Null.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Null.swift; sourceTree = ""; }; - 6E2C2B371C20F6EB00B2C995 /* Order.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Order.swift; sourceTree = ""; }; 6E2C2B381C20F6EB00B2C995 /* POSIXError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXError.swift; sourceTree = ""; }; 6E2C2B391C20F6EB00B2C995 /* POSIXFileStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXFileStatus.swift; sourceTree = ""; }; 6E2C2B3A1C20F6EB00B2C995 /* POSIXFileSystemStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXFileSystemStatus.swift; sourceTree = ""; }; 6E2C2B3B1C20F6EB00B2C995 /* POSIXRegularExpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXRegularExpression.swift; sourceTree = ""; }; 6E2C2B3C1C20F6EB00B2C995 /* POSIXTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXTime.swift; sourceTree = ""; }; - 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Predicate.swift; sourceTree = ""; }; 6E2C2B3F1C20F6EB00B2C995 /* RawRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = ""; }; 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpression.swift; sourceTree = ""; }; 6E2C2B411C20F6EB00B2C995 /* RegularExpressionCompileError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpressionCompileError.swift; sourceTree = ""; }; 6E2C2B421C20F6EB00B2C995 /* RegularExpressionCompileOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpressionCompileOption.swift; sourceTree = ""; }; 6E2C2B431C20F6EB00B2C995 /* RegularExpressionMatchOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpressionMatchOption.swift; sourceTree = ""; }; 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SemanticVersion.swift; sourceTree = ""; }; - 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortDescriptor.swift; sourceTree = ""; }; 6E2C2B461C20F6EB00B2C995 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; - 6E2C2B471C20F6EB00B2C995 /* Task.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Task.swift; sourceTree = ""; }; 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transformer.swift; sourceTree = ""; }; - 6E2C2B491C20F6EB00B2C995 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; - 6E2C2B4A1C20F6EB00B2C995 /* URLClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLClient.swift; sourceTree = ""; }; - 6E2C2B4B1C20F6EB00B2C995 /* URLProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLProtocol.swift; sourceTree = ""; }; - 6E2C2B4C1C20F6EB00B2C995 /* URLRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLRequest.swift; sourceTree = ""; }; - 6E2C2B4D1C20F6EB00B2C995 /* URLResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLResponse.swift; sourceTree = ""; }; 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UUID.swift; sourceTree = ""; }; 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateComponentsTest.swift; sourceTree = ""; }; 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderTests.swift; sourceTree = ""; }; 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXTimeTests.swift; sourceTree = ""; }; 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpressionTests.swift; sourceTree = ""; }; - 6E2C2B551C20F6EB00B2C995 /* SortDescriptorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortDescriptorTests.swift; sourceTree = ""; }; 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UUIDTests.swift; sourceTree = ""; }; 6E2C2C2A1C21105000B2C995 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Package.swift; sourceTree = ""; }; @@ -317,8 +259,8 @@ 6E30BA171B40F543009B1B49 /* SwiftFoundationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFoundationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 6E30BA1E1B40F543009B1B49 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6E82FD711CBA06C10049CD1B /* Lock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = ""; }; - 6E82FD791CBB70710049CD1B /* AtomicTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomicTests.swift; sourceTree = ""; }; 6E8474C91D24EC3A009CA7DB /* Hash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Hash.swift; sourceTree = ""; }; + 6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparisonResult.swift; sourceTree = ""; }; 6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = ""; }; 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = ""; }; 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = ""; }; @@ -404,7 +346,7 @@ 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */, 6E2C2B1D1C20F6EB00B2C995 /* BitMaskOption.swift */, 6E2C2B1F1C20F6EB00B2C995 /* ByteValue.swift */, - 6E8474C91D24EC3A009CA7DB /* Hash.swift */, + 6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */, 6E2C2B241C20F6EB00B2C995 /* Data.swift */, 6E2C2B251C20F6EB00B2C995 /* Date.swift */, 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */, @@ -415,8 +357,9 @@ 6E2C2B2A1C20F6EB00B2C995 /* FilePermission.swift */, 6E2C2B2B1C20F6EB00B2C995 /* FileType.swift */, 6E2C2B2C1C20F6EB00B2C995 /* Formatter.swift */, + 6E8474C91D24EC3A009CA7DB /* Hash.swift */, 6EE84DDC1CAF667E00A40C4D /* Hexadecimal.swift */, - 6E2C2C281C20FC6B00B2C995 /* HTTP */, + 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */, 6E2C2B341C20F6EB00B2C995 /* JSON.swift */, 6E957C251C43A7C8003F3C51 /* JSONParse.swift */, 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */, @@ -424,18 +367,13 @@ 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */, 6E82FD711CBA06C10049CD1B /* Lock.swift */, 6E2C2B361C20F6EB00B2C995 /* Null.swift */, - 6E2C2B371C20F6EB00B2C995 /* Order.swift */, - 6E2C2B3E1C20F6EB00B2C995 /* Predicate.swift */, 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */, 6E2C2B411C20F6EB00B2C995 /* RegularExpressionCompileError.swift */, 6E2C2B421C20F6EB00B2C995 /* RegularExpressionCompileOption.swift */, 6E2C2B431C20F6EB00B2C995 /* RegularExpressionMatchOption.swift */, 6E2C2B441C20F6EB00B2C995 /* SemanticVersion.swift */, - 6E2C2B451C20F6EB00B2C995 /* SortDescriptor.swift */, - 6E2C2B471C20F6EB00B2C995 /* Task.swift */, 6E04074D1CB3E07500BE3A79 /* Thread.swift */, 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */, - 6E2C2C291C20FC9500B2C995 /* URL */, 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */, 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */, ); @@ -446,12 +384,10 @@ isa = PBXGroup; children = ( 6E2C2C2E1C2128C600B2C995 /* main.swift */, - 6E82FD791CBB70710049CD1B /* AtomicTests.swift */, 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */, 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */, 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */, 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */, - 6E2C2B551C20F6EB00B2C995 /* SortDescriptorTests.swift */, 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */, 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */, 6E1ACD4A1C435822005775FD /* DataTests.swift */, @@ -493,31 +429,6 @@ name = Swift; sourceTree = ""; }; - 6E2C2C281C20FC6B00B2C995 /* HTTP */ = { - isa = PBXGroup; - children = ( - 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */, - 6E2C2B2E1C20F6EB00B2C995 /* HTTPMethod.swift */, - 6E2C2B2F1C20F6EB00B2C995 /* HTTPRequest.swift */, - 6E2C2B301C20F6EB00B2C995 /* HTTPResponse.swift */, - 6E2C2B311C20F6EB00B2C995 /* HTTPStatusCode.swift */, - 6E2C2B321C20F6EB00B2C995 /* HTTPVersion.swift */, - ); - name = HTTP; - sourceTree = ""; - }; - 6E2C2C291C20FC9500B2C995 /* URL */ = { - isa = PBXGroup; - children = ( - 6E2C2B491C20F6EB00B2C995 /* URL.swift */, - 6E2C2B4A1C20F6EB00B2C995 /* URLClient.swift */, - 6E2C2B4B1C20F6EB00B2C995 /* URLProtocol.swift */, - 6E2C2B4C1C20F6EB00B2C995 /* URLRequest.swift */, - 6E2C2B4D1C20F6EB00B2C995 /* URLResponse.swift */, - ); - name = URL; - sourceTree = ""; - }; 6E30BA031B40F543009B1B49 = { isa = PBXGroup; children = ( @@ -791,37 +702,26 @@ 6E2C2BD61C20F76600B2C995 /* RegularExpressionMatchOption.swift in Sources */, 6E2C2BB91C20F76600B2C995 /* DateComponents.swift in Sources */, 6E2C2BB21C20F76600B2C995 /* ByteValue.swift in Sources */, - 6E2C2BC21C20F76600B2C995 /* HTTPRequest.swift in Sources */, 6E2C2BCD1C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */, - 6E2C2BD11C20F76600B2C995 /* Predicate.swift in Sources */, 6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */, 6E2C2BD21C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BD91C20F76600B2C995 /* String.swift in Sources */, 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, - 6E2C2BE01C20F76600B2C995 /* URLResponse.swift in Sources */, 6E2C2BC61C20F76600B2C995 /* Integer.swift in Sources */, - 6E2C2BDF1C20F76600B2C995 /* URLRequest.swift in Sources */, 6E2C2BBA1C20F76600B2C995 /* Decimal.swift in Sources */, 6E2C2BC91C20F76600B2C995 /* Null.swift in Sources */, 6E2C2BB01C20F76600B2C995 /* BitMaskOption.swift in Sources */, 6E2C2BD51C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */, - 6E2C2BC31C20F76600B2C995 /* HTTPResponse.swift in Sources */, 6E2C2BE21C20F76600B2C995 /* Version.swift in Sources */, 6E2C2BBC1C20F76600B2C995 /* FileManager.swift in Sources */, 6E2C2BB71C20F76600B2C995 /* Data.swift in Sources */, - 6E2C2BDC1C20F76600B2C995 /* URL.swift in Sources */, 6E2C2BCF1C20F76600B2C995 /* POSIXTime.swift in Sources */, 6E2C2BBF1C20F76600B2C995 /* Formatter.swift in Sources */, 6EE84DDE1CAF667E00A40C4D /* Hexadecimal.swift in Sources */, - 6E2C2BDE1C20F76600B2C995 /* URLProtocol.swift in Sources */, 6E2C2BC81C20F76600B2C995 /* JSONExtensions.swift in Sources */, - 6E2C2BC51C20F76600B2C995 /* HTTPVersion.swift in Sources */, - 6E2C2BC11C20F76600B2C995 /* HTTPMethod.swift in Sources */, 6E2C2BE11C20F76600B2C995 /* UUID.swift in Sources */, 6E2C2BBB1C20F76600B2C995 /* FileDescriptor.swift in Sources */, - 6E2C2BDA1C20F76600B2C995 /* Task.swift in Sources */, - 6E2C2BDD1C20F76600B2C995 /* URLClient.swift in Sources */, - 6E2C2BC41C20F76600B2C995 /* HTTPStatusCode.swift in Sources */, + 6E8474CE1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */, 6E2C2BDB1C20F76600B2C995 /* Transformer.swift in Sources */, 6E2C2BD41C20F76600B2C995 /* RegularExpressionCompileError.swift in Sources */, 6E2C2BD71C20F76600B2C995 /* SemanticVersion.swift in Sources */, @@ -830,12 +730,10 @@ 6E957C2C1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6EE84DDA1CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2BCB1C20F76600B2C995 /* POSIXError.swift in Sources */, - 6E2C2BCA1C20F76600B2C995 /* Order.swift in Sources */, 6E957C2F1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2BB81C20F76600B2C995 /* Date.swift in Sources */, 6E2C2BC71C20F76600B2C995 /* JSON.swift in Sources */, 6E2C2BAF1C20F76600B2C995 /* Base64.swift in Sources */, - 6E2C2BD81C20F76600B2C995 /* SortDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -851,37 +749,26 @@ 6E2C2BA21C20F76600B2C995 /* RegularExpressionMatchOption.swift in Sources */, 6E2C2B851C20F76600B2C995 /* DateComponents.swift in Sources */, 6E2C2B7E1C20F76600B2C995 /* ByteValue.swift in Sources */, - 6E2C2B8E1C20F76600B2C995 /* HTTPRequest.swift in Sources */, 6E2C2B991C20F76600B2C995 /* POSIXFileSystemStatus.swift in Sources */, - 6E2C2B9D1C20F76600B2C995 /* Predicate.swift in Sources */, 6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */, 6E2C2B9E1C20F76600B2C995 /* RawRepresentable.swift in Sources */, 6E2C2BA51C20F76600B2C995 /* String.swift in Sources */, 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, - 6E2C2BAC1C20F76600B2C995 /* URLResponse.swift in Sources */, 6E2C2B921C20F76600B2C995 /* Integer.swift in Sources */, - 6E2C2BAB1C20F76600B2C995 /* URLRequest.swift in Sources */, 6E2C2B861C20F76600B2C995 /* Decimal.swift in Sources */, 6E2C2B951C20F76600B2C995 /* Null.swift in Sources */, 6E2C2B7C1C20F76600B2C995 /* BitMaskOption.swift in Sources */, 6E2C2BA11C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */, - 6E2C2B8F1C20F76600B2C995 /* HTTPResponse.swift in Sources */, 6E2C2BAE1C20F76600B2C995 /* Version.swift in Sources */, 6E2C2B881C20F76600B2C995 /* FileManager.swift in Sources */, 6E2C2B831C20F76600B2C995 /* Data.swift in Sources */, - 6E2C2BA81C20F76600B2C995 /* URL.swift in Sources */, 6E2C2B9B1C20F76600B2C995 /* POSIXTime.swift in Sources */, 6E2C2B8B1C20F76600B2C995 /* Formatter.swift in Sources */, 6EE84DDF1CAF667E00A40C4D /* Hexadecimal.swift in Sources */, - 6E2C2BAA1C20F76600B2C995 /* URLProtocol.swift in Sources */, 6E2C2B941C20F76600B2C995 /* JSONExtensions.swift in Sources */, - 6E2C2B911C20F76600B2C995 /* HTTPVersion.swift in Sources */, - 6E2C2B8D1C20F76600B2C995 /* HTTPMethod.swift in Sources */, 6E2C2BAD1C20F76600B2C995 /* UUID.swift in Sources */, 6E2C2B871C20F76600B2C995 /* FileDescriptor.swift in Sources */, - 6E2C2BA61C20F76600B2C995 /* Task.swift in Sources */, - 6E2C2BA91C20F76600B2C995 /* URLClient.swift in Sources */, - 6E2C2B901C20F76600B2C995 /* HTTPStatusCode.swift in Sources */, + 6E8474CF1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */, 6E2C2BA71C20F76600B2C995 /* Transformer.swift in Sources */, 6E2C2BA01C20F76600B2C995 /* RegularExpressionCompileError.swift in Sources */, 6E2C2BA31C20F76600B2C995 /* SemanticVersion.swift in Sources */, @@ -890,12 +777,10 @@ 6E957C2D1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6EE84DDB1CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2B971C20F76600B2C995 /* POSIXError.swift in Sources */, - 6E2C2B961C20F76600B2C995 /* Order.swift in Sources */, 6E957C301C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2B841C20F76600B2C995 /* Date.swift in Sources */, 6E2C2B931C20F76600B2C995 /* JSON.swift in Sources */, 6E2C2B7B1C20F76600B2C995 /* Base64.swift in Sources */, - 6E2C2BA41C20F76600B2C995 /* SortDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -905,11 +790,9 @@ files = ( 6E2C2C181C20F76B00B2C995 /* OrderTests.swift in Sources */, 6E2C2C301C2128C600B2C995 /* main.swift in Sources */, - 6E82FD7B1CBB70710049CD1B /* AtomicTests.swift in Sources */, 6EFF9A1F1CAD11F600917CB3 /* Range.swift in Sources */, 6E2C2C1D1C20F76B00B2C995 /* UUIDTests.swift in Sources */, 6E957C581C442E3E003F3C51 /* JSONTests.swift in Sources */, - 6E2C2C1B1C20F76B00B2C995 /* SortDescriptorTests.swift in Sources */, 6E2C2C171C20F76B00B2C995 /* DateComponentsTest.swift in Sources */, 6E2C2C191C20F76B00B2C995 /* POSIXTimeTests.swift in Sources */, 6E2C2C1A1C20F76B00B2C995 /* RegularExpressionTests.swift in Sources */, @@ -932,16 +815,13 @@ 6E2C2C0A1C20F76700B2C995 /* RegularExpressionMatchOption.swift in Sources */, 6E2C2BED1C20F76700B2C995 /* DateComponents.swift in Sources */, 6E2C2BE61C20F76700B2C995 /* ByteValue.swift in Sources */, - 6E2C2BF61C20F76700B2C995 /* HTTPRequest.swift in Sources */, 6E2C2C011C20F76700B2C995 /* POSIXFileSystemStatus.swift in Sources */, 6E8474CB1D24F1A5009CA7DB /* UUID.swift in Sources */, - 6E2C2C051C20F76700B2C995 /* Predicate.swift in Sources */, 6E041D3D1CB404CD004E080B /* String.swift in Sources */, 6E2C2C061C20F76700B2C995 /* RawRepresentable.swift in Sources */, 6E2C2C021C20F76700B2C995 /* POSIXRegularExpression.swift in Sources */, - 6E2C2C141C20F76700B2C995 /* URLResponse.swift in Sources */, 6E2C2BFA1C20F76700B2C995 /* Integer.swift in Sources */, - 6E2C2C131C20F76700B2C995 /* URLRequest.swift in Sources */, + 6E8474CD1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */, 6EFF9A1B1CAD0C6B00917CB3 /* Range.swift in Sources */, 6E2C2BEE1C20F76700B2C995 /* Decimal.swift in Sources */, 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */, @@ -949,21 +829,13 @@ 6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */, 6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */, 6E2C2C091C20F76700B2C995 /* RegularExpressionCompileOption.swift in Sources */, - 6E2C2BF71C20F76700B2C995 /* HTTPResponse.swift in Sources */, 6E2C2C161C20F76700B2C995 /* Version.swift in Sources */, 6E2C2BF01C20F76700B2C995 /* FileManager.swift in Sources */, 6E2C2BEB1C20F76700B2C995 /* Data.swift in Sources */, - 6E2C2C101C20F76700B2C995 /* URL.swift in Sources */, 6E2C2C031C20F76700B2C995 /* POSIXTime.swift in Sources */, 6E2C2BF31C20F76700B2C995 /* Formatter.swift in Sources */, - 6E2C2C121C20F76700B2C995 /* URLProtocol.swift in Sources */, 6E2C2BFC1C20F76700B2C995 /* JSONExtensions.swift in Sources */, - 6E2C2BF91C20F76700B2C995 /* HTTPVersion.swift in Sources */, - 6E2C2BF51C20F76700B2C995 /* HTTPMethod.swift in Sources */, 6E2C2BEF1C20F76700B2C995 /* FileDescriptor.swift in Sources */, - 6E2C2C0E1C20F76700B2C995 /* Task.swift in Sources */, - 6E2C2C111C20F76700B2C995 /* URLClient.swift in Sources */, - 6E2C2BF81C20F76700B2C995 /* HTTPStatusCode.swift in Sources */, 6E2C2C0F1C20F76700B2C995 /* Transformer.swift in Sources */, 6E2C2C081C20F76700B2C995 /* RegularExpressionCompileError.swift in Sources */, 6E2C2C0B1C20F76700B2C995 /* SemanticVersion.swift in Sources */, @@ -971,13 +843,11 @@ 6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */, 6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6E2C2BFF1C20F76700B2C995 /* POSIXError.swift in Sources */, - 6E2C2BFE1C20F76700B2C995 /* Order.swift in Sources */, 6E957C2E1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2BEC1C20F76700B2C995 /* Date.swift in Sources */, 6E2C2BFB1C20F76700B2C995 /* JSON.swift in Sources */, 6EE84DD91CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2BE31C20F76700B2C995 /* Base64.swift in Sources */, - 6E2C2C0C1C20F76700B2C995 /* SortDescriptor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -986,11 +856,9 @@ buildActionMask = 2147483647; files = ( 6E2C2C1F1C20F76D00B2C995 /* OrderTests.swift in Sources */, - 6E82FD7A1CBB70710049CD1B /* AtomicTests.swift in Sources */, 6E2C2C2F1C2128C600B2C995 /* main.swift in Sources */, 6E2C2C241C20F76D00B2C995 /* UUIDTests.swift in Sources */, 6E957C571C442E3E003F3C51 /* JSONTests.swift in Sources */, - 6E2C2C221C20F76D00B2C995 /* SortDescriptorTests.swift in Sources */, 6E2C2C1E1C20F76D00B2C995 /* DateComponentsTest.swift in Sources */, 6E2C2C201C20F76D00B2C995 /* POSIXTimeTests.swift in Sources */, 6E2C2C211C20F76D00B2C995 /* RegularExpressionTests.swift in Sources */, diff --git a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme index bddaedb..d417ba4 100644 --- a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme +++ b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme @@ -23,7 +23,7 @@ From 253a05519a35417f1cd8cf7560912f4ce02cb4a9 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 30 Jun 2016 03:04:20 -0500 Subject: [PATCH 47/68] Improved UUID: Equatable performance --- Sources/SwiftFoundation/UUID.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sources/SwiftFoundation/UUID.swift b/Sources/SwiftFoundation/UUID.swift index 721bcda..d68eea2 100644 --- a/Sources/SwiftFoundation/UUID.swift +++ b/Sources/SwiftFoundation/UUID.swift @@ -102,6 +102,28 @@ return toData().hashValue } } + + // MARK: - Equatable + + public func == (lhs: UUID, rhs: UUID) -> Bool { + + return lhs.bytes.0 == rhs.bytes.0 && + lhs.bytes.1 == rhs.bytes.1 && + lhs.bytes.2 == rhs.bytes.2 && + lhs.bytes.3 == rhs.bytes.3 && + lhs.bytes.4 == rhs.bytes.4 && + lhs.bytes.5 == rhs.bytes.5 && + lhs.bytes.6 == rhs.bytes.6 && + lhs.bytes.7 == rhs.bytes.7 && + lhs.bytes.8 == rhs.bytes.8 && + lhs.bytes.9 == rhs.bytes.9 && + lhs.bytes.10 == rhs.bytes.10 && + lhs.bytes.11 == rhs.bytes.11 && + lhs.bytes.12 == rhs.bytes.12 && + lhs.bytes.13 == rhs.bytes.13 && + lhs.bytes.14 == rhs.bytes.14 && + lhs.bytes.15 == rhs.bytes.15 + } #endif From 9aa43968604c4ade221cc6a7cd937906ccabefbf Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 30 Jun 2016 03:30:27 -0500 Subject: [PATCH 48/68] Fixed unit tests for Darwin --- Package.swift | 4 +- Sources/SwiftFoundation/Date.swift | 78 +++++++++++-------- Sources/SwiftFoundation/DateComponents.swift | 8 +- Sources/SwiftFoundation/POSIXFileStatus.swift | 16 ++-- Sources/SwiftFoundation/UUID.swift | 24 ++++++ Sources/UnitTests/DataTests.swift | 10 +-- Sources/UnitTests/DateComponentsTest.swift | 4 +- Sources/UnitTests/JSONTests.swift | 22 ------ Sources/UnitTests/OrderTests.swift | 45 ----------- Sources/UnitTests/POSIXTimeTests.swift | 12 +-- Sources/UnitTests/UUIDTests.swift | 6 +- Sources/UnitTests/main.swift | 5 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 6 -- 13 files changed, 99 insertions(+), 141 deletions(-) delete mode 100644 Sources/UnitTests/OrderTests.swift diff --git a/Package.swift b/Package.swift index fc461df..7f329f9 100644 --- a/Package.swift +++ b/Package.swift @@ -14,5 +14,5 @@ let package = Package( Target( name: "SwiftFoundation") ], - exclude: ["Xcode", "Carthage", "Sources/FoundationConvertible", "Sources/FoundationUnitTests"] -) \ No newline at end of file + exclude: ["Xcode", "Carthage"] +) diff --git a/Sources/SwiftFoundation/Date.swift b/Sources/SwiftFoundation/Date.swift index 138c933..26ae98c 100644 --- a/Sources/SwiftFoundation/Date.swift +++ b/Sources/SwiftFoundation/Date.swift @@ -8,6 +8,7 @@ #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) import Darwin.C + import struct Foundation.Date #elseif os(Linux) import Glibc #endif @@ -147,6 +148,43 @@ } } + // MARK: - Operators + + public func == (lhs: Date, rhs: Date) -> Bool { + + return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate + } + + public func < (lhs: Date, rhs: Date) -> Bool { + + return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate + } + + public func - (lhs: Date, rhs: Date) -> TimeInterval { + + return lhs.timeIntervalSinceReferenceDate - rhs.timeIntervalSinceReferenceDate + } + + public func + (lhs: Date, rhs: TimeInterval) -> Date { + + return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate + rhs) + } + + public func - (lhs: Date, rhs: TimeInterval) -> Date { + + return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate - rhs) + } + + public func += (lhs: inout Date, rhs: TimeInterval) { + + lhs = lhs + rhs + } + + public func -= (lhs: inout Date, rhs: TimeInterval) { + + lhs = lhs - rhs + } + // MARK: - Supporting Types /// Time interval difference between two dates, in seconds. @@ -154,39 +192,15 @@ #endif -// MARK: - Operators +// MARK: - Darwin -public func == (lhs: Date, rhs: Date) -> Bool { +#if (os(OSX) || os(iOS) || os(watchOS) || os(tvOS)) && !XcodeLinux - return lhs.timeIntervalSinceReferenceDate == rhs.timeIntervalSinceReferenceDate -} - -public func < (lhs: Date, rhs: Date) -> Bool { - - return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate -} - -public func - (lhs: Date, rhs: Date) -> TimeInterval { - - return lhs.timeIntervalSinceReferenceDate - rhs.timeIntervalSinceReferenceDate -} - -public func + (lhs: Date, rhs: TimeInterval) -> Date { + public typealias Date = Foundation.Date - return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate + rhs) -} - -public func - (lhs: Date, rhs: TimeInterval) -> Date { - - return Date(timeIntervalSinceReferenceDate: lhs.timeIntervalSinceReferenceDate - rhs) -} - -public func += (lhs: inout Date, rhs: TimeInterval) { - - lhs = lhs + rhs -} - -public func -= (lhs: inout Date, rhs: TimeInterval) { + public func - (lhs: Date, rhs: Date) -> TimeInterval { + + return lhs.timeIntervalSinceReferenceDate - rhs.timeIntervalSinceReferenceDate + } - lhs = lhs - rhs -} +#endif diff --git a/Sources/SwiftFoundation/DateComponents.swift b/Sources/SwiftFoundation/DateComponents.swift index 3d56486..e8b3340 100644 --- a/Sources/SwiftFoundation/DateComponents.swift +++ b/Sources/SwiftFoundation/DateComponents.swift @@ -8,6 +8,7 @@ #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) import Darwin.C + import Foundation #elseif os(Linux) import Glibc #endif @@ -35,7 +36,7 @@ public struct DateComponents { public var dayOfYear: Int32 = 1 /// Intializes from a time interval interval between the current date and 1 January 1970, GMT. - public init(since1970 timeinterval: TimeInterval) { + public init(timeIntervalSince1970 timeinterval: TimeInterval) { self.init(brokenDown: tm(UTCSecondsSince1970: timeval(timeInterval: timeinterval).tv_sec )) } @@ -47,11 +48,12 @@ public struct DateComponents { /// Initializes from a `Date`. public init(date: Date) { - self.init(since1970: date.since1970) + self.init(timeIntervalSince1970: date.timeIntervalSince1970) } public var date: Date { - return Date(since1970: timeInterval) + + return Date(timeIntervalSince1970: timeInterval) } /// Get the value for the specified component. diff --git a/Sources/SwiftFoundation/POSIXFileStatus.swift b/Sources/SwiftFoundation/POSIXFileStatus.swift index 79a3de4..f7d9107 100644 --- a/Sources/SwiftFoundation/POSIXFileStatus.swift +++ b/Sources/SwiftFoundation/POSIXFileStatus.swift @@ -39,8 +39,8 @@ public extension stat { /// Other routines, like ```mmap```, may or may not update ```st_atime```. var lastAccessDate: Date { - get { return Date(since1970: st_atimespec.timeIntervalValue) } - set { st_atimespec = timespec(timeInterval: lastDataModificationDate.since1970) } + get { return Date(timeIntervalSince1970: st_atimespec.timeInterval) } + set { st_atimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } } /// Date of last data modification. Date of ```st_mtimespec``` or ```st_mtime```. @@ -50,8 +50,8 @@ public extension stat { /// The ```st_mtime``` field is not changed for changes in owner, group, hard link count, or mode. var lastDataModificationDate: Date { - get { return Date(since1970: st_mtimespec.timeIntervalValue) } - set { st_mtimespec = timespec(timeInterval: lastDataModificationDate.since1970) } + get { return Date(timeIntervalSince1970: st_mtimespec.timeInterval) } + set { st_mtimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } } /// Date of last status change. Date of ```st_ctimespec``` or ```st_ctime```. @@ -59,15 +59,15 @@ public extension stat { /// The field ```st_ctime``` is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.). var lastStatusChangeDate: Date { - get { return Date(since1970: st_ctimespec.timeIntervalValue) } - set { st_ctimespec = timespec(timeInterval: lastDataModificationDate.since1970) } + get { return Date(timeIntervalSince1970: st_ctimespec.timeInterval) } + set { st_ctimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } } /// Date file was created. Date of ```st_birthtimespec``` or ```st_birthtime```. var creationDate: Date { - get { return Date(since1970: st_birthtimespec.timeIntervalValue) } - set { st_birthtimespec = timespec(timeInterval: lastDataModificationDate.since1970) } + get { return Date(timeIntervalSince1970: st_birthtimespec.timeInterval) } + set { st_birthtimespec = timespec(timeInterval: lastDataModificationDate.timeIntervalSince1970) } } #endif diff --git a/Sources/SwiftFoundation/UUID.swift b/Sources/SwiftFoundation/UUID.swift index d68eea2..33106f1 100644 --- a/Sources/SwiftFoundation/UUID.swift +++ b/Sources/SwiftFoundation/UUID.swift @@ -133,8 +133,16 @@ public typealias UUID = Foundation.UUID + extension Foundation.UUID { + + public static var length: Int { return 16 } + public static var stringLength: Int { return 36 } + public static var unformattedStringLength: Int { return 32 } + } + extension Foundation.UUID: ByteValue { + @inline(__always) public init(bytes: uuid_t) { self.init(uuid: bytes) @@ -142,12 +150,28 @@ public var bytes: uuid_t { + @inline(__always) get { return uuid } + @inline(__always) set { self = Foundation.UUID(uuid: newValue) } } } + extension Foundation.UUID: RawRepresentable { + + @inline(__always) + public init?(rawValue uuidString: String) { + + self.init(uuidString: uuidString) + } + + public var rawValue: String { + + return uuidString + } + } + #endif // MARK: - DataConvertible diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index 67ffce6..6fde644 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -23,15 +23,9 @@ final class DataTests: XCTestCase { var testData = string.toUTF8Data() - let dataLength = testData.byteValue.count + XCTAssert(testData.isEmpty == false, "Could not create test data") - let dataPointer = UnsafeMutablePointer(allocatingCapacity: dataLength) - - defer { dataPointer.deallocateCapacity(dataLength) } - - memcpy(&testData.byteValue, dataPointer, dataLength) - - let data = Data.from(pointer: dataPointer, length: dataLength) + let data = testData.bytes.withUnsafeBufferPointer{ Data(bytes: $0.baseAddress!, count: testData.count) } XCTAssert(data == testData, "\(data) == \(testData)") } diff --git a/Sources/UnitTests/DateComponentsTest.swift b/Sources/UnitTests/DateComponentsTest.swift index bc597e5..cec3c78 100644 --- a/Sources/UnitTests/DateComponentsTest.swift +++ b/Sources/UnitTests/DateComponentsTest.swift @@ -20,7 +20,7 @@ final class DateComponentsTest: XCTestCase { dateComponents.month = 10 dateComponents.dayOfMonth = 10 - let assertionDate = Date(since1970: 560822400) + let assertionDate = SwiftFoundation.Date(timeIntervalSince1970: TimeInterval(560822400)) let madeDate = dateComponents.date print(assertionDate, madeDate) @@ -30,7 +30,7 @@ final class DateComponentsTest: XCTestCase { func testValueForComponent() { - let dateComponents = DateComponents(since1970: 560822400) + let dateComponents = DateComponents(timeIntervalSince1970: 560822400) XCTAssert(dateComponents[.year] == 1987) XCTAssert(dateComponents[.month] == 10) diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 5e34931..599fc70 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -37,17 +37,6 @@ final class JSONTests: XCTestCase { func parseJSON(_ jsonValue: JSON.Value, _ jsonString: String) { - #if os(OSX) || os(iOS) - - // validate JSON string on Darwin - do { - - try JSONSerialization.jsonObject(with: jsonString.toUTF8Data().toFoundation() as Foundation.Data, options: JSONSerialization.ReadingOptions(rawValue: 0)) - } - catch { XCTFail("Invalid JSON String"); return } - - #endif - guard let parsedJSONValue = JSON.Value(string: jsonString) else { XCTFail("JSON parsing failed"); return } @@ -86,17 +75,6 @@ final class JSONTests: XCTestCase { guard let jsonString = json.toString() else { XCTFail("Could not serialize JSON"); return } - #if os(OSX) || os(iOS) - - let foundationJSONOutput = try! JSONSerialization.data(withJSONObject: json.toFoundation().rawValue, options: JSONSerialization.WritingOptions(rawValue: 0)) - - let foundationJSONOutputString = NSString(data: foundationJSONOutput, encoding: String.Encoding.utf8.rawValue)! - - XCTAssert(jsonString == foundationJSONOutputString as String, "Must match Foundation output. \(jsonString) == \(foundationJSONOutputString)") - - XCTAssert(jsonString == foundationJSONOutputString as String, "Expected JSON string must match Foundation output. \(expectedJSONString) == \(foundationJSONOutputString)") - #endif - XCTAssert(jsonString == expectedJSONString, "Does not match expected output. \(jsonString) == \(expectedJSONString)") print("JSON Output: \(jsonString)") diff --git a/Sources/UnitTests/OrderTests.swift b/Sources/UnitTests/OrderTests.swift deleted file mode 100644 index ddaf881..0000000 --- a/Sources/UnitTests/OrderTests.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// OrderTests.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/3/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -import XCTest -import SwiftFoundation - -final class OrderTests: XCTestCase { - - static let allTests: [(String, (OrderTests) -> () throws -> Void)] = [("testComparisonResult", testComparisonResult)] - - func testComparisonResult() { - - // number - - XCTAssert((1 as Int).compare(2) == .ascending) - - XCTAssert((2 as Int).compare(1) == .descending) - - XCTAssert((1 as Int).compare(1) == .same) - - // string - - XCTAssert("a".compare("b") == .ascending) - - XCTAssert("b".compare("a") == .descending) - - XCTAssert("a".compare("a") == .same) - - // dates - - let now = SwiftFoundation.Date() - - let later = now + 0.5 - - XCTAssert(now.compare(later) == .ascending) - - XCTAssert(now < later) - } -} - diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index 7c3f6fb..2455a0f 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -38,22 +38,22 @@ final class POSIXTimeTests: XCTestCase { func testTimeVal() { - let date = SwiftFoundation.Date() + let date = Date() - let time = timeval(timeInterval: date.since1970) + let time = timeval(timeInterval: date.timeIntervalSince1970) - XCTAssert(Int(time.timeIntervalValue) == Int(date.since1970), "TimeVal derived interval: \(time.timeIntervalValue) must equal Date's timeIntervalSince1970 \(date.since1970)") + XCTAssert(Int(time.timeInterval) == Int(date.timeIntervalSince1970), "TimeVal derived interval: \(time.timeInterval) must equal Date's timeIntervalSince1970 \(date.timeIntervalSince1970)") } func testTimeSpec() { - let date = SwiftFoundation.Date() + let date = Date() - let time = timespec(timeInterval: date.since1970) + let time = timespec(timeInterval: date.timeIntervalSince1970) #if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - XCTAssert(time.timeIntervalValue == date.since1970, "timespec: \(time.timeIntervalValue) == Date: \(date)") + XCTAssert(time.timeInterval == date.timeIntervalSince1970, "timespec: \(time.timeInterval) == Date: \(date)") #elseif os(Linux) diff --git a/Sources/UnitTests/UUIDTests.swift b/Sources/UnitTests/UUIDTests.swift index 1c57c09..5663687 100644 --- a/Sources/UnitTests/UUIDTests.swift +++ b/Sources/UnitTests/UUIDTests.swift @@ -48,14 +48,14 @@ final class UUIDTests: XCTestCase { } func testBytes() { - - let expectedData = Data(byteValue: [91, 254, 177, 148, 104, 196, 72, 232, 143, 67, 60, 88, 99, 100, 203, 111]) + + let expectedData = Data(bytes: [91, 254, 177, 148, 104, 196, 72, 232, 143, 67, 60, 88, 99, 100, 203, 111] as [Byte]) let stringValue = "5BFEB194-68C4-48E8-8F43-3C586364CB6F" guard let uuid = UUID(rawValue: stringValue) else { XCTFail("Could not create UUID from " + stringValue); return } - XCTAssert(uuid.toData() == expectedData, "Unexpected UUID data \(uuid.toData().byteValue)") + XCTAssert(uuid.toData() == expectedData, "Unexpected UUID data \(uuid.toData().bytes)") } } diff --git a/Sources/UnitTests/main.swift b/Sources/UnitTests/main.swift index 7c5b8e6..195a913 100644 --- a/Sources/UnitTests/main.swift +++ b/Sources/UnitTests/main.swift @@ -17,14 +17,11 @@ import XCTest #endif XCTMain([testCase(DateComponentsTest.allTests), - testCase(OrderTests.allTests), testCase(POSIXTimeTests.allTests), testCase(RegularExpressionTests.allTests), - testCase(SortDescriptorTests.allTests), testCase(StringTests.allTests), testCase(UUIDTests.allTests), testCase(DataTests.allTests), testCase(JSONTests.allTests), - testCase(RangeTests.allTests), - testCase(AtomicTests.allTests) + testCase(RangeTests.allTests) ]) diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 93f7342..11fb5b4 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -111,13 +111,11 @@ 6E2C2C0F1C20F76700B2C995 /* Transformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B481C20F6EB00B2C995 /* Transformer.swift */; }; 6E2C2C161C20F76700B2C995 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */; }; 6E2C2C171C20F76B00B2C995 /* DateComponentsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */; }; - 6E2C2C181C20F76B00B2C995 /* OrderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */; }; 6E2C2C191C20F76B00B2C995 /* POSIXTimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */; }; 6E2C2C1A1C20F76B00B2C995 /* RegularExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */; }; 6E2C2C1C1C20F76B00B2C995 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */; }; 6E2C2C1D1C20F76B00B2C995 /* UUIDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B571C20F6EB00B2C995 /* UUIDTests.swift */; }; 6E2C2C1E1C20F76D00B2C995 /* DateComponentsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */; }; - 6E2C2C1F1C20F76D00B2C995 /* OrderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */; }; 6E2C2C201C20F76D00B2C995 /* POSIXTimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */; }; 6E2C2C211C20F76D00B2C995 /* RegularExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */; }; 6E2C2C231C20F76D00B2C995 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */; }; @@ -246,7 +244,6 @@ 6E2C2B4E1C20F6EB00B2C995 /* UUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UUID.swift; sourceTree = ""; }; 6E2C2B4F1C20F6EB00B2C995 /* Version.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateComponentsTest.swift; sourceTree = ""; }; - 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderTests.swift; sourceTree = ""; }; 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSIXTimeTests.swift; sourceTree = ""; }; 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularExpressionTests.swift; sourceTree = ""; }; 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; @@ -385,7 +382,6 @@ children = ( 6E2C2C2E1C2128C600B2C995 /* main.swift */, 6E2C2B511C20F6EB00B2C995 /* DateComponentsTest.swift */, - 6E2C2B521C20F6EB00B2C995 /* OrderTests.swift */, 6E2C2B531C20F6EB00B2C995 /* POSIXTimeTests.swift */, 6E2C2B541C20F6EB00B2C995 /* RegularExpressionTests.swift */, 6E2C2B561C20F6EB00B2C995 /* StringTests.swift */, @@ -788,7 +784,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6E2C2C181C20F76B00B2C995 /* OrderTests.swift in Sources */, 6E2C2C301C2128C600B2C995 /* main.swift in Sources */, 6EFF9A1F1CAD11F600917CB3 /* Range.swift in Sources */, 6E2C2C1D1C20F76B00B2C995 /* UUIDTests.swift in Sources */, @@ -855,7 +850,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6E2C2C1F1C20F76D00B2C995 /* OrderTests.swift in Sources */, 6E2C2C2F1C2128C600B2C995 /* main.swift in Sources */, 6E2C2C241C20F76D00B2C995 /* UUIDTests.swift in Sources */, 6E957C571C442E3E003F3C51 /* JSONTests.swift in Sources */, From e9d7e9bc4ce54cb19c1dbb464f310dff32c235cf Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 30 Jun 2016 03:46:57 -0500 Subject: [PATCH 49/68] #31 Updated Travis CI for Xcode 8 --- .travis.yml | 6 ++++-- Sources/SwiftFoundation/Decimal.swift | 17 ----------------- Sources/UnitTests/StringTests.swift | 5 ----- Xcode/SwiftFoundation.xcodeproj/project.pbxproj | 8 -------- 4 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 Sources/SwiftFoundation/Decimal.swift diff --git a/.travis.yml b/.travis.yml index b29d53a..a22c22a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: generic +osx_image: xcode8 os: - linux + - osx sudo: required dist: trusty before_install: @@ -11,9 +13,9 @@ install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install clang uuid-dev libjson-c-dev ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/development/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-3.0-preview-1/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi env: - - SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a + - SWIFT_VERSION=swift-3.0-PREVIEW-1 script: - uname - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi diff --git a/Sources/SwiftFoundation/Decimal.swift b/Sources/SwiftFoundation/Decimal.swift deleted file mode 100644 index be67f90..0000000 --- a/Sources/SwiftFoundation/Decimal.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// Decimal.swift -// SwiftFoundation -// -// Created by Alsey Coleman Miller on 7/23/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -/// Describes a decimal number. -public struct Decimal { - - public var exponent: UInt = 0 - - public var integer: Int = 0 - - public init() { } -} \ No newline at end of file diff --git a/Sources/UnitTests/StringTests.swift b/Sources/UnitTests/StringTests.swift index eebfe42..bcef604 100644 --- a/Sources/UnitTests/StringTests.swift +++ b/Sources/UnitTests/StringTests.swift @@ -24,9 +24,4 @@ final class StringTests: XCTestCase { XCTAssert(string == decodedString, "\(string) == \(decodedString)") } - - // MARK: - Performance Tests - - - } diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index 11fb5b4..fcf22ec 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -22,7 +22,6 @@ 6E2C2B831C20F76600B2C995 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B241C20F6EB00B2C995 /* Data.swift */; }; 6E2C2B841C20F76600B2C995 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B251C20F6EB00B2C995 /* Date.swift */; }; 6E2C2B851C20F76600B2C995 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */; }; - 6E2C2B861C20F76600B2C995 /* Decimal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B271C20F6EB00B2C995 /* Decimal.swift */; }; 6E2C2B871C20F76600B2C995 /* FileDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B281C20F6EB00B2C995 /* FileDescriptor.swift */; }; 6E2C2B881C20F76600B2C995 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B291C20F6EB00B2C995 /* FileManager.swift */; }; 6E2C2B891C20F76600B2C995 /* FilePermission.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2A1C20F6EB00B2C995 /* FilePermission.swift */; }; @@ -54,7 +53,6 @@ 6E2C2BB71C20F76600B2C995 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B241C20F6EB00B2C995 /* Data.swift */; }; 6E2C2BB81C20F76600B2C995 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B251C20F6EB00B2C995 /* Date.swift */; }; 6E2C2BB91C20F76600B2C995 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */; }; - 6E2C2BBA1C20F76600B2C995 /* Decimal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B271C20F6EB00B2C995 /* Decimal.swift */; }; 6E2C2BBB1C20F76600B2C995 /* FileDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B281C20F6EB00B2C995 /* FileDescriptor.swift */; }; 6E2C2BBC1C20F76600B2C995 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B291C20F6EB00B2C995 /* FileManager.swift */; }; 6E2C2BBD1C20F76600B2C995 /* FilePermission.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2A1C20F6EB00B2C995 /* FilePermission.swift */; }; @@ -86,7 +84,6 @@ 6E2C2BEB1C20F76700B2C995 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B241C20F6EB00B2C995 /* Data.swift */; }; 6E2C2BEC1C20F76700B2C995 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B251C20F6EB00B2C995 /* Date.swift */; }; 6E2C2BED1C20F76700B2C995 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */; }; - 6E2C2BEE1C20F76700B2C995 /* Decimal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B271C20F6EB00B2C995 /* Decimal.swift */; }; 6E2C2BEF1C20F76700B2C995 /* FileDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B281C20F6EB00B2C995 /* FileDescriptor.swift */; }; 6E2C2BF01C20F76700B2C995 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B291C20F6EB00B2C995 /* FileManager.swift */; }; 6E2C2BF11C20F76700B2C995 /* FilePermission.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B2A1C20F6EB00B2C995 /* FilePermission.swift */; }; @@ -217,7 +214,6 @@ 6E2C2B241C20F6EB00B2C995 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 6E2C2B251C20F6EB00B2C995 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = ""; }; 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateComponents.swift; sourceTree = ""; }; - 6E2C2B271C20F6EB00B2C995 /* Decimal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decimal.swift; sourceTree = ""; }; 6E2C2B281C20F6EB00B2C995 /* FileDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileDescriptor.swift; sourceTree = ""; }; 6E2C2B291C20F6EB00B2C995 /* FileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManager.swift; sourceTree = ""; }; 6E2C2B2A1C20F6EB00B2C995 /* FilePermission.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilePermission.swift; sourceTree = ""; }; @@ -347,7 +343,6 @@ 6E2C2B241C20F6EB00B2C995 /* Data.swift */, 6E2C2B251C20F6EB00B2C995 /* Date.swift */, 6E2C2B261C20F6EB00B2C995 /* DateComponents.swift */, - 6E2C2B271C20F6EB00B2C995 /* Decimal.swift */, 6EE84DD81CAF659800A40C4D /* Endianness.swift */, 6E2C2B281C20F6EB00B2C995 /* FileDescriptor.swift */, 6E2C2B291C20F6EB00B2C995 /* FileManager.swift */, @@ -704,7 +699,6 @@ 6E2C2BD91C20F76600B2C995 /* String.swift in Sources */, 6E2C2BCE1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2BC61C20F76600B2C995 /* Integer.swift in Sources */, - 6E2C2BBA1C20F76600B2C995 /* Decimal.swift in Sources */, 6E2C2BC91C20F76600B2C995 /* Null.swift in Sources */, 6E2C2BB01C20F76600B2C995 /* BitMaskOption.swift in Sources */, 6E2C2BD51C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */, @@ -751,7 +745,6 @@ 6E2C2BA51C20F76600B2C995 /* String.swift in Sources */, 6E2C2B9A1C20F76600B2C995 /* POSIXRegularExpression.swift in Sources */, 6E2C2B921C20F76600B2C995 /* Integer.swift in Sources */, - 6E2C2B861C20F76600B2C995 /* Decimal.swift in Sources */, 6E2C2B951C20F76600B2C995 /* Null.swift in Sources */, 6E2C2B7C1C20F76600B2C995 /* BitMaskOption.swift in Sources */, 6E2C2BA11C20F76600B2C995 /* RegularExpressionCompileOption.swift in Sources */, @@ -818,7 +811,6 @@ 6E2C2BFA1C20F76700B2C995 /* Integer.swift in Sources */, 6E8474CD1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */, 6EFF9A1B1CAD0C6B00917CB3 /* Range.swift in Sources */, - 6E2C2BEE1C20F76700B2C995 /* Decimal.swift in Sources */, 6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */, 6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */, 6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */, From b9408543943138796f03d56f52fdeb3999bdcec5 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 30 Jun 2016 03:50:50 -0500 Subject: [PATCH 50/68] Fixed #31 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a22c22a..a1c9a3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: generic osx_image: xcode8 os: - linux - - osx + - osx sudo: required dist: trusty before_install: From ee3b33fb1b284ca7d59a5eaac7f053e8b0f0764e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 30 Jun 2016 04:01:18 -0500 Subject: [PATCH 51/68] Fixed Linux support for Thread --- Sources/SwiftFoundation/Thread.swift | 58 ++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index e8d4fe7..6054001 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -28,21 +28,28 @@ public final class Thread { let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) #if os(Linux) + var internalThread: pthread_t = 0 - #elseif os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - var internalThread: pthread_t? = nil - #endif - - guard pthread_create(&internalThread, nil, ThreadPrivateMain, pointer) == 0 - else { throw POSIXError.fromErrno! } - - #if os(Linux) + + guard pthread_create(&internalThread, nil, ThreadPrivateMainLinux, pointer) == 0 + else { throw POSIXError.fromErrno! } + self.internalThread = internalThread + + pthread_detach(internalThread) + #elseif os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + + var internalThread: pthread_t? = nil + + guard pthread_create(&internalThread, nil, ThreadPrivateMainDarwin, pointer) == 0 + else { throw POSIXError.fromErrno! } + self.internalThread = internalThread! + + pthread_detach(internalThread!) + #endif - - pthread_detach(internalThread!) } // MARK: - Class Methods @@ -73,16 +80,35 @@ public final class Thread { // MARK: - Private -private func ThreadPrivateMain(arg: UnsafeMutablePointer) -> UnsafeMutablePointer? { +#if os(Linux) || XcodeLinux - let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) + private func ThreadPrivateMainLinux(arg: UnsafeMutablePointer?) -> UnsafeMutablePointer? { + + let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg!)) + + unmanaged.takeUnretainedValue().closure() + + unmanaged.release() + + return nil + } - unmanaged.takeUnretainedValue().closure() +#endif + +#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - unmanaged.release() + private func ThreadPrivateMainDarwin(arg: UnsafeMutablePointer) -> UnsafeMutablePointer? { + + let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg)) + + unmanaged.takeUnretainedValue().closure() + + unmanaged.release() + + return nil + } - return nil -} +#endif private extension Thread { From 36a24c9502e7172f0b333a4b19bae45689523086 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Fri, 1 Jul 2016 01:18:08 -0500 Subject: [PATCH 52/68] deleted playground --- Introduction.playground/Contents.swift | 38 ------------------ Introduction.playground/contents.xcplayground | 4 -- .../contents.xcworkspacedata | 7 ---- .../UserInterfaceState.xcuserstate | Bin 7628 -> 0 bytes Introduction.playground/timeline.xctimeline | 16 -------- Sources/UnitTests/DataTests.swift | 2 +- 6 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 Introduction.playground/Contents.swift delete mode 100644 Introduction.playground/contents.xcplayground delete mode 100644 Introduction.playground/playground.xcworkspace/contents.xcworkspacedata delete mode 100644 Introduction.playground/playground.xcworkspace/xcuserdata/Coleman.xcuserdatad/UserInterfaceState.xcuserstate delete mode 100644 Introduction.playground/timeline.xctimeline diff --git a/Introduction.playground/Contents.swift b/Introduction.playground/Contents.swift deleted file mode 100644 index 6de0165..0000000 --- a/Introduction.playground/Contents.swift +++ /dev/null @@ -1,38 +0,0 @@ -//: SwiftFoundation Introduction -//: -//: On Xcode, make sure you compile the ```SwiftFoundation OS X``` target first. - -import SwiftFoundation - -var str = "Hello, SwiftFoundation" - -//: SwiftFoundation is a Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. -//: You can use it in places where Apple's Foundation library is unavailible (e.g. Linux) - -let randomUUID = UUID() - -randomUUID.rawValue - -//: SwiftFoundation aims to provide the a similar *interface* and *implementation* as Foundation, but upgraded for Swift and adopting Protocol-Oriented Programming where feasible. - -import Foundation - -let validRawUUID = "7ADBFDE5-0311-441F-AA77-CC7BBECFA949" - -let uuid = UUID(rawValue: validRawUUID)! - -let foundationUUID = NSUUID(UUIDString: validRawUUID)! - -uuid.rawValue == foundationUUID.UUIDString - -1.compare(2) - -("a" as NSString).compare("b" as String).rawValue - -NSComparisonResult.OrderedAscending.rawValue - -NSComparisonResult.OrderedDescending.rawValue - -NSComparisonResult.OrderedSame.rawValue - - diff --git a/Introduction.playground/contents.xcplayground b/Introduction.playground/contents.xcplayground deleted file mode 100644 index 3de2b51..0000000 --- a/Introduction.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Introduction.playground/playground.xcworkspace/contents.xcworkspacedata b/Introduction.playground/playground.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/Introduction.playground/playground.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Introduction.playground/playground.xcworkspace/xcuserdata/Coleman.xcuserdatad/UserInterfaceState.xcuserstate b/Introduction.playground/playground.xcworkspace/xcuserdata/Coleman.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index 38acb352ed4e6beeef0e250da235f07fd5c9dbbc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7628 zcmcIod3;mV@}F~(G~2z&&2p2nNDD2pbz>=Q6@`|zSfB+-DWwHM+T4~vnv^63DprPF zMBG6{MB0J~q9}@rxFCw?&yR?}^Z9)0)AwA_r{b=l{Lam7(gyYO^PgYRCO2p1%$YMY z=R0$zuG#MkM{;sb0|5#uP=f}N=u`Aib^0PH6!rxJ)#<^y`BHr(JTu)Bs-Nd$!72Xw*?*a`Q+F1R0d!yb459)bPv1Uv_a z;dwX$FThcF4UWTG@DF$!{t0K{8~7H!gYV%7_z`}BpWzoc2fqBk!muBG>}FTB+X+)cKU4$?_>lRe}ya)3Neo*;+FYvee2otz+Vkdx#TIZggX{zE<_ACa%f*W^3$ z3pqzFP@qZFKuy$4ZPZSaX*wN9FQtR%U^!aioy@$)<(PklrRP4fgArP){c zyi%dxUltCxNG$4-3+wBpa5xxhEer&LEa;e9XZXC4d2V6gMe4q)MGnVFLq!#42>C(peAo{A3M{?Q}NBdyDTd>7lUF?fS5Zg&7_+SC#&Z=;AkLhC; z3cw;r-338thJ_GIzGBU5EIH$BAv!t+eMCPawc{!Pdxx@1_^GD|9kIK&e9~e?TwIh) zyU3RbB8sK3uQBik5@dxG`93K;o2j5ciOea0TX6mf1jg*P7ao#vaEFv|96&E}TgFE0cIDnVoxNc~B5)Og20}jGdcsY*gfT!UZyaKPpv9p<&o`EN@ z-}1)GJ&gfhq{S;uO&hmXIeUsr7r=`h^5Kf9_7c2uk>ppI)ZOqdya)e+_u&KhH~a@agpY6nUWH{i5hvkfEXN9*vYQ3nr|=n^Vc%cCf7$0( zEbOM@)#zg1l{lS!Rz;yx_GBm&43+x)3=VyP#*%=Xb-Xf0be$%auvt`E*Z@n4eou2) z@-l82DCMz|CC#3ISMn-5l&8s|5-w`3Y;9)HBFY0@AgSz`N$;8(7bml_G5J6%)xpKu zxCJYt#rY?&^xDiO*rP`|dXh)v7G$L67Zk(}@_G1mJ5EzPet`f((yn~!k|LdOfe^@L z37Gwe1|3m#u`>)HNicXj^2)fr$2b>#?s5h(69=T;M+9OaR$_zqh=|oV6Kk-RIb+s+ z#0fQ|7yIu+`r>S6ZZG?9z((2Va>W%ln;iI+A*l<6mF>q8+3(FDqi{TQ5@Zxf4Z)BU zpP`8C%h+Ax%jLqUB^;-9xtJAPGP%n+@`Tvl(#fS@Z6^b9PCFTdZn;X7S*tvLmLChF z>c&`ykxX{5Ne0esCt2vhlvzEIAjUO<T;}CI^x&*Yiop>4Q`(?Cf9@i5s$UL$jfpZgS z!ciEIITvqF;9N)|Jvm7WS%l5FP&T`q3*xXVgYEB@SxVMG>K<|}X(QK>WdzA`vVyE6 ztH^2$V+31p5iZ6h*oxQSQoME#i^%KAI#v~IhRtLHxry9NZefwxhWE1CAeX(j<70RL zpNZO8KFP&WT}xx56jCyWgXyCne>p2F-7K(J4IJ{aY{m%P(3(=?t`YFK&8 zGHTDrzK7f^2f{YIuAOYhW%4cuDyw&8-#=R*7BD-=eX@X^i0xz-F2|J0a*r<%qdq|P zfwhzDB@dE^a0RZ!Rh{HvX6XI6nwj<<*`q@emXlAWlOyB>T#MJ^I=lhbPc zP4W&{|M&_)-j%NqoFSi+FUWt% zm+Uyk^q3s1kH+1cZXKt34hXkr1;JuIg+mLHc)X^743rr}+92i}dh<7T&z9j^is zY@>+FiWhwGqCoNXS=rm);6~!CKv$NQ}k~%FE*ZGXF(}VpRbZ zn5C%&x8X2${<;%T>;^HqEtZ9-NLghdXR5Avq`hcA)*Yd}X&>5`UV`n|ft|Qx2Th@= zv_BnyJMjU05Ff&n>d8_=v}&I@&DS_D`c$LfQWR~KVk%bI$I&si%n+I-FEf-5qZu?4 z@55bqKknYaioeZtIBUZ6Wg)PKp*+L9K2@HOPd>El#w0C{7HrczixtrW4tffli{6@nPH_Pt|k^oz^q0GW%CD z+dm>F;8oH5%gXs^6+o+LZ31T>I-B|EQJHh)Pd!sL_0YOR-%7MGuF*VvJf_hCStCDf z!YA;lZjG90IANU#ZNVq;Ada2M0$IUThCp)@R=kF`CCs^wF2h6kbgU+eB|W7!m~}Wh z_cUEaSJO2tYS%&rT}N+V^>Zi~j3}`r=fes)dkfA+Dd1}fD=W*ld1*;Rp(HmeEtTJq z@F;5nJ&P~DNpGYZ*aA1vo9QiVk+t-8*2BC5c2~2$vELh#0#(f(_8FvvGWBbuC~hO^B#OYj)Zi(jD&cE zMO7m3{V`Z6u#~VZx`%D-cG%6Dhr975rp+-Kw`4HbCoi^+*+FR&&`0TGZeb8}VjQOv zZqE`ZRrJdNj8q zVZHudFo5+=b6IbHEbDK-O+I10?O!NiJ#8K9YMZHrb+tu?HZIn&_R$5jiS?`((rf6o z^g4>HYrTr~s~@4q=|}WSdX|1mzgJO}LFG^-t9q;YszR!zsx_*cRU1`XRGq55sza(H zs{c`)QoX5qOZB$u6V(~j7pkvRXI0;-`>KbiGt^n?;p&mGUSY4{VO1(|}fckOu zlj^6`Pph9*A6CDreog(l`VI9d_21NgSAV1Fr5U6t(#+R{HA^+uYF2A*)NIr|pxLi^ zPIFlEn&utNdz$w(|JHn{`B?L*=8WcN%{k4lnhQxJNtL8Y(kAJXl9R?HElAp%bUf*d zR-^5w9i$zq&Cq6P^R#2MW!f6;EbScaTy34!t8LKE)6Ul})wXGuX_sqPYFBI5YS(Gk zYd2``(;n0w)qbzj>GE_Fb=A5WT|~EBw@SB0w@$ZSw?Wsg+oRj3dqnrB?tt!y?wIZs z-K)A2x|6!ox;J$n>VDMyq$hfV-mLGd@2^kO57ZCUXXvx^Ir;*9slHr4MSr#4rLWP? z($CS))z|4)=r`#P>R;0TL;p|xyZV3WKhXb2|B?O^{b%~m^}iXwKn-d`l0j!M7&wE; zAQ-HMOv4z%RD;(LHmouy0xlgz=+!x$e+*$5h9(Wb6;dQ)$=lEWHU%nsTpHJfl@>zT?pT`&Qm-AQf z6Zt9p)x3+Z=4<#_{2acKkMOPhQofB}!LQ=i@YnOV^4s`MekZ?+-^)M5Kg{pvkMhU) zfAU}R-|*k@Kkz^Czwqbz-%MblCbg-TsgLOrQ;Mm-Da|y{G{`i>G|ZG~$~G05YE2Q- z3e#Pt9j2#D@0!k<&YSgS&TKMU%r>)VzQR1wTyCCXo@TBzSD9LUY*MV!qaV zof*w5%&W`~n_o7+Z~n~uh51YK*XCaZPB00AU={3wLr4~S3qyoqLZ*-{3>QWUxk8>$ zAe0KzgeGCRaF1|EI3|1`d@1}aoD+T(E?9^~WieR#6VYYl*p{>|fYP-rd*VbeU*n+l&w(D$bZR>37Z5wPi z+cw*_*tXiX*|ys{Y!BED*bdv?vVCOx()P9O8{2obA8Z%w#ICYy>{`3tKFD5dZ?vO* zo&5&;jrP0jTkYHI?e(8iV<;$RpoE6Tioi68e=N#wt&JE5doQItsJ3mjhB&Q`0PR@#^ SabSgX^hKXlzGI)sIsXgl(M!7k diff --git a/Introduction.playground/timeline.xctimeline b/Introduction.playground/timeline.xctimeline deleted file mode 100644 index b402ea0..0000000 --- a/Introduction.playground/timeline.xctimeline +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index 6fde644..768a92a 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -21,7 +21,7 @@ final class DataTests: XCTestCase { let string = "TestData" - var testData = string.toUTF8Data() + let testData = string.toUTF8Data() XCTAssert(testData.isEmpty == false, "Could not create test data") From 226500f62614154eed678f94c499cbf6c9346e10 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Fri, 1 Jul 2016 23:20:46 -0500 Subject: [PATCH 53/68] Updated Travis CI --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1c9a3b..dd8b7d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,8 @@ env: - SWIFT_VERSION=swift-3.0-PREVIEW-1 script: - uname - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool build -workspace SwiftFoundation.xcworkspace -scheme "SwiftFoundation iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -project SwiftFoundation.xcodeproj -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool build -project SwiftFoundation.xcodeproj -scheme "SwiftFoundation iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$(pwd)/tests/$SWIFT_VERSION-ubuntu14.04/usr/bin:"${PATH}" ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then swift build ; fi From dadd8ff7d5ab9ee81628910856d0f0732a70ac54 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 2 Jul 2016 00:43:02 -0500 Subject: [PATCH 54/68] Updated Travis CI For Darwin --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd8b7d4..9785fbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,8 @@ env: - SWIFT_VERSION=swift-3.0-PREVIEW-1 script: - uname - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -project SwiftFoundation.xcodeproj -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool build -project SwiftFoundation.xcodeproj -scheme "SwiftFoundation iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool test -project Xcode/SwiftFoundation.xcodeproj -scheme "SwiftFoundation OS X" -sdk macosx ONLY_ACTIVE_ARCH=NO ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xctool build -project Xcode/SwiftFoundation.xcodeproj -scheme "SwiftFoundation iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$(pwd)/tests/$SWIFT_VERSION-ubuntu14.04/usr/bin:"${PATH}" ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then swift build ; fi From 98e85ce883fb90324369bddad6f29639157169ad Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 2 Jul 2016 03:39:56 -0500 Subject: [PATCH 55/68] Updated SwiftPM package --- Package.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 7f329f9..4724b0b 100644 --- a/Package.swift +++ b/Package.swift @@ -2,11 +2,6 @@ import PackageDescription let package = Package( name: "SwiftFoundation", - dependencies: [ - .Package(url: "https://github.com/PureSwift/CUUID.git", majorVersion: 1), - .Package(url: "https://github.com/PureSwift/CStatfs.git", majorVersion: 1), - .Package(url: "https://github.com/PureSwift/CJSONC.git", majorVersion: 1) - ], targets: [ Target( name: "UnitTests", @@ -14,5 +9,10 @@ let package = Package( Target( name: "SwiftFoundation") ], + dependencies: [ + .Package(url: "https://github.com/PureSwift/CUUID.git", majorVersion: 1), + .Package(url: "https://github.com/PureSwift/CStatfs.git", majorVersion: 1), + .Package(url: "https://github.com/PureSwift/CJSONC.git", majorVersion: 1) + ], exclude: ["Xcode", "Carthage"] ) From 375a4295e954cdb8f5677fd69eeaea6be8c23f3e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 2 Jul 2016 03:41:15 -0500 Subject: [PATCH 56/68] Remove PureSwift/CUUID as a dependency --- Package.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Package.swift b/Package.swift index 4724b0b..10f4c85 100644 --- a/Package.swift +++ b/Package.swift @@ -10,7 +10,6 @@ let package = Package( name: "SwiftFoundation") ], dependencies: [ - .Package(url: "https://github.com/PureSwift/CUUID.git", majorVersion: 1), .Package(url: "https://github.com/PureSwift/CStatfs.git", majorVersion: 1), .Package(url: "https://github.com/PureSwift/CJSONC.git", majorVersion: 1) ], From e43136eb0a26c37a5309510477ec44c74612cd78 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 2 Jul 2016 12:15:46 -0500 Subject: [PATCH 57/68] Fixed Thread for latest Swift 3.0 on Linux --- Sources/SwiftFoundation/Thread.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index 6054001..bf620fa 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -80,11 +80,11 @@ public final class Thread { // MARK: - Private -#if os(Linux) || XcodeLinux +#if os(Linux) private func ThreadPrivateMainLinux(arg: UnsafeMutablePointer?) -> UnsafeMutablePointer? { - let unmanaged = Unmanaged.fromOpaque(OpaquePointer(arg!)) + let unmanaged = Unmanaged.fromOpaque(arg!) unmanaged.takeUnretainedValue().closure() From e1a7db99012802585e5bad31b930b5052024800f Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 2 Jul 2016 12:18:02 -0500 Subject: [PATCH 58/68] Working on Thread for latest Swift 3.0 on Linux --- Sources/SwiftFoundation/Thread.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftFoundation/Thread.swift b/Sources/SwiftFoundation/Thread.swift index bf620fa..86d2085 100644 --- a/Sources/SwiftFoundation/Thread.swift +++ b/Sources/SwiftFoundation/Thread.swift @@ -25,10 +25,10 @@ public final class Thread { let holder = Unmanaged.passRetained(Closure(closure: closure)) - let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) - #if os(Linux) + let pointer = UnsafeMutablePointer(holder.toOpaque()) + var internalThread: pthread_t = 0 guard pthread_create(&internalThread, nil, ThreadPrivateMainLinux, pointer) == 0 @@ -40,6 +40,8 @@ public final class Thread { #elseif os(OSX) || os(iOS) || os(watchOS) || os(tvOS) + let pointer = UnsafeMutablePointer(OpaquePointer(bitPattern: holder)) + var internalThread: pthread_t? = nil guard pthread_create(&internalThread, nil, ThreadPrivateMainDarwin, pointer) == 0 From 00f68bb27330f6256d5ff776efd7b48ad74fa60b Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 01:00:06 -0500 Subject: [PATCH 59/68] Updated unit test for Data --- Sources/UnitTests/DataTests.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index 768a92a..76be88b 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -16,7 +16,7 @@ import SwiftFoundation final class DataTests: XCTestCase { static let allTests: [(String, (DataTests) -> () throws -> Void)] = [("testFromBytePointer", testFromBytePointer)] - + func testFromBytePointer() { let string = "TestData" @@ -25,7 +25,13 @@ final class DataTests: XCTestCase { XCTAssert(testData.isEmpty == false, "Could not create test data") - let data = testData.bytes.withUnsafeBufferPointer{ Data(bytes: $0.baseAddress!, count: testData.count) } + let dataPointer = UnsafeMutablePointer(allocatingCapacity: testData.count) + + defer { dataPointer.deallocateCapacity(testData.count) } + + memcpy(dataPointer, testData.bytes, testData.count) + + let data = Data(bytes: dataPointer, count: testData.count) XCTAssert(data == testData, "\(data) == \(testData)") } From 1356ef97e4d13cb5dd2b4d0f791bd0585973930d Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 02:47:37 -0500 Subject: [PATCH 60/68] Updated JSON for Swift API Guidelines --- Sources/SwiftFoundation/JSON.swift | 241 ++++++++---------- Sources/SwiftFoundation/JSONExtensions.swift | 68 +++-- Sources/SwiftFoundation/JSONParse.swift | 24 +- .../SwiftFoundation/JSONSerialization.swift | 31 +-- Sources/UnitTests/JSONTests.swift | 48 ++-- .../SwiftFoundation.xcodeproj/project.pbxproj | 2 +- 6 files changed, 181 insertions(+), 233 deletions(-) diff --git a/Sources/SwiftFoundation/JSON.swift b/Sources/SwiftFoundation/JSON.swift index 5571ca5..450de21 100644 --- a/Sources/SwiftFoundation/JSON.swift +++ b/Sources/SwiftFoundation/JSON.swift @@ -14,59 +14,81 @@ public struct JSON { public typealias Object = [String: JSON.Value] /// JSON value type. - /// Guarenteed to be valid JSON if root value is array or object. + /// + /// - Note: Guarenteed to be valid JSON if root value is array or object. public enum Value: RawRepresentable, Equatable, CustomStringConvertible { - case Null + /// JSON value is a null placeholder. + case null - /// JSON value is a String Value - case String(StringValue) + /// JSON value is an array of other JSON values. + case array(SwiftFoundation.JSON.Array) - /// JSON value is a Number Value (specific subtypes) - case Number(JSON.Number) + /// JSON value a JSON object. + case object(SwiftFoundation.JSON.Object) - /// JSON value is an Array of other JSON values - case Array(JSONArray) + /// JSON value is a `String`. + case string(Swift.String) - /// JSON value a JSON object - case Object(JSONObject) + /// JSON value is a `Bool`. + case boolean(Bool) - // MARK: - Extract Values + /// JSON value is a `Int`. + case integer(Int) - public var arrayValue: JSON.Array? { - - switch self { - - case let .Array(value): return value - - default: return nil - } - } + /// JSON value is a `Double`. + case double(Swift.Double) + } +} + +// MARK: Extract Values + +public extension JSON.Value { + + public var arrayValue: JSON.Array? { - public var objectValue: JSON.Object? { - - switch self { - - case let .Object(value): return value - - default: return nil - } - } + guard case let .array(value) = self else { return nil } + + return value + } + + public var objectValue: JSON.Object? { + + guard case let .object(value) = self else { return nil } + + return value + } + + public var stringValue: String? { + + guard case let .string(value) = self else { return nil } + + return value } - // MARK: - JSON Number + public var booleanValue: Bool? { + + guard case let .boolean(value) = self else { return nil } + + return value + } - public enum Number: RawRepresentable, Equatable, CustomStringConvertible { + public var integerValue: Int? { - case Boolean(Bool) + guard case let .integer(value) = self else { return nil } - case Integer(Int) + return value + } + + public var doubleValue: Double? { + + guard case let .double(value) = self else { return nil } - case Double(DoubleValue) + return value } } -// MARK: - RawRepresentable +// MARK: RawRepresentable public extension JSON.Value { @@ -74,65 +96,83 @@ public extension JSON.Value { switch self { - case .Null: return SwiftFoundation.Null() + case .null: return SwiftFoundation.Null() + + case .string(let value): return value + + case .integer(let value): return value - case .String(let string): return string + case .boolean(let value): return value - case .Number(let number): return number.rawValue + case .double(let value): return value - case .Array(let array): return array.rawValues + case .array(let array): return array.rawValues - case .Object(let dictionary): + case .object(let dictionary): - var dictionaryValue = [StringValue: Any](minimumCapacity: dictionary.count) + var dictionaryValue = [String: Any](minimumCapacity: dictionary.count) for (key, value) in dictionary { dictionaryValue[key] = value.rawValue } - return dictionaryValue + return dictionary } } init?(rawValue: Any) { - guard (rawValue as? SwiftFoundation.Null) == nil else { + guard rawValue is SwiftFoundation.Null == false else { - self = .Null + self = .null return } if let string = rawValue as? Swift.String { - self = .String(string) + self = .string(string) return } - if let number = JSON.Number(rawValue: rawValue) { + if let integer = rawValue as? Int { - self = .Number(number) + self = .integer(integer) return } - if let rawArray = rawValue as? [Any], let jsonArray: [JSON.Value] = JSON.Value.from(rawValues: rawArray) { + if let boolean = rawValue as? Bool { - self = .Array(jsonArray) + self = .boolean(boolean) + return + } + + if let double = rawValue as? Double { + + self = .double(double) + return + } + + if let rawArray = rawValue as? [Any], + let jsonArray: [JSON.Value] = JSON.Value.from(rawValues: rawArray) { + + self = .array(jsonArray) return } if let rawDictionary = rawValue as? [Swift.String: Any] { - var jsonObject = [StringValue: JSONValue](minimumCapacity: rawDictionary.count) + var jsonObject: [Swift.String: JSON.Value] = Dictionary(minimumCapacity: rawDictionary.count) for (key, rawValue) in rawDictionary { - guard let jsonValue = JSON.Value(rawValue: rawValue) else { return nil } + guard let jsonValue = JSON.Value(rawValue: rawValue) + else { return nil } jsonObject[key] = jsonValue } - self = .Object(jsonObject) + self = .object(jsonObject) return } @@ -140,40 +180,11 @@ public extension JSON.Value { } } -public extension JSON.Number { - - public var rawValue: Any { - - switch self { - case .Boolean(let value): return value - case .Integer(let value): return value - case .Double(let value): return value - } - } - - public init?(rawValue: Any) { - - if let value = rawValue as? Bool { self = .Boolean(value); return } - if let value = rawValue as? Int { self = .Integer(value); return } - if let value = rawValue as? DoubleValue { self = .Double(value); return } - - return nil - } -} - -// MARK: - CustomStringConvertible +// MARK: CustomStringConvertible public extension JSON.Value { - public var description: Swift.String { - - return "\(rawValue)" - } -} - -public extension JSON.Number { - public var description: String { return "\(rawValue)" @@ -186,72 +197,20 @@ public func ==(lhs: JSON.Value, rhs: JSON.Value) -> Bool { switch (lhs, rhs) { - case (.Null, .Null): return true - - case let (.String(leftValue), .String(rightValue)): return leftValue == rightValue + case (.null, .null): return true - case let (.Number(leftValue), .Number(rightValue)): return leftValue == rightValue + case let (.string(leftValue), .string(rightValue)): return leftValue == rightValue - case let (.Array(leftValue), .Array(rightValue)): return leftValue == rightValue + case let (.boolean(leftValue), .boolean(rightValue)): return leftValue == rightValue - case let (.Object(leftValue), .Object(rightValue)): return leftValue == rightValue + case let (.integer(leftValue), .integer(rightValue)): return leftValue == rightValue - default: return false - } -} - -public func ==(lhs: JSON.Number, rhs: JSON.Number) -> Bool { - - switch (lhs, rhs) { + case let (.double(leftValue), .double(rightValue)): return leftValue == rightValue - case let (.Boolean(leftValue), .Boolean(rightValue)): return leftValue == rightValue + case let (.array(leftValue), .array(rightValue)): return leftValue == rightValue - case let (.Integer(leftValue), .Integer(rightValue)): return leftValue == rightValue - - case let (.Double(leftValue), .Double(rightValue)): return leftValue == rightValue + case let (.object(leftValue), .object(rightValue)): return leftValue == rightValue default: return false } } - -// MARK: - Protocol - -/// Type can be converted to JSON. -public protocol JSONEncodable { - - /// Encodes the reciever into JSON. - func toJSON() -> JSON.Value -} - -/// Type can be converted from JSON. -public protocol JSONDecodable { - - /// Decodes the reciever from JSON. - init?(JSONValue: JSON.Value) -} - -/// Type can be converted from JSON according to parameters. -public protocol JSONParametrizedDecodable { - - associatedtype JSONDecodingParameters - - /// Decodes the reciever from JSON according to the specified parameters. - init?(JSONValue: JSON.Value, parameters: JSONDecodingParameters) -} - -// Typealiases due to compiler error - -public typealias JSONValue = JSON.Value - -public typealias JSONArray = [JSONValue] - -public typealias JSONObject = [String: JSONValue] - -public typealias StringValue = String - -public typealias FloatValue = Float - -public typealias DoubleValue = Double - -public typealias NullValue = Null - diff --git a/Sources/SwiftFoundation/JSONExtensions.swift b/Sources/SwiftFoundation/JSONExtensions.swift index 281a71c..80e9708 100644 --- a/Sources/SwiftFoundation/JSONExtensions.swift +++ b/Sources/SwiftFoundation/JSONExtensions.swift @@ -6,13 +6,29 @@ // Copyright © 2015 PureSwift. All rights reserved. // +// MARK: Protocol + +/// Type can be converted to JSON. +public protocol JSONEncodable { + + /// Encodes the reciever into JSON. + func toJSON() -> JSON.Value +} + +/// Type can be converted from JSON. +public protocol JSONDecodable { + + /// Decodes the reciever from JSON. + init?(JSONValue: JSON.Value) +} + // MARK: - Primitive Types // MARK: Encodable extension String: JSONEncodable { - public func toJSON() -> JSON.Value { return .String(self) } + public func toJSON() -> JSON.Value { return .string(self) } } extension String: JSONDecodable { @@ -27,7 +43,7 @@ extension String: JSONDecodable { extension Int: JSONEncodable { - public func toJSON() -> JSON.Value { return .Number(.Integer(self)) } + public func toJSON() -> JSON.Value { return .integer(self) } } extension Int: JSONDecodable { @@ -42,7 +58,7 @@ extension Int: JSONDecodable { extension Double: JSONEncodable { - public func toJSON() -> JSON.Value { return .Number(.Double(self)) } + public func toJSON() -> JSON.Value { return .double(self) } } extension Double: JSONDecodable { @@ -57,7 +73,7 @@ extension Double: JSONDecodable { extension Bool: JSONEncodable { - public func toJSON() -> JSON.Value { return .Number(.Boolean(self)) } + public func toJSON() -> JSON.Value { return .boolean(self) } } extension Bool: JSONDecodable { @@ -78,16 +94,9 @@ public extension Collection where Iterator.Element: JSONEncodable { func toJSON() -> JSON.Value { - var jsonArray = JSON.Array() - - for jsonEncodable in self { - - let jsonValue = jsonEncodable.toJSON() - - jsonArray.append(jsonValue) - } + let jsonArray = self.map { $0.toJSON() } - return .Array(jsonArray) + return .array(jsonArray) } } @@ -96,7 +105,7 @@ public extension Dictionary where Value: JSONEncodable, Key: StringLiteralConver /// Encodes the reciever into JSON. func toJSON() -> JSON.Value { - var jsonObject = JSON.Object() + var jsonObject = JSON.Object(minimumCapacity: self.count) for (key, value) in self { @@ -107,7 +116,7 @@ public extension Dictionary where Value: JSONEncodable, Key: StringLiteralConver jsonObject[keyString] = jsonValue } - return .Object(jsonObject) + return .object(jsonObject) } } @@ -116,37 +125,20 @@ public extension Dictionary where Value: JSONEncodable, Key: StringLiteralConver public extension JSONDecodable { /// Decodes from an array of JSON values. - static func fromJSON(JSONArray: JSON.Array) -> [Self]? { + static func from(JSON array: SwiftFoundation.JSON.Array) -> [Self]? { - var jsonDecodables = [Self]() + var jsonDecodables: ContiguousArray = ContiguousArray() - for jsonValue in JSONArray { - - guard let jsonDecodable = self.init(JSONValue: jsonValue) else { return nil } - - jsonDecodables.append(jsonDecodable) - } + jsonDecodables.reserveCapacity(array.count) - return jsonDecodables - } -} - -public extension JSONParametrizedDecodable { - - /// Decodes from an array of JSON values. - static func fromJSON(JSONArray: JSON.Array, parameters: JSONDecodingParameters) -> [Self]? { - - var jsonDecodables = [Self]() - - for jsonValue in JSONArray { + for jsonValue in array { - guard let jsonDecodable = self.init(JSONValue: jsonValue, parameters: parameters) - else { return nil } + guard let jsonDecodable = self.init(JSONValue: jsonValue) else { return nil } jsonDecodables.append(jsonDecodable) } - return jsonDecodables + return Array(jsonDecodables) } } diff --git a/Sources/SwiftFoundation/JSONParse.swift b/Sources/SwiftFoundation/JSONParse.swift index 5fa31f7..1b3ed56 100755 --- a/Sources/SwiftFoundation/JSONParse.swift +++ b/Sources/SwiftFoundation/JSONParse.swift @@ -40,7 +40,7 @@ private extension JSON.Value { switch type { - case json_type_null: self = .Null + case json_type_null: self = .null case json_type_string: @@ -48,7 +48,7 @@ private extension JSON.Value { let string = Swift.String(validatingUTF8: stringPointer) ?? "" - self = JSON.Value.String(string) + self = JSON.Value.string(string) case json_type_boolean: @@ -56,7 +56,7 @@ private extension JSON.Value { let boolean: Bool = { if value == 0 { return false } else { return true } }() - self = .Number(.Boolean(boolean)) + self = .boolean(boolean) case json_type_int: @@ -65,25 +65,27 @@ private extension JSON.Value { // Handle integer overflow if value > Int64(Int.max) { - self = .Number(.Integer(Int.max)) + self = .integer(Int.max) } else { - self = .Number(.Integer(Int(value))) + self = .integer(Int(value)) } case json_type_double: let value = json_object_get_double(jsonObject) - self = .Number(.Double(value)) + self = .double(value) case json_type_array: - var array = [JSONValue]() - let arrayLength = json_object_array_length(jsonObject) + var array = ContiguousArray() + + array.reserveCapacity(Int(arrayLength)) + for i in 0 ..< arrayLength { let jsonValuePointer = json_object_array_get_idx(jsonObject, i) @@ -93,13 +95,13 @@ private extension JSON.Value { array.append(jsonValue) } - self = .Array(array) + self = .array(Array(array)) case json_type_object: let hashTable = json_object_get_object(jsonObject)! - var jsonDictionary = [StringValue: JSONValue]() + var jsonDictionary: [String: JSON.Value] = [:] var entry = hashTable.pointee.head @@ -118,7 +120,7 @@ private extension JSON.Value { entry = entry!.pointee.next } - self = .Object(jsonDictionary) + self = .object(jsonDictionary) default: fatalError("Unhandled case: \(type.rawValue)") } diff --git a/Sources/SwiftFoundation/JSONSerialization.swift b/Sources/SwiftFoundation/JSONSerialization.swift index d219952..44681c3 100755 --- a/Sources/SwiftFoundation/JSONSerialization.swift +++ b/Sources/SwiftFoundation/JSONSerialization.swift @@ -23,7 +23,7 @@ public extension JSON.Value { switch self { - case .Array(_), .Object(_): break + case .array(_), .object(_): break default: return nil } @@ -50,26 +50,21 @@ private extension JSON.Value { switch self { - case .Null: return nil + case .null: return nil - case .String(let value): return json_object_new_string(value) + case .string(let value): return json_object_new_string(value) - case .Number(let number): + case .boolean(let value): - switch number { - - case .Boolean(let value): - - let jsonBool: Int32 = { if value { return Int32(1) } else { return Int32(0) } }() - - return json_object_new_boolean(jsonBool) - - case .Integer(let value): return json_object_new_int64(Int64(value)) - - case .Double(let value): return json_object_new_double(value) - } + let jsonBool: Int32 = { if value { return Int32(1) } else { return Int32(0) } }() + + return json_object_new_boolean(jsonBool) + + case .integer(let value): return json_object_new_int64(Int64(value)) + + case .double(let value): return json_object_new_double(value) - case .Array(let arrayValue): + case .array(let arrayValue): let jsonArray = json_object_new_array() @@ -82,7 +77,7 @@ private extension JSON.Value { return jsonArray - case .Object(let dictionaryValue): + case .object(let dictionaryValue): let jsonObject = json_object_new_object() diff --git a/Sources/UnitTests/JSONTests.swift b/Sources/UnitTests/JSONTests.swift index 599fc70..6907f08 100755 --- a/Sources/UnitTests/JSONTests.swift +++ b/Sources/UnitTests/JSONTests.swift @@ -40,31 +40,31 @@ final class JSONTests: XCTestCase { guard let parsedJSONValue = JSON.Value(string: jsonString) else { XCTFail("JSON parsing failed"); return } - print("Parsed JSON: \(jsonValue)\n") + print("Parsed JSON: \(jsonValue)") XCTAssert(jsonValue == parsedJSONValue, "\(jsonValue) == \(parsedJSONValue)") } - parseJSON(.Object(["Key": .Null]), "{ \"Key\" : null }") + parseJSON(.object(["Key": .null]), "{ \"Key\" : null }") - parseJSON(.Object(["Key": .String("Value")]), "{ \"Key\" : \"Value\" }") + parseJSON(.object(["Key": .string("Value")]), "{ \"Key\" : \"Value\" }") - parseJSON(.Object(["Key": .Number(.Boolean(true))]), "{ \"Key\" : true }") + parseJSON(.object(["Key": .boolean(true)]), "{ \"Key\" : true }") - parseJSON(.Object(["Key": .Number(.Integer(10))]), "{ \"Key\" : 10 }") + parseJSON(.object(["Key": .integer(10)]), "{ \"Key\" : 10 }") - parseJSON(.Object(["Key": .Number(.Double(1.01))]), "{ \"Key\" : 1.01 }") + parseJSON(.object(["Key": .double(1.01)]), "{ \"Key\" : 1.01 }") - parseJSON(.Object(["Key": .Object(["Key2": .String("Value")])]), "{ \"Key\" : { \"Key2\" : \"Value\" } }") + parseJSON(.object(["Key": .object(["Key2": .string("Value")])]), "{ \"Key\" : { \"Key2\" : \"Value\" } }") - parseJSON(.Array([ - .Number(.Boolean(true)), - .Number(.Boolean(false)), - .Number(.Integer(10)), - .Number(.Double(10.1)), - .String("string"), - .Array([.String("subarrayValue1"), .String("subarrayValue2")]), - .Object(["subobjectKey": .String("subobjectValue")]) + parseJSON(.array([ + .boolean(true), + .boolean(false), + .integer(10), + .double(10.1), + .string("string"), + .array([.string("subarrayValue1"), .string("subarrayValue2")]), + .object(["subobjectKey": .string("subobjectValue")]) ]), "[true, false, 10, 10.1, \"string\", [\"subarrayValue1\", \"subarrayValue2\"], {\"subobjectKey\" : \"subobjectValue\"} ]") } @@ -80,17 +80,17 @@ final class JSONTests: XCTestCase { print("JSON Output: \(jsonString)") } - writeJSON(.Object([ - "Key": .String("Value") + writeJSON(.object([ + "Key": .string("Value") ]), "{\"Key\":\"Value\"}") - writeJSON(.Array([ - .String("value1"), - .String("value2"), - .Null, - .Number(.Boolean(true)), - .Number(.Integer(10)), - .Object(["Key": .String("Value")]) + writeJSON(.array([ + .string("value1"), + .string("value2"), + .null, + .boolean(true), + .integer(10), + .object(["Key": .string("Value")]) ]), "[\"value1\",\"value2\",null,true,10,{\"Key\":\"Value\"}]") } } diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index fcf22ec..b21b8a0 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -353,10 +353,10 @@ 6EE84DDC1CAF667E00A40C4D /* Hexadecimal.swift */, 6E2C2B2D1C20F6EB00B2C995 /* HTTP.swift */, 6E2C2B341C20F6EB00B2C995 /* JSON.swift */, + 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */, 6E957C251C43A7C8003F3C51 /* JSONParse.swift */, 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */, 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */, - 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */, 6E82FD711CBA06C10049CD1B /* Lock.swift */, 6E2C2B361C20F6EB00B2C995 /* Null.swift */, 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */, From fc476cfe0610add763cd39db2959a9e4b079e273 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:04:12 -0500 Subject: [PATCH 61/68] Added Base64 Foundation API --- Sources/SwiftFoundation/Base64.swift | 495 ++++++++++++++------------- 1 file changed, 258 insertions(+), 237 deletions(-) diff --git a/Sources/SwiftFoundation/Base64.swift b/Sources/SwiftFoundation/Base64.swift index 1032ed8..b4adbaa 100644 --- a/Sources/SwiftFoundation/Base64.swift +++ b/Sources/SwiftFoundation/Base64.swift @@ -5,254 +5,275 @@ // Created by Alsey Coleman Miller on 6/28/15. // Copyright © 2015 PureSwift. All rights reserved. // -// Encoding algorithm from https://github.com/drichardson/SwiftyBase64 -/// [Base64](https://en.wikipedia.org/wiki/Base64) encoding. -public struct Base64 { - - // MARK: - Encoding - - /** - Use the Base64 algorithm as decribed by RFC 4648 section 4 to - encode the input bytes. The alphabet specifies the translation - table to use. RFC 4648 defines two such alphabets: - - Standard (section 4) - - URL and Filename Safe (section 5) - - parameter bytes: Bytes to encode. - - parameter alphabet: The Base64 alphabet to encode with. - - returns: Base64 encoded ASCII bytes. - */ - public static func encode(data: Data, alphabet: Alphabet = .Standard) -> Data { +#if os(Linux) || XcodeLinux + + public extension Data { + + public struct Base64EncodingOptions : OptionSet { + public let rawValue : UInt + public init(rawValue: UInt) { self.rawValue = rawValue } + + public static let encoding64CharacterLineLength = Base64EncodingOptions(rawValue: UInt(1 << 0)) + public static let encoding76CharacterLineLength = Base64EncodingOptions(rawValue: UInt(1 << 1)) + public static let encodingEndLineWithCarriageReturn = Base64EncodingOptions(rawValue: UInt(1 << 4)) + public static let encodingEndLineWithLineFeed = Base64EncodingOptions(rawValue: UInt(1 << 5)) + } - let bytes = data.bytes + public struct Base64DecodingOptions : OptionSet { + public let rawValue : UInt + public init(rawValue: UInt) { self.rawValue = rawValue } + + public static let ignoreUnknownCharacters = Base64DecodingOptions(rawValue: UInt(1 << 0)) + } + + /* Create an NSData from a Base-64 encoded NSString using the given options. By default, returns nil when the input is not recognized as valid Base-64. + */ + public init?(base64Encoded base64String: String, options: Base64DecodingOptions) { + let encodedBytes = Array(base64String.utf8) + guard let decodedBytes = Data.base64DecodeBytes(encodedBytes, options: options) else { + return nil + } + self.init(bytes: decodedBytes, count: decodedBytes.count) + } - var encoded : [UInt8] = [] + /* Create a Base-64 encoded NSString from the receiver's contents using the given options. + */ + public func base64EncodedString(_ options: Base64EncodingOptions = []) -> String { + let encodedBytes = Data.base64EncodeBytes(bytes, options: options) + let characters = encodedBytes.map { Character(UnicodeScalar($0)) } + return String(characters) + } + + /* Create an NSData from a Base-64, UTF-8 encoded NSData. By default, returns nil when the input is not recognized as valid Base-64. + */ + public init?(base64Encoded base64Data: Data, options: Base64DecodingOptions) { + guard let decodedBytes = Data.base64DecodeBytes(base64Data.bytes, options: options) else { + return nil + } + self.init(bytes: decodedBytes, count: decodedBytes.count) + } + + /* Create a Base-64, UTF-8 encoded NSData from the receiver's contents using the given options. + */ + public func base64EncodedData(_ options: Base64EncodingOptions = []) -> Data { + let encodedBytes = Data.base64EncodeBytes(bytes, options: options) + return Data(bytes: encodedBytes, count: encodedBytes.count) + } + + /** + The ranges of ASCII characters that are used to encode data in Base64. + */ + private static let base64ByteMappings: [Range] = [ + 65 ..< 91, // A-Z + 97 ..< 123, // a-z + 48 ..< 58, // 0-9 + 43 ..< 44, // + + 47 ..< 48, // / + ] + /** + Padding character used when the number of bytes to encode is not divisible by 3 + */ + private static let base64Padding : UInt8 = 61 // = + + /** + This method takes a byte with a character from Base64-encoded string + and gets the binary value that the character corresponds to. + + - parameter byte: The byte with the Base64 character. + - returns: Base64DecodedByte value containing the result (Valid , Invalid, Padding) + */ + private enum Base64DecodedByte { + case valid(UInt8) + case invalid + case padding + } + private static func base64DecodeByte(_ byte: UInt8) -> Base64DecodedByte { + guard byte != base64Padding else {return .padding} + var decodedStart: UInt8 = 0 + for range in base64ByteMappings { + if range.contains(byte) { + let result = decodedStart + (byte - range.lowerBound) + return .valid(result) + } + decodedStart += range.upperBound - range.lowerBound + } + return .invalid + } - let table = Base64.table(for: alphabet) - let padding = table[64] + /** + This method takes six bits of binary data and encodes it as a character + in Base64. + + The value in the byte must be less than 64, because a Base64 character + can only represent 6 bits. + + - parameter byte: The byte to encode + - returns: The ASCII value for the encoded character. + */ + private static func base64EncodeByte(_ byte: UInt8) -> UInt8 { + assert(byte < 64) + var decodedStart: UInt8 = 0 + for range in base64ByteMappings { + let decodedRange = decodedStart ..< decodedStart + (range.upperBound - range.lowerBound) + if decodedRange.contains(byte) { + return range.lowerBound + (byte - decodedStart) + } + decodedStart += range.upperBound - range.lowerBound + } + return 0 + } - var i = 0 - let count = bytes.count - // for ; i+3 <= count; i += 3 - while i+3 <= count { + /** + This method decodes Base64-encoded data. + + If the input contains any bytes that are not valid Base64 characters, + this will return nil. + + - parameter bytes: The Base64 bytes + - parameter options: Options for handling invalid input + - returns: The decoded bytes. + */ + private static func base64DecodeBytes(_ bytes: [UInt8], options: Base64DecodingOptions = []) -> [UInt8]? { + var decodedBytes = [UInt8]() + decodedBytes.reserveCapacity((bytes.count/3)*2) - let one = bytes[i] >> 2 - let two = ((bytes[i] & 0b11) << 4) | ((bytes[i+1] & 0b11110000) >> 4) - let three = ((bytes[i+1] & 0b00001111) << 2) | ((bytes[i+2] & 0b11000000) >> 6) - let four = bytes[i+2] & 0b00111111 + var currentByte : UInt8 = 0 + var validCharacterCount = 0 + var paddingCount = 0 + var index = 0 - encoded.append(table[Int(one)]) - encoded.append(table[Int(two)]) - encoded.append(table[Int(three)]) - encoded.append(table[Int(four)]) - i += 3 - } - - if i+2 == count { - // (3) The final quantum of encoding input is exactly 16 bits; here, the - // final unit of encoded output will be three characters followed by - // one "=" padding character. - let one = bytes[i] >> 2 - let two = ((bytes[i] & 0b11) << 4) | ((bytes[i+1] & 0b11110000) >> 4) - let three = ((bytes[i+1] & 0b00001111) << 2) - encoded.append(table[Int(one)]) - encoded.append(table[Int(two)]) - encoded.append(table[Int(three)]) - encoded.append(padding) - } else if i+1 == count { - // (2) The final quantum of encoding input is exactly 8 bits; here, the - // final unit of encoded output will be two characters followed by - // two "=" padding characters. - let one = bytes[i] >> 2 - let two = ((bytes[i] & 0b11) << 4) - encoded.append(table[Int(one)]) - encoded.append(table[Int(two)]) - encoded.append(padding) - encoded.append(padding) - } else { - // (1) The final quantum of encoding input is an integral multiple of 24 - // bits; here, the final unit of encoded output will be an integral - // multiple of 4 characters with no "=" padding. - assert(i == count) + for base64Char in bytes { + + let value : UInt8 + + switch base64DecodeByte(base64Char) { + case .valid(let v): + value = v + validCharacterCount += 1 + case .invalid: + if options.contains(.ignoreUnknownCharacters) { + continue + } else { + return nil + } + case .padding: + paddingCount += 1 + continue + } + + //padding found in the middle of the sequence is invalid + if paddingCount > 0 { + return nil + } + + switch index%4 { + case 0: + currentByte = (value << 2) + case 1: + currentByte |= (value >> 4) + decodedBytes.append(currentByte) + currentByte = (value << 4) + case 2: + currentByte |= (value >> 2) + decodedBytes.append(currentByte) + currentByte = (value << 6) + case 3: + currentByte |= value + decodedBytes.append(currentByte) + default: + fatalError() + } + + index += 1 + } + + guard (validCharacterCount + paddingCount)%4 == 0 else { + //invalid character count + return nil + } + return decodedBytes } - return Data(bytes: encoded) - } -} - -// MARK: - Alphabet - -public extension Base64 { - - /** - Base64 Alphabet to use during encoding. - - Standard: The standard Base64 encoding, defined in RFC 4648 section 4. - - URLAndFilenameSafe: The base64url encoding, defined in RFC 4648 section 5. - */ - public enum Alphabet { - /// The standard Base64 alphabet - case Standard - /// The URL and Filename Safe Base64 alphabet - case URLAndFilenameSafe - } -} - -private extension Base64 { - - /// Get the encoding table for the alphabet. - static func table(for alphabet: Alphabet) -> [UInt8] { - switch alphabet { - case .Standard: - return StandardAlphabet - case .URLAndFilenameSafe: - return URLAndFilenameSafeAlphabet + /** + This method encodes data in Base64. + + - parameter bytes: The bytes you want to encode + - parameter options: Options for formatting the result + - returns: The Base64-encoding for those bytes. + */ + private static func base64EncodeBytes(_ bytes: [UInt8], options: Base64EncodingOptions = []) -> [UInt8] { + var result = [UInt8]() + result.reserveCapacity((bytes.count/3)*4) + + let lineOptions : (lineLength : Int, separator : [UInt8])? = { + let lineLength: Int + + if options.contains(.encoding64CharacterLineLength) { lineLength = 64 } + else if options.contains(.encoding76CharacterLineLength) { lineLength = 76 } + else { + return nil + } + + var separator = [UInt8]() + if options.contains(.encodingEndLineWithCarriageReturn) { separator.append(13) } + if options.contains(.encodingEndLineWithLineFeed) { separator.append(10) } + + //if the kind of line ending to insert is not specified, the default line ending is Carriage Return + Line Feed. + if separator.count == 0 {separator = [13,10]} + + return (lineLength,separator) + }() + + var currentLineCount = 0 + let appendByteToResult : (UInt8) -> () = { + result.append($0) + currentLineCount += 1 + if let options = lineOptions where currentLineCount == options.lineLength { + result.append(contentsOf: options.separator) + currentLineCount = 0 + } + } + + var currentByte : UInt8 = 0 + + for (index,value) in bytes.enumerated() { + switch index%3 { + case 0: + currentByte = (value >> 2) + appendByteToResult(Data.base64EncodeByte(currentByte)) + currentByte = ((value << 6) >> 2) + case 1: + currentByte |= (value >> 4) + appendByteToResult(Data.base64EncodeByte(currentByte)) + currentByte = ((value << 4) >> 2) + case 2: + currentByte |= (value >> 6) + appendByteToResult(Data.base64EncodeByte(currentByte)) + currentByte = ((value << 2) >> 2) + appendByteToResult(Data.base64EncodeByte(currentByte)) + default: + fatalError() + } + } + //add padding + switch bytes.count%3 { + case 0: break //no padding needed + case 1: + appendByteToResult(Data.base64EncodeByte(currentByte)) + appendByteToResult(self.base64Padding) + appendByteToResult(self.base64Padding) + case 2: + appendByteToResult(Data.base64EncodeByte(currentByte)) + appendByteToResult(self.base64Padding) + default: + fatalError() + } + return result } } -} - -// The tables in this file were generated using generate_alphabet_table in the tools directory. -// Note the tables contain 65 characters: 64 to do the translation and 1 more for the padding -// character used in each alphabet. - -/// Standard Base64 encoding table. -private let StandardAlphabet : [UInt8] = [ - 65, // 0=A - 66, // 1=B - 67, // 2=C - 68, // 3=D - 69, // 4=E - 70, // 5=F - 71, // 6=G - 72, // 7=H - 73, // 8=I - 74, // 9=J - 75, // 10=K - 76, // 11=L - 77, // 12=M - 78, // 13=N - 79, // 14=O - 80, // 15=P - 81, // 16=Q - 82, // 17=R - 83, // 18=S - 84, // 19=T - 85, // 20=U - 86, // 21=V - 87, // 22=W - 88, // 23=X - 89, // 24=Y - 90, // 25=Z - 97, // 26=a - 98, // 27=b - 99, // 28=c - 100, // 29=d - 101, // 30=e - 102, // 31=f - 103, // 32=g - 104, // 33=h - 105, // 34=i - 106, // 35=j - 107, // 36=k - 108, // 37=l - 109, // 38=m - 110, // 39=n - 111, // 40=o - 112, // 41=p - 113, // 42=q - 114, // 43=r - 115, // 44=s - 116, // 45=t - 117, // 46=u - 118, // 47=v - 119, // 48=w - 120, // 49=x - 121, // 50=y - 122, // 51=z - 48, // 52=0 - 49, // 53=1 - 50, // 54=2 - 51, // 55=3 - 52, // 56=4 - 53, // 57=5 - 54, // 58=6 - 55, // 59=7 - 56, // 60=8 - 57, // 61=9 - 43, // 62=+ - 47, // 63=/ - // PADDING FOLLOWS, not used during lookups - 61, // 64== -] - -/// URL and Filename Safe Base64 encoding table. -private let URLAndFilenameSafeAlphabet : [UInt8] = [ - 65, // 0=A - 66, // 1=B - 67, // 2=C - 68, // 3=D - 69, // 4=E - 70, // 5=F - 71, // 6=G - 72, // 7=H - 73, // 8=I - 74, // 9=J - 75, // 10=K - 76, // 11=L - 77, // 12=M - 78, // 13=N - 79, // 14=O - 80, // 15=P - 81, // 16=Q - 82, // 17=R - 83, // 18=S - 84, // 19=T - 85, // 20=U - 86, // 21=V - 87, // 22=W - 88, // 23=X - 89, // 24=Y - 90, // 25=Z - 97, // 26=a - 98, // 27=b - 99, // 28=c - 100, // 29=d - 101, // 30=e - 102, // 31=f - 103, // 32=g - 104, // 33=h - 105, // 34=i - 106, // 35=j - 107, // 36=k - 108, // 37=l - 109, // 38=m - 110, // 39=n - 111, // 40=o - 112, // 41=p - 113, // 42=q - 114, // 43=r - 115, // 44=s - 116, // 45=t - 117, // 46=u - 118, // 47=v - 119, // 48=w - 120, // 49=x - 121, // 50=y - 122, // 51=z - 48, // 52=0 - 49, // 53=1 - 50, // 54=2 - 51, // 55=3 - 52, // 56=4 - 53, // 57=5 - 54, // 58=6 - 55, // 59=7 - 56, // 60=8 - 57, // 61=9 - 45, // 62=- - 95, // 63=_ - // PADDING FOLLOWS, not used during lookups - 61, // 64== -] + +#endif From 25e73f444a627e9ebbac124fb440001cdeff504e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:17:58 -0500 Subject: [PATCH 62/68] Updated Lock to match Foundation API --- Sources/SwiftFoundation/Lock.swift | 289 ++++++++++++++++++----------- 1 file changed, 180 insertions(+), 109 deletions(-) diff --git a/Sources/SwiftFoundation/Lock.swift b/Sources/SwiftFoundation/Lock.swift index 36b44f5..2e758d8 100644 --- a/Sources/SwiftFoundation/Lock.swift +++ b/Sources/SwiftFoundation/Lock.swift @@ -12,147 +12,218 @@ import Glibc #endif -/// Protocol defining lock and unlock operations. public protocol Locking { - /// Block until acquiring lock. func lock() - - /// Relinquish lock. func unlock() } -/// Used to coordinate the operation of multiple threads of execution within the same application. -/// A lock object can be used to mediate access to an application’s global data or to protect a critical section of code, -/// allowing it to run atomically. -/// -/// - Note: `Lock` uses POSIX threads to implement its locking behavior. -/// When sending an unlock message to a `Lock`, you must be sure that message is sent from the same thread -/// that sent the initial lock message. Unlocking a lock from a different thread can result in undefined behavior. -/// You should not use this class to implement a recursive lock. -/// Calling the lock method twice on the same thread will lock up your thread permanently. -/// Unlocking a lock that is not locked is considered a programmer error and should be fixed in your code. -/// The `Lock` reports such errors by printing an error message to the console when they occur. -public final class Lock: Locking { - - // MARK: - Properties - - /// You can use a name string to identify a lock within your code. +public class Lock: Locking { + + private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + + public init() { + pthread_mutex_init(mutex, nil) + } + + deinit { + pthread_mutex_destroy(mutex) + mutex.deinitialize() + mutex.deallocateCapacity(1) + } + + public func lock() { + pthread_mutex_lock(mutex) + } + + public func unlock() { + pthread_mutex_unlock(mutex) + } + + public func tryLock() -> Bool { + return pthread_mutex_trylock(mutex) == 0 + } + public var name: String? +} + +extension Lock { + internal func synchronized(_ closure: @noescape () -> T) -> T { + self.lock() + defer { self.unlock() } + return closure() + } +} + +public class NSConditionLock : NSObject, Locking { + internal var _cond = Condition() + internal var _value: Int + internal var _thread: pthread_t? + + public convenience override init() { + self.init(condition: 0) + } - private var internalMutex = pthread_mutex_t() + public init(condition: Int) { + _value = condition + } - // MARK: - Intialization + public func lock() { + let _ = lockBeforeDate(Date.distantFuture) + } - deinit { pthread_mutex_destroy(&internalMutex) } + public func unlock() { + _cond.lock() + _thread = nil + _cond.broadcast() + _cond.unlock() + } - public init() { - - pthread_mutex_init(&internalMutex, nil) + public var condition: Int { + return _value } - // MARK: - Methods + public func lockWhenCondition(_ condition: Int) { + let _ = lockWhenCondition(condition, beforeDate: Date.distantFuture) + } - /// Attempts to acquire a lock before a given time. - /// - /// - Discussion: The thread is blocked until the receiver acquires the lock or limit is reached. - public func lock(before limit: Date) { - - assert(Date() < limit, "\(limit) must be after the current date.") - - guard tryLock() else { - - repeat { sched_yield() } - - while limit - Date() > 0 - - return + public func tryLock() -> Bool { + return lockBeforeDate(Date.distantPast) + } + + public func tryLockWhenCondition(_ condition: Int) -> Bool { + return lockWhenCondition(condition, beforeDate: Date.distantPast) + } + + public func unlockWithCondition(_ condition: Int) { + _cond.lock() + _thread = nil + _value = condition + _cond.broadcast() + _cond.unlock() + } + + public func lockBeforeDate(_ limit: Date) -> Bool { + _cond.lock() + while _thread == nil { + if !_cond.waitUntilDate(limit) { + _cond.unlock() + return false + } } + _thread = pthread_self() + _cond.unlock() + return true + } + + public func lockWhenCondition(_ condition: Int, beforeDate limit: Date) -> Bool { + _cond.lock() + while _thread != nil || _value != condition { + if !_cond.waitUntilDate(limit) { + _cond.unlock() + return false + } + } + _thread = pthread_self() + _cond.unlock() + return true + } + + public var name: String? +} + +public class RecursiveLock: NSObject, Locking { + internal var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + + public override init() { + super.init() + var attrib = pthread_mutexattr_t() + withUnsafeMutablePointer(&attrib) { attrs in + pthread_mutexattr_settype(attrs, Int32(PTHREAD_MUTEX_RECURSIVE)) + pthread_mutex_init(mutex, attrs) + } + } + + deinit { + pthread_mutex_destroy(mutex) + mutex.deinitialize() + mutex.deallocateCapacity(1) } - @inline(__always) public func lock() { - - let errorCode = pthread_mutex_lock(&internalMutex) - - assert(errorCode == 0, "Could not lock mutex. \(POSIXError(rawValue: errorCode)!)") + pthread_mutex_lock(mutex) } - @inline(__always) public func unlock() { - - let errorCode = pthread_mutex_unlock(&internalMutex) - - assert(errorCode == 0, "Could not unlock mutex. \(POSIXError(rawValue: errorCode)!)") + pthread_mutex_unlock(mutex) } - /// Try to acquire lock and return immediately. - @inline(__always) public func tryLock() -> Bool { - - return pthread_mutex_trylock(&internalMutex) == 0 + return pthread_mutex_trylock(mutex) == 0 } + + public var name: String? } -// MARK: - Private Types - -private extension Lock { +public class Condition: NSObject, Locking { + internal var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + internal var cond = UnsafeMutablePointer(allocatingCapacity: 1) - /// POSIX Mutex (`Lock`) Attribute - private final class Attribute { - - // MARK: - Singletons - - private static let Normal = Attribute(type: .normal) - - private static let ErrorCheck = Attribute(type: .errorCheck) - - private static let Recursive = Attribute(type: .recursive) - - // MARK: - Properties - - private var internalAttribute = pthread_mutexattr_t() - - // MARK: - Initialization - - deinit { pthread_mutexattr_destroy(&internalAttribute) } - - private init() { - - pthread_mutexattr_init(&internalAttribute) + public override init() { + pthread_mutex_init(mutex, nil) + pthread_cond_init(cond, nil) + } + + deinit { + pthread_mutex_destroy(mutex) + pthread_cond_destroy(cond) + mutex.deinitialize() + cond.deinitialize() + mutex.deallocateCapacity(1) + cond.deallocateCapacity(1) + } + + public func lock() { + pthread_mutex_lock(mutex) + } + + public func unlock() { + pthread_mutex_unlock(mutex) + } + + public func wait() { + pthread_cond_wait(cond, mutex) + } + + public func waitUntilDate(_ limit: Date) -> Bool { + let lim = limit.timeIntervalSinceReferenceDate + let ti = lim - CFAbsoluteTimeGetCurrent() + if ti < 0.0 { + return false } - - private convenience init(type: AttributeType) { - - self.init() - - self.type = type + var ts = timespec() + ts.tv_sec = Int(floor(ti)) + ts.tv_nsec = Int((ti - Double(ts.tv_sec)) * 1000000000.0) + var tv = timeval() + withUnsafeMutablePointer(&tv) { t in + gettimeofday(t, nil) + ts.tv_sec += t.pointee.tv_sec + ts.tv_nsec += Int((t.pointee.tv_usec * 1000000) / 1000000000) } - - // MARK: - Methods - - private var type: AttributeType { - - get { - - var typeRawValue: CInt = 0 - - pthread_mutexattr_gettype(&internalAttribute, &typeRawValue) - - return AttributeType(rawValue: typeRawValue)! - } - - set { pthread_mutexattr_settype(&internalAttribute, newValue.rawValue) } + let retVal: Int32 = withUnsafePointer(&ts) { t in + return pthread_cond_timedwait(cond, mutex, t) } + + return retVal == 0 } - /// POSIX Mutex (`Lock`) Attribute Type - private enum AttributeType: CInt { - - case normal = 0 - case errorCheck = 1 - case recursive = 2 - - private init() { self = normal } + public func signal() { + pthread_cond_signal(cond) + } + + public func broadcast() { + pthread_cond_broadcast(cond) } + + public var name: String? } From f7f830cd665138470181011948799f5c1a29528c Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:21:15 -0500 Subject: [PATCH 63/68] Updated Lock API --- Sources/SwiftFoundation/Lock.swift | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/SwiftFoundation/Lock.swift b/Sources/SwiftFoundation/Lock.swift index 2e758d8..a6d50c1 100644 --- a/Sources/SwiftFoundation/Lock.swift +++ b/Sources/SwiftFoundation/Lock.swift @@ -18,7 +18,7 @@ public protocol Locking { func unlock() } -public class Lock: Locking { +public final class Lock: Locking { private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) @@ -48,17 +48,17 @@ public class Lock: Locking { } extension Lock { - internal func synchronized(_ closure: @noescape () -> T) -> T { + private func synchronized(_ closure: @noescape () -> T) -> T { self.lock() defer { self.unlock() } return closure() } } -public class NSConditionLock : NSObject, Locking { - internal var _cond = Condition() - internal var _value: Int - internal var _thread: pthread_t? +public final class ConditionLock : NSObject, Locking { + private var _cond = Condition() + private var _value: Int + private var _thread: pthread_t? public convenience override init() { self.init(condition: 0) @@ -132,11 +132,11 @@ public class NSConditionLock : NSObject, Locking { public var name: String? } -public class RecursiveLock: NSObject, Locking { - internal var mutex = UnsafeMutablePointer(allocatingCapacity: 1) +public final class RecursiveLock: Locking { + private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) - public override init() { - super.init() + public init() { + var attrib = pthread_mutexattr_t() withUnsafeMutablePointer(&attrib) { attrs in pthread_mutexattr_settype(attrs, Int32(PTHREAD_MUTEX_RECURSIVE)) @@ -165,11 +165,11 @@ public class RecursiveLock: NSObject, Locking { public var name: String? } -public class Condition: NSObject, Locking { - internal var mutex = UnsafeMutablePointer(allocatingCapacity: 1) - internal var cond = UnsafeMutablePointer(allocatingCapacity: 1) +public final class Condition: Locking { + private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + private var cond = UnsafeMutablePointer(allocatingCapacity: 1) - public override init() { + public init() { pthread_mutex_init(mutex, nil) pthread_cond_init(cond, nil) } From 08004718a65106ed129a78aa3dc3ad0857ecdb02 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:26:50 -0500 Subject: [PATCH 64/68] Version bump --- Xcode/SwiftFoundation/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xcode/SwiftFoundation/Info.plist b/Xcode/SwiftFoundation/Info.plist index 6c36814..83f51e7 100644 --- a/Xcode/SwiftFoundation/Info.plist +++ b/Xcode/SwiftFoundation/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.0 + 2.0.0 CFBundleSignature ???? CFBundleVersion From 6b65d2f2d33d5ae9e473eec05f091f90a9a8f38b Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:29:22 -0500 Subject: [PATCH 65/68] Updated Lock for Linux --- Sources/SwiftFoundation/Lock.swift | 390 ++++++++++++++--------------- 1 file changed, 195 insertions(+), 195 deletions(-) diff --git a/Sources/SwiftFoundation/Lock.swift b/Sources/SwiftFoundation/Lock.swift index a6d50c1..9c553dd 100644 --- a/Sources/SwiftFoundation/Lock.swift +++ b/Sources/SwiftFoundation/Lock.swift @@ -12,218 +12,218 @@ import Glibc #endif -public protocol Locking { +#if os(Linux) || XcodeLinux - func lock() - func unlock() -} - -public final class Lock: Locking { - - private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) - - public init() { - pthread_mutex_init(mutex, nil) - } - - deinit { - pthread_mutex_destroy(mutex) - mutex.deinitialize() - mutex.deallocateCapacity(1) - } - - public func lock() { - pthread_mutex_lock(mutex) - } - - public func unlock() { - pthread_mutex_unlock(mutex) - } - - public func tryLock() -> Bool { - return pthread_mutex_trylock(mutex) == 0 - } - - public var name: String? -} - -extension Lock { - private func synchronized(_ closure: @noescape () -> T) -> T { - self.lock() - defer { self.unlock() } - return closure() - } -} - -public final class ConditionLock : NSObject, Locking { - private var _cond = Condition() - private var _value: Int - private var _thread: pthread_t? - - public convenience override init() { - self.init(condition: 0) - } - - public init(condition: Int) { - _value = condition - } - - public func lock() { - let _ = lockBeforeDate(Date.distantFuture) - } - - public func unlock() { - _cond.lock() - _thread = nil - _cond.broadcast() - _cond.unlock() - } - - public var condition: Int { - return _value - } - - public func lockWhenCondition(_ condition: Int) { - let _ = lockWhenCondition(condition, beforeDate: Date.distantFuture) + public protocol Locking { + + func lock() + func unlock() } - public func tryLock() -> Bool { - return lockBeforeDate(Date.distantPast) + public final class Lock: Locking { + + private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + + public init() { + pthread_mutex_init(mutex, nil) + } + + deinit { + pthread_mutex_destroy(mutex) + mutex.deinitialize() + mutex.deallocateCapacity(1) + } + + public func lock() { + pthread_mutex_lock(mutex) + } + + public func unlock() { + pthread_mutex_unlock(mutex) + } + + public func tryLock() -> Bool { + return pthread_mutex_trylock(mutex) == 0 + } + + public var name: String? } - public func tryLockWhenCondition(_ condition: Int) -> Bool { - return lockWhenCondition(condition, beforeDate: Date.distantPast) + extension Lock { + private func synchronized(_ closure: @noescape () -> T) -> T { + self.lock() + defer { self.unlock() } + return closure() + } } - public func unlockWithCondition(_ condition: Int) { - _cond.lock() - _thread = nil - _value = condition - _cond.broadcast() - _cond.unlock() + public final class ConditionLock: Locking { + private var _cond = Condition() + private var _value: Int + private var _thread: pthread_t? + + public init(condition: Int = 0) { + _value = condition + } + + public func lock() { + let _ = lockBeforeDate(Date.distantFuture) + } + + public func unlock() { + _cond.lock() + _thread = nil + _cond.broadcast() + _cond.unlock() + } + + public var condition: Int { + return _value + } + + public func lockWhenCondition(_ condition: Int) { + let _ = lockWhenCondition(condition, beforeDate: Date.distantFuture) + } + + public func tryLock() -> Bool { + return lockBeforeDate(Date.distantPast) + } + + public func tryLockWhenCondition(_ condition: Int) -> Bool { + return lockWhenCondition(condition, beforeDate: Date.distantPast) + } + + public func unlockWithCondition(_ condition: Int) { + _cond.lock() + _thread = nil + _value = condition + _cond.broadcast() + _cond.unlock() + } + + public func lockBeforeDate(_ limit: Date) -> Bool { + _cond.lock() + while _thread == nil { + if !_cond.waitUntilDate(limit) { + _cond.unlock() + return false + } + } + _thread = pthread_self() + _cond.unlock() + return true + } + + public func lockWhenCondition(_ condition: Int, beforeDate limit: Date) -> Bool { + _cond.lock() + while _thread != nil || _value != condition { + if !_cond.waitUntilDate(limit) { + _cond.unlock() + return false + } + } + _thread = pthread_self() + _cond.unlock() + return true + } + + public var name: String? } - public func lockBeforeDate(_ limit: Date) -> Bool { - _cond.lock() - while _thread == nil { - if !_cond.waitUntilDate(limit) { - _cond.unlock() - return false + public final class RecursiveLock: Locking { + private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + + public init() { + + var attrib = pthread_mutexattr_t() + withUnsafeMutablePointer(&attrib) { attrs in + pthread_mutexattr_settype(attrs, Int32(PTHREAD_MUTEX_RECURSIVE)) + pthread_mutex_init(mutex, attrs) } } - _thread = pthread_self() - _cond.unlock() - return true + + deinit { + pthread_mutex_destroy(mutex) + mutex.deinitialize() + mutex.deallocateCapacity(1) + } + + public func lock() { + pthread_mutex_lock(mutex) + } + + public func unlock() { + pthread_mutex_unlock(mutex) + } + + public func tryLock() -> Bool { + return pthread_mutex_trylock(mutex) == 0 + } + + public var name: String? } - public func lockWhenCondition(_ condition: Int, beforeDate limit: Date) -> Bool { - _cond.lock() - while _thread != nil || _value != condition { - if !_cond.waitUntilDate(limit) { - _cond.unlock() + public final class Condition: Locking { + private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) + private var cond = UnsafeMutablePointer(allocatingCapacity: 1) + + public init() { + pthread_mutex_init(mutex, nil) + pthread_cond_init(cond, nil) + } + + deinit { + pthread_mutex_destroy(mutex) + pthread_cond_destroy(cond) + mutex.deinitialize() + cond.deinitialize() + mutex.deallocateCapacity(1) + cond.deallocateCapacity(1) + } + + public func lock() { + pthread_mutex_lock(mutex) + } + + public func unlock() { + pthread_mutex_unlock(mutex) + } + + public func wait() { + pthread_cond_wait(cond, mutex) + } + + public func waitUntilDate(_ limit: Date) -> Bool { + let lim = limit.timeIntervalSinceReferenceDate + let ti = lim - Date.timeIntervalSinceReferenceDate + if ti < 0.0 { return false } + var ts = timespec() + ts.tv_sec = Int(floor(ti)) + ts.tv_nsec = Int((ti - Double(ts.tv_sec)) * 1000000000.0) + var tv = timeval() + withUnsafeMutablePointer(&tv) { t in + gettimeofday(t, nil) + ts.tv_sec += t.pointee.tv_sec + ts.tv_nsec += Int((t.pointee.tv_usec * 1000000) / 1000000000) + } + let retVal: Int32 = withUnsafePointer(&ts) { t in + return pthread_cond_timedwait(cond, mutex, t) + } + + return retVal == 0 } - _thread = pthread_self() - _cond.unlock() - return true - } - - public var name: String? -} - -public final class RecursiveLock: Locking { - private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) - - public init() { - var attrib = pthread_mutexattr_t() - withUnsafeMutablePointer(&attrib) { attrs in - pthread_mutexattr_settype(attrs, Int32(PTHREAD_MUTEX_RECURSIVE)) - pthread_mutex_init(mutex, attrs) + public func signal() { + pthread_cond_signal(cond) } + + public func broadcast() { + pthread_cond_broadcast(cond) + } + + public var name: String? } - deinit { - pthread_mutex_destroy(mutex) - mutex.deinitialize() - mutex.deallocateCapacity(1) - } - - public func lock() { - pthread_mutex_lock(mutex) - } - - public func unlock() { - pthread_mutex_unlock(mutex) - } - - public func tryLock() -> Bool { - return pthread_mutex_trylock(mutex) == 0 - } - - public var name: String? -} - -public final class Condition: Locking { - private var mutex = UnsafeMutablePointer(allocatingCapacity: 1) - private var cond = UnsafeMutablePointer(allocatingCapacity: 1) - - public init() { - pthread_mutex_init(mutex, nil) - pthread_cond_init(cond, nil) - } - - deinit { - pthread_mutex_destroy(mutex) - pthread_cond_destroy(cond) - mutex.deinitialize() - cond.deinitialize() - mutex.deallocateCapacity(1) - cond.deallocateCapacity(1) - } - - public func lock() { - pthread_mutex_lock(mutex) - } - - public func unlock() { - pthread_mutex_unlock(mutex) - } - - public func wait() { - pthread_cond_wait(cond, mutex) - } - - public func waitUntilDate(_ limit: Date) -> Bool { - let lim = limit.timeIntervalSinceReferenceDate - let ti = lim - CFAbsoluteTimeGetCurrent() - if ti < 0.0 { - return false - } - var ts = timespec() - ts.tv_sec = Int(floor(ti)) - ts.tv_nsec = Int((ti - Double(ts.tv_sec)) * 1000000000.0) - var tv = timeval() - withUnsafeMutablePointer(&tv) { t in - gettimeofday(t, nil) - ts.tv_sec += t.pointee.tv_sec - ts.tv_nsec += Int((t.pointee.tv_usec * 1000000) / 1000000000) - } - let retVal: Int32 = withUnsafePointer(&ts) { t in - return pthread_cond_timedwait(cond, mutex, t) - } - - return retVal == 0 - } - - public func signal() { - pthread_cond_signal(cond) - } - - public func broadcast() { - pthread_cond_broadcast(cond) - } - - public var name: String? -} +#endif From 9e0f0b0ab3c476a717aa7093017be06785dabdaa Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:47:30 -0500 Subject: [PATCH 66/68] Fixed #33 --- Sources/SwiftFoundation/Data.swift | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Sources/SwiftFoundation/Data.swift b/Sources/SwiftFoundation/Data.swift index 94d2cac..16a3cb6 100644 --- a/Sources/SwiftFoundation/Data.swift +++ b/Sources/SwiftFoundation/Data.swift @@ -24,7 +24,16 @@ // MARK: - Properties - public var bytes: [Byte] + private var _bytes: ContiguousArray + + public var bytes: [Byte] { + + @inline(__always) + get { return Array(_bytes) } + + @inline(__always) + set { _bytes = ContiguousArray(newValue) } + } // MARK: - Initialization @@ -34,7 +43,7 @@ @inline(__always) public init(bytes: [Byte] = []) { - self.bytes = bytes + _bytes = ContiguousArray(bytes) } /// Initialize a `Data` with the contents of an Array. @@ -43,7 +52,7 @@ @inline(__always) public init(bytes: ArraySlice) { - self.bytes = Array(bytes) + _bytes = ContiguousArray(bytes) } /// Initialize a `Data` with the specified size. @@ -53,7 +62,7 @@ public init?(count: Int) { // Never fails on Linux - self.bytes = Array(repeating: 0, count: count) + _bytes = ContiguousArray.init(repeating: 0, count: count) } /// Initialize a `Data` with copied memory content. @@ -63,7 +72,7 @@ @inline(__always) public init(bytes pointer: UnsafePointer, count: Int) { - self.bytes = [UInt8](repeating: 0, count: count) + _bytes = ContiguousArray(repeating: 0, count: count) memcpy(&bytes, pointer, count) } @@ -104,7 +113,7 @@ @inline(__always) public mutating func append(_ other: Data) { - self.bytes += other.bytes + _bytes += other._bytes } /// Return a new copy of the data in a specified range. @@ -113,7 +122,7 @@ @inline(__always) public func subdata(in range: Range) -> Data { - return Data(bytes: bytes[range]) + return Data(bytes: _bytes[range]) } // MARK: - Index and Subscript @@ -123,10 +132,10 @@ public subscript(index: Index) -> Byte { @inline(__always) - get { return bytes[index] } + get { return _bytes[index] } @inline(__always) - set { bytes[index] = newValue } + set { _bytes[index] = newValue } } public subscript(bounds: Range) -> MutableRandomAccessSlice { @@ -135,7 +144,7 @@ get { return MutableRandomAccessSlice(base: self, bounds: bounds) } @inline(__always) - set { bytes.replaceSubrange(bounds, with: newValue) } + set { _bytes.replaceSubrange(bounds, with: newValue) } } /// The start `Index` in the data. @@ -172,7 +181,7 @@ public func == (lhs: Data, rhs: Data) -> Bool { - guard lhs.bytes.count == rhs.bytes.count else { return false } + guard lhs.count == rhs.count else { return false } var bytes1 = lhs.bytes @@ -185,7 +194,11 @@ public func + (lhs: Data, rhs: Data) -> Data { - return Data(bytes: lhs.bytes + rhs.bytes) + var result = Data() + + result._bytes = lhs._bytes + rhs._bytes + + return result } #endif From 405f355fd87930d4b7aba989e5cd74b6b3369c28 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 03:48:44 -0500 Subject: [PATCH 67/68] Updated String extensions --- Sources/SwiftFoundation/String.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftFoundation/String.swift b/Sources/SwiftFoundation/String.swift index e9624a2..0207893 100644 --- a/Sources/SwiftFoundation/String.swift +++ b/Sources/SwiftFoundation/String.swift @@ -14,12 +14,12 @@ public extension String { var string = "" - var generator = data.bytes.makeIterator() + var generator = data.makeIterator() var encoding = UTF8() - - repeat { + repeat { + switch encoding.decode(&generator) { case let .scalarValue(scalar): @@ -44,7 +44,7 @@ public extension String { func toUTF8Data() -> Data { - return Data(bytes: [] + utf8) + return Data(bytes: Array(utf8)) } func substring(range: Range) -> String? { From 7d07d62912c1a23cb5e9bf9ceaa4be101804e4a2 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 3 Jul 2016 04:01:20 -0500 Subject: [PATCH 68/68] Fixed Data Also made Unit tests for OS X compile in debug configuration --- Sources/SwiftFoundation/Data.swift | 5 ++ .../SwiftFoundation/JSONSerialization.swift | 43 +++++++++++++++ .../SwiftFoundation/JSONWritingOption.swift | 55 ------------------- Sources/UnitTests/DataTests.swift | 2 +- Sources/UnitTests/POSIXTimeTests.swift | 4 +- Sources/UnitTests/UUIDTests.swift | 2 +- .../SwiftFoundation.xcodeproj/project.pbxproj | 8 --- .../xcschemes/SwiftFoundation OS X.xcscheme | 2 +- 8 files changed, 53 insertions(+), 68 deletions(-) delete mode 100644 Sources/SwiftFoundation/JSONWritingOption.swift diff --git a/Sources/SwiftFoundation/Data.swift b/Sources/SwiftFoundation/Data.swift index 16a3cb6..5cc931c 100644 --- a/Sources/SwiftFoundation/Data.swift +++ b/Sources/SwiftFoundation/Data.swift @@ -147,6 +147,11 @@ set { _bytes.replaceSubrange(bounds, with: newValue) } } + public var count: Int { + + return _bytes.count + } + /// The start `Index` in the data. public var startIndex: Index { diff --git a/Sources/SwiftFoundation/JSONSerialization.swift b/Sources/SwiftFoundation/JSONSerialization.swift index 44681c3..24e86c1 100755 --- a/Sources/SwiftFoundation/JSONSerialization.swift +++ b/Sources/SwiftFoundation/JSONSerialization.swift @@ -93,3 +93,46 @@ private extension JSON.Value { } } +// MARK: - Supporting Types + +public extension JSON { + + /// Options for serializing JSON. + /// + /// - Note: Uses the [JSON-C](https://github.com/json-c/json-c) library. + public enum WritingOption: BitMaskOption { + + /// Causes the output to have minimal whitespace inserted to make things slightly more readable. + case Spaced + + /// Causes the output to be formatted. See the [Two Space Tab](http://jsonformatter.curiousconcept.com/) option + /// for an example of the format. + case Pretty + + /// Drop trailing zero for float values + case NoZero + + public init?(rawValue: Int32) { + + switch rawValue { + + case JSON_C_TO_STRING_SPACED: self = .Spaced + case JSON_C_TO_STRING_PRETTY: self = .Pretty + case JSON_C_TO_STRING_NOZERO: self = .NoZero + + default: return nil + } + } + + public var rawValue: Int32 { + + switch self { + + case Spaced: return JSON_C_TO_STRING_SPACED + case Pretty: return JSON_C_TO_STRING_PRETTY + case NoZero: return JSON_C_TO_STRING_NOZERO + } + } + } +} + diff --git a/Sources/SwiftFoundation/JSONWritingOption.swift b/Sources/SwiftFoundation/JSONWritingOption.swift deleted file mode 100644 index 5e65941..0000000 --- a/Sources/SwiftFoundation/JSONWritingOption.swift +++ /dev/null @@ -1,55 +0,0 @@ -// -// JSONWritingOption.swift -// JSONC -// -// Created by Alsey Coleman Miller on 12/19/15. -// Copyright © 2015 PureSwift. All rights reserved. -// - -#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) - import JSON -#elseif os(Linux) - import CJSONC -#endif - -public extension JSON { - - /// Options for serializing JSON. - /// - /// - Note: Uses the [JSON-C](https://github.com/json-c/json-c) library. - public enum WritingOption: BitMaskOption { - - /// Causes the output to have minimal whitespace inserted to make things slightly more readable. - case Spaced - - /// Causes the output to be formatted. See the [Two Space Tab](http://jsonformatter.curiousconcept.com/) option - /// for an example of the format. - case Pretty - - /// Drop trailing zero for float values - case NoZero - - public init?(rawValue: Int32) { - - switch rawValue { - - case JSON_C_TO_STRING_SPACED: self = .Spaced - case JSON_C_TO_STRING_PRETTY: self = .Pretty - case JSON_C_TO_STRING_NOZERO: self = .NoZero - - default: return nil - } - } - - public var rawValue: Int32 { - - switch self { - - case Spaced: return JSON_C_TO_STRING_SPACED - case Pretty: return JSON_C_TO_STRING_PRETTY - case NoZero: return JSON_C_TO_STRING_NOZERO - } - } - } -} - diff --git a/Sources/UnitTests/DataTests.swift b/Sources/UnitTests/DataTests.swift index 76be88b..eb87be3 100644 --- a/Sources/UnitTests/DataTests.swift +++ b/Sources/UnitTests/DataTests.swift @@ -31,7 +31,7 @@ final class DataTests: XCTestCase { memcpy(dataPointer, testData.bytes, testData.count) - let data = Data(bytes: dataPointer, count: testData.count) + let data = SwiftFoundation.Data(bytes: dataPointer, count: testData.count) XCTAssert(data == testData, "\(data) == \(testData)") } diff --git a/Sources/UnitTests/POSIXTimeTests.swift b/Sources/UnitTests/POSIXTimeTests.swift index 2455a0f..1856ce2 100644 --- a/Sources/UnitTests/POSIXTimeTests.swift +++ b/Sources/UnitTests/POSIXTimeTests.swift @@ -38,7 +38,7 @@ final class POSIXTimeTests: XCTestCase { func testTimeVal() { - let date = Date() + let date = SwiftFoundation.Date() let time = timeval(timeInterval: date.timeIntervalSince1970) @@ -47,7 +47,7 @@ final class POSIXTimeTests: XCTestCase { func testTimeSpec() { - let date = Date() + let date = SwiftFoundation.Date() let time = timespec(timeInterval: date.timeIntervalSince1970) diff --git a/Sources/UnitTests/UUIDTests.swift b/Sources/UnitTests/UUIDTests.swift index 5663687..d11e778 100644 --- a/Sources/UnitTests/UUIDTests.swift +++ b/Sources/UnitTests/UUIDTests.swift @@ -49,7 +49,7 @@ final class UUIDTests: XCTestCase { func testBytes() { - let expectedData = Data(bytes: [91, 254, 177, 148, 104, 196, 72, 232, 143, 67, 60, 88, 99, 100, 203, 111] as [Byte]) + let expectedData = SwiftFoundation.Data(bytes: [91, 254, 177, 148, 104, 196, 72, 232, 143, 67, 60, 88, 99, 100, 203, 111] as [Byte]) let stringValue = "5BFEB194-68C4-48E8-8F43-3C586364CB6F" diff --git a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj index b21b8a0..902ef19 100644 --- a/Xcode/SwiftFoundation.xcodeproj/project.pbxproj +++ b/Xcode/SwiftFoundation.xcodeproj/project.pbxproj @@ -135,9 +135,6 @@ 6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */; }; 6E957C2C1C43AA55003F3C51 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */; }; 6E957C2D1C43AA55003F3C51 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */; }; - 6E957C2E1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */; }; - 6E957C2F1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */; }; - 6E957C301C43AA55003F3C51 /* JSONWritingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */; }; 6E957C481C43B397003F3C51 /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E957C451C43B397003F3C51 /* JSON.framework */; }; 6E957C491C43B397003F3C51 /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E957C451C43B397003F3C51 /* JSON.framework */; }; 6E957C4A1C43B397003F3C51 /* JSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E957C451C43B397003F3C51 /* JSON.framework */; }; @@ -256,7 +253,6 @@ 6E8474CC1D24FCFE009CA7DB /* ComparisonResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparisonResult.swift; sourceTree = ""; }; 6E957C251C43A7C8003F3C51 /* JSONParse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParse.swift; sourceTree = ""; }; 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerialization.swift; sourceTree = ""; }; - 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONWritingOption.swift; sourceTree = ""; }; 6E957C451C43B397003F3C51 /* JSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSON.framework; sourceTree = ""; }; 6E957C471C43B397003F3C51 /* JSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSON.framework; sourceTree = ""; }; 6E957C561C442E3E003F3C51 /* JSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = ""; }; @@ -356,7 +352,6 @@ 6E2C2B351C20F6EB00B2C995 /* JSONExtensions.swift */, 6E957C251C43A7C8003F3C51 /* JSONParse.swift */, 6E957C291C43AA55003F3C51 /* JSONSerialization.swift */, - 6E957C2A1C43AA55003F3C51 /* JSONWritingOption.swift */, 6E82FD711CBA06C10049CD1B /* Lock.swift */, 6E2C2B361C20F6EB00B2C995 /* Null.swift */, 6E2C2B401C20F6EB00B2C995 /* RegularExpression.swift */, @@ -720,7 +715,6 @@ 6E957C2C1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6EE84DDA1CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2BCB1C20F76600B2C995 /* POSIXError.swift in Sources */, - 6E957C2F1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2BB81C20F76600B2C995 /* Date.swift in Sources */, 6E2C2BC71C20F76600B2C995 /* JSON.swift in Sources */, 6E2C2BAF1C20F76600B2C995 /* Base64.swift in Sources */, @@ -766,7 +760,6 @@ 6E957C2D1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6EE84DDB1CAF659800A40C4D /* Endianness.swift in Sources */, 6E2C2B971C20F76600B2C995 /* POSIXError.swift in Sources */, - 6E957C301C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2B841C20F76600B2C995 /* Date.swift in Sources */, 6E2C2B931C20F76600B2C995 /* JSON.swift in Sources */, 6E2C2B7B1C20F76600B2C995 /* Base64.swift in Sources */, @@ -830,7 +823,6 @@ 6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */, 6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */, 6E2C2BFF1C20F76700B2C995 /* POSIXError.swift in Sources */, - 6E957C2E1C43AA55003F3C51 /* JSONWritingOption.swift in Sources */, 6E2C2BEC1C20F76700B2C995 /* Date.swift in Sources */, 6E2C2BFB1C20F76700B2C995 /* JSON.swift in Sources */, 6EE84DD91CAF659800A40C4D /* Endianness.swift in Sources */, diff --git a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme index d417ba4..bddaedb 100644 --- a/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme +++ b/Xcode/SwiftFoundation.xcodeproj/xcshareddata/xcschemes/SwiftFoundation OS X.xcscheme @@ -23,7 +23,7 @@