From 0a927ddb5cf9d3acbaef396557fe5d88b678911b Mon Sep 17 00:00:00 2001 From: DavidHe Date: Tue, 10 Feb 2015 16:18:55 -0600 Subject: [PATCH 01/10] Add Bool extension --- ExSwift.xcodeproj/project.pbxproj | 16 ++++++++++++++++ ExSwift/Bool.swift | 18 ++++++++++++++++++ ExSwiftTests/ExSwiftBoolTests.swift | 23 +++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 ExSwift/Bool.swift create mode 100644 ExSwiftTests/ExSwiftBoolTests.swift diff --git a/ExSwift.xcodeproj/project.pbxproj b/ExSwift.xcodeproj/project.pbxproj index 3933399..8da322c 100755 --- a/ExSwift.xcodeproj/project.pbxproj +++ b/ExSwift.xcodeproj/project.pbxproj @@ -69,6 +69,12 @@ 3C0AB97B195C7FB30009BDA0 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB977195C7FAF0009BDA0 /* Sequence.swift */; }; 3C0AB97D195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */; }; 3C0AB97E195C7FC20009BDA0 /* ExSwiftSequenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */; }; + 6CB1F15F1A8AB867002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; }; + 6CB1F1611A8AB8D3002EA767 /* ExSwiftBoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F1601A8AB8D3002EA767 /* ExSwiftBoolTests.swift */; }; + 6CB1F1621A8AB979002EA767 /* ExSwiftBoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F1601A8AB8D3002EA767 /* ExSwiftBoolTests.swift */; }; + 6CB1F1631A8ABA1A002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; }; + 6CB1F1641A8ABA1A002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; }; + 6CB1F1661A8ABA1C002EA767 /* Bool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CB1F15E1A8AB867002EA767 /* Bool.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -99,6 +105,8 @@ 2EC02FBD194ED0D500619CB5 /* ExSwift-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ExSwift-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 3C0AB977195C7FAF0009BDA0 /* Sequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = ""; }; 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftSequenceTests.swift; sourceTree = ""; }; + 6CB1F15E1A8AB867002EA767 /* Bool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bool.swift; sourceTree = ""; }; + 6CB1F1601A8AB8D3002EA767 /* ExSwiftBoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftBoolTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -166,6 +174,7 @@ 1E11AFB01943225B006BCE48 /* Range.swift */, 1E11AFB11943225B006BCE48 /* String.swift */, 1EC241FB1946E91B0047109A /* NSArray.swift */, + 6CB1F15E1A8AB867002EA767 /* Bool.swift */, 1E11AF891943222D006BCE48 /* ExSwift.h */, 1E11AF871943222D006BCE48 /* Supporting Files */, ); @@ -193,6 +202,7 @@ 1E11AFA519432236006BCE48 /* ExSwiftStringTests.swift */, 1EA5F689194387CA00E8A40F /* ExSwiftTests.swift */, 1EC241FD1946E92E0047109A /* ExSwiftNSArrayTests.swift */, + 6CB1F1601A8AB8D3002EA767 /* ExSwiftBoolTests.swift */, 1E11AF941943222D006BCE48 /* Supporting Files */, ); path = ExSwiftTests; @@ -384,6 +394,7 @@ 3C0AB978195C7FAF0009BDA0 /* Sequence.swift in Sources */, 1E11AFB21943225B006BCE48 /* Array.swift in Sources */, 1ED536841943863100BDA94E /* ExSwift.swift in Sources */, + 6CB1F15F1A8AB867002EA767 /* Bool.swift in Sources */, 1E11AFB41943225B006BCE48 /* Dictionary.swift in Sources */, 1E11AFB61943225B006BCE48 /* Float.swift in Sources */, 1E11AFB81943225B006BCE48 /* Int.swift in Sources */, @@ -396,6 +407,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6CB1F1611A8AB8D3002EA767 /* ExSwiftBoolTests.swift in Sources */, 1E1DABF5197ECF030070CFBC /* ExSwiftArrayTests.swift in Sources */, 1E11AFAA19432236006BCE48 /* ExSwiftRangeTests.swift in Sources */, 2EB34F09195473AC00A8D2AF /* Int.swift in Sources */, @@ -410,6 +422,7 @@ 3C0AB97D195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift in Sources */, 2EB34F0C195473AC00A8D2AF /* NSArray.swift in Sources */, 2EB34F05195473AC00A8D2AF /* ExSwift.swift in Sources */, + 6CB1F1631A8ABA1A002EA767 /* Bool.swift in Sources */, 2EB34F08195473AC00A8D2AF /* Float.swift in Sources */, 1E11AFAB19432236006BCE48 /* ExSwiftStringTests.swift in Sources */, 1E11AFA919432236006BCE48 /* ExSwiftIntTests.swift in Sources */, @@ -427,6 +440,7 @@ 2EC02FCD194ED10500619CB5 /* Float.swift in Sources */, 3C0AB97A195C7FB30009BDA0 /* Sequence.swift in Sources */, 2EC02FCA194ED10500619CB5 /* ExSwift.swift in Sources */, + 6CB1F1641A8ABA1A002EA767 /* Bool.swift in Sources */, 2EC02FCE194ED10500619CB5 /* Int.swift in Sources */, 2EC02FCF194ED10500619CB5 /* Range.swift in Sources */, 2EC02FD0194ED10500619CB5 /* String.swift in Sources */, @@ -440,6 +454,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6CB1F1621A8AB979002EA767 /* ExSwiftBoolTests.swift in Sources */, 1ED8FC30194EF9E1004F829A /* ExSwiftDictionaryTests.swift in Sources */, 2EB34F111954744D00A8D2AF /* Int.swift in Sources */, 2EB34F0E1954744D00A8D2AF /* Array.swift in Sources */, @@ -454,6 +469,7 @@ 3C0AB97E195C7FC20009BDA0 /* ExSwiftSequenceTests.swift in Sources */, 2EB34F141954744D00A8D2AF /* NSArray.swift in Sources */, 2EB34F0D1954744D00A8D2AF /* ExSwift.swift in Sources */, + 6CB1F1661A8ABA1C002EA767 /* Bool.swift in Sources */, 2EB34F101954744D00A8D2AF /* Float.swift in Sources */, 1ED8FC35194EF9E1004F829A /* ExSwiftTests.swift in Sources */, 1ED8FC36194EF9E1004F829A /* ExSwiftNSArrayTests.swift in Sources */, diff --git a/ExSwift/Bool.swift b/ExSwift/Bool.swift new file mode 100644 index 0000000..7071efe --- /dev/null +++ b/ExSwift/Bool.swift @@ -0,0 +1,18 @@ +// +// Bool.swift +// ExSwift +// +// Created by Hernandez Alvarez, David on 2/10/15. +// Copyright (c) 2015 pNre. All rights reserved. +// + +import Foundation + +extension Bool { + + mutating func toggle() -> Bool { + self = !self + return self + } + +} \ No newline at end of file diff --git a/ExSwiftTests/ExSwiftBoolTests.swift b/ExSwiftTests/ExSwiftBoolTests.swift new file mode 100644 index 0000000..6696c1f --- /dev/null +++ b/ExSwiftTests/ExSwiftBoolTests.swift @@ -0,0 +1,23 @@ +// +// ExSwiftBoolTests.swift +// ExSwift +// +// Created by Hernandez Alvarez, David on 2/10/15. +// Copyright (c) 2015 pNre. All rights reserved. +// + +import XCTest + +class ExSwiftBoolTests: XCTestCase { + + func testToogleTrue() { + var bool: Bool = false + XCTAssertTrue(bool.toggle(), "Bool did not toogle to true") + } + + func testToogleFalse() { + var bool: Bool = true + XCTAssertFalse(bool.toggle(), "Bool did not toogle to false") + } + +} \ No newline at end of file From 3c1032cfdb57d07d2ebd5cc0914e97ee2d9fa9d3 Mon Sep 17 00:00:00 2001 From: Nick Shelley Date: Wed, 25 Feb 2015 12:08:17 -0700 Subject: [PATCH 02/10] Add Lisp's find method to Arrays. --- ExSwift/Array.swift | 30 +++++++++++++++++++++++++++- ExSwiftTests/ExSwiftArrayTests.swift | 15 ++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ExSwift/Array.swift b/ExSwift/Array.swift index 3118a78..6bdd7ca 100644 --- a/ExSwift/Array.swift +++ b/ExSwift/Array.swift @@ -124,6 +124,34 @@ internal extension Array { @availability(*, unavailable, message="use the 'last' property instead") func last () -> Element? { return last } + + /** + First occurrence of item, if found. + + :param: item The item to search for + :returns: Matched item or nil + */ + func find (item: U) -> T? { + if let index = indexOf(item) { + return self[index] + } + + return nil + } + + /** + First item that meets the condition. + + :param: condition A function which returns a boolean if an element satisfies a given condition or not. + :returns: First matched item or nil + */ + func find (condition: Element -> Bool) -> T? { + if let index = indexOf(condition) { + return self[index] + } + + return nil + } /** Index of the first occurrence of item, if found. @@ -133,7 +161,7 @@ internal extension Array { */ func indexOf (item: U) -> Int? { if item is Element { - return find(unsafeBitCast(self, [U].self), item) + return Swift.find(unsafeBitCast(self, [U].self), item) } return nil diff --git a/ExSwiftTests/ExSwiftArrayTests.swift b/ExSwiftTests/ExSwiftArrayTests.swift index 694caad..784e56f 100644 --- a/ExSwiftTests/ExSwiftArrayTests.swift +++ b/ExSwiftTests/ExSwiftArrayTests.swift @@ -128,6 +128,21 @@ class ExtensionsArrayTests: XCTestCase { XCTAssertEqual(diff, array) XCTAssertEqual(array - [], array) } + + func testFind() { + // Equatable parameter + XCTAssertEqual(1, array.find(1)!) + XCTAssertEqual(3, array.find(3)!) + XCTAssertNil(array.find(6)) + + // Matching block + XCTAssertEqual(2, array.find { item in + return item % 2 == 0 + }!) + XCTAssertNil(array.find { item in + return item > 10 + }) + } func testIndexOf() { // Equatable parameter From 3a4a08d7f6f2f53380ffc1ca8ac60d496d96176d Mon Sep 17 00:00:00 2001 From: Nick Shelley Date: Sun, 1 Mar 2015 12:05:39 -0700 Subject: [PATCH 03/10] Update find with condition to use takeFirst. --- ExSwift/Array.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ExSwift/Array.swift b/ExSwift/Array.swift index 6bdd7ca..2a6c8f4 100644 --- a/ExSwift/Array.swift +++ b/ExSwift/Array.swift @@ -145,12 +145,8 @@ internal extension Array { :param: condition A function which returns a boolean if an element satisfies a given condition or not. :returns: First matched item or nil */ - func find (condition: Element -> Bool) -> T? { - if let index = indexOf(condition) { - return self[index] - } - - return nil + func find (condition: Element -> Bool) -> Element? { + return takeFirst(condition) } /** From c1bd78f7d6aa3d8a07f50c62b2769cf2ca7277fb Mon Sep 17 00:00:00 2001 From: Hilton Campbell Date: Mon, 16 Mar 2015 13:26:20 -0600 Subject: [PATCH 04/10] Ex.cached for 1-arg functions. --- ExSwift/ExSwift.swift | 31 ++++++++++++++++++++++++++----- ExSwiftTests/ExSwiftTests.swift | 25 +++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/ExSwift/ExSwift.swift b/ExSwift/ExSwift.swift index 556aae3..cfdc7c8 100644 --- a/ExSwift/ExSwift.swift +++ b/ExSwift/ExSwift.swift @@ -140,6 +140,28 @@ public class ExSwift { } } + /** + Creates a wrapper for function that caches the result of function's invocations. + + :param: function Function with one parameter to cache + :returns: Wrapper function + */ + public class func cached (function: P -> R) -> (P -> R) { + var cache = [P:R]() + + return { (param: P) -> R in + let key = param + + if let cachedValue = cache[key] { + return cachedValue + } else { + let value = function(param) + cache[key] = value + return value + } + } + } + /** Creates a wrapper for function that caches the result of function's invocations. @@ -154,7 +176,6 @@ public class ExSwift { var cache = [P:R]() return { (params: P...) -> R in - let adaptedFunction = unsafeBitCast(function, Function.self) let adaptedHash = unsafeBitCast(hash, Hash.self) @@ -162,11 +183,11 @@ public class ExSwift { if let cachedValue = cache[key] { return cachedValue + } else { + let value = adaptedFunction(params) + cache[key] = value + return value } - - cache[key] = adaptedFunction(params) - - return cache[key]! } } diff --git a/ExSwiftTests/ExSwiftTests.swift b/ExSwiftTests/ExSwiftTests.swift index 03d4a39..0cb2a3a 100644 --- a/ExSwiftTests/ExSwiftTests.swift +++ b/ExSwiftTests/ExSwiftTests.swift @@ -76,6 +76,31 @@ class ExSwiftTests: XCTestCase { XCTAssertEqual(helloWorld(), "Hello World") } + func testOneArgCached () { + var calls = 0 + + // Slow Fibonacci + var fib: ((Int) -> Int)! + fib = { (n: Int) -> Int in + calls++ + + if n <= 1 { + return n + } + return fib(n - 1) + fib(n - 2) + } + + let fibonacci = Ex.cached(fib) + + // This one is computed (fib is called 465 times) + fibonacci(12) + XCTAssertEqual(465, calls) + + // The results is taken from the cache (fib is not called) + fibonacci(12) + XCTAssertEqual(465, calls) + } + func testCached () { var calls = 0 diff --git a/README.md b/README.md index 5024cab..62db43b 100644 --- a/README.md +++ b/README.md @@ -427,7 +427,7 @@ Name | Signatures **`once`**|`once (function: P -> T) -> (P -> T?)`
`once (call: Void -> T) -> (Void -> T?)` **`partial`**|`partial (function: (P...) -> T, _ parameters: P...) -> ((P...) -> T?)` **`bind`**|`bind (function: (P...) -> T, _ parameters: P...) -> (() -> T)` -**`cached`**|`cached (function: (P...) -> R) -> ((P...) -> R)`
`cached (function: (P...) -> R, hash: ((P...) -> P)) -> ((P...) -> R)` +**`cached`**|`cached (function: P -> R) -> (P -> R)`
`cached (function: (P...) -> R) -> ((P...) -> R)`
`cached (function: (P...) -> R, hash: ((P...) -> P)) -> ((P...) -> R)` #### Operators #### Name | Signatures From 4c09a2a3561e995a1283408446ae405e09db5074 Mon Sep 17 00:00:00 2001 From: pNre Date: Thu, 19 Mar 2015 21:56:41 +0100 Subject: [PATCH 05/10] String.toDouble updated to support scientific notation --- ExSwift/String.swift | 25 +++++++++++++------------ ExSwiftTests/ExSwiftStringTests.swift | 11 ++++++++++- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ExSwift/String.swift b/ExSwift/String.swift index dbee9c4..8436600 100644 --- a/ExSwift/String.swift +++ b/ExSwift/String.swift @@ -216,19 +216,15 @@ public extension String { */ func toDouble() -> Double? { - let pattern = "^[-+]?[0-9]*\\.?[0-9]+$" + let scanner = NSScanner(string: self) + var double: Double = 0 - if let regex = ExSwift.regex(pattern, ignoreCase: true) { - let text = self.trimmed() - let matches = regex.matchesInString(text, options: nil, range: NSMakeRange(0, countElements(text))) - if matches.isEmpty { - return nil - } - - return (self as NSString).doubleValue + if scanner.scanDouble(&double) { + return double } return nil + } /** @@ -237,11 +233,16 @@ public extension String { :returns: A float parsed from the string or nil if it cannot be parsed. */ func toFloat() -> Float? { - if let val = self.toDouble() { - return Float(val) + + let scanner = NSScanner(string: self) + var float: Float = 0 + + if scanner.scanFloat(&float) { + return float } - + return nil + } /** diff --git a/ExSwiftTests/ExSwiftStringTests.swift b/ExSwiftTests/ExSwiftStringTests.swift index 97ba64c..b7db1d2 100644 --- a/ExSwiftTests/ExSwiftStringTests.swift +++ b/ExSwiftTests/ExSwiftStringTests.swift @@ -150,6 +150,7 @@ class ExSwiftStringTests: XCTestCase { } func testToDouble() { + var d : Double = " 7.2 ".toDouble()! XCTAssertEqual(7.2, d) @@ -159,7 +160,15 @@ class ExSwiftStringTests: XCTestCase { d = "42".toDouble()! XCTAssertEqual(42, d) - XCTAssertNil("a772.2".toDouble()) + XCTAssertNil("a772.2".toDouble()) + + // scientific notation + d = "2.1e3".toDouble()! + XCTAssertEqualWithAccuracy(d, 2100.0, 0.001) + + d = "10.5e-2".toDouble()! + XCTAssertEqualWithAccuracy(d, 0.105, 0.001) + } func testToFloat() { From 15a67303c55eb48d234a039c823c9b1bfad3f77a Mon Sep 17 00:00:00 2001 From: PGLongo Date: Fri, 27 Mar 2015 16:22:51 +0100 Subject: [PATCH 06/10] Fix compatibility issue NSDate add --- ExSwift/NSDate.swift | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ExSwift/NSDate.swift b/ExSwift/NSDate.swift index f45a907..96ac56f 100644 --- a/ExSwift/NSDate.swift +++ b/ExSwift/NSDate.swift @@ -26,13 +26,27 @@ public extension NSDate { */ public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate { var calendar = NSCalendar.currentCalendar() - var date = calendar.dateByAddingUnit(.CalendarUnitSecond, value: seconds, toDate: self, options: nil) as NSDate! - date = calendar.dateByAddingUnit(.CalendarUnitMinute, value: minutes, toDate: date, options: nil) - date = calendar.dateByAddingUnit(.CalendarUnitDay, value: days, toDate: date, options: nil) - date = calendar.dateByAddingUnit(.CalendarUnitHour, value: hours, toDate: date, options: nil) - date = calendar.dateByAddingUnit(.CalendarUnitWeekOfMonth, value: weeks, toDate: date, options: nil) - date = calendar.dateByAddingUnit(.CalendarUnitMonth, value: months, toDate: date, options: nil) - date = calendar.dateByAddingUnit(.CalendarUnitYear, value: years, toDate: date, options: nil) + + var component = NSDateComponents() + component.setValue(seconds, forComponent: .CalendarUnitSecond) + var date : NSDate! = calendar.dateByAddingComponents(component, toDate: self, options: nil)! + component = NSDateComponents() + component.setValue(minutes, forComponent: .CalendarUnitMinute) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(days, forComponent: .CalendarUnitDay) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(hours, forComponent: .CalendarUnitHour) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component.setValue(weeks, forComponent: .CalendarUnitWeekOfMonth) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(months, forComponent: .CalendarUnitMonth) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(years, forComponent: .CalendarUnitYear) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! return date } From c49a1c229bd26601cb7bc140f900e04ff40a8051 Mon Sep 17 00:00:00 2001 From: PGLongo Date: Fri, 27 Mar 2015 16:27:05 +0100 Subject: [PATCH 07/10] Add version check --- ExSwift/NSDate.swift | 52 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/ExSwift/NSDate.swift b/ExSwift/NSDate.swift index 96ac56f..4fa22f5 100644 --- a/ExSwift/NSDate.swift +++ b/ExSwift/NSDate.swift @@ -26,27 +26,37 @@ public extension NSDate { */ public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate { var calendar = NSCalendar.currentCalendar() - - var component = NSDateComponents() - component.setValue(seconds, forComponent: .CalendarUnitSecond) - var date : NSDate! = calendar.dateByAddingComponents(component, toDate: self, options: nil)! - component = NSDateComponents() - component.setValue(minutes, forComponent: .CalendarUnitMinute) - date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! - component = NSDateComponents() - component.setValue(days, forComponent: .CalendarUnitDay) - date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! - component = NSDateComponents() - component.setValue(hours, forComponent: .CalendarUnitHour) - date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! - component.setValue(weeks, forComponent: .CalendarUnitWeekOfMonth) - date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! - component = NSDateComponents() - component.setValue(months, forComponent: .CalendarUnitMonth) - date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! - component = NSDateComponents() - component.setValue(years, forComponent: .CalendarUnitYear) - date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1 || floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber10_9_2 ) { + var component = NSDateComponents() + component.setValue(seconds, forComponent: .CalendarUnitSecond) + var date : NSDate! = calendar.dateByAddingComponents(component, toDate: self, options: nil)! + component = NSDateComponents() + component.setValue(minutes, forComponent: .CalendarUnitMinute) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(days, forComponent: .CalendarUnitDay) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(hours, forComponent: .CalendarUnitHour) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component.setValue(weeks, forComponent: .CalendarUnitWeekOfMonth) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(months, forComponent: .CalendarUnitMonth) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() + component.setValue(years, forComponent: .CalendarUnitYear) + date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + return date + } + + var date : NSDate! = calendar.dateByAddingUnit(.CalendarUnitSecond, value: seconds, toDate: self, options: nil) + date = calendar.dateByAddingUnit(.CalendarUnitMinute, value: minutes, toDate: date, options: nil) + date = calendar.dateByAddingUnit(.CalendarUnitDay, value: days, toDate: date, options: nil) + date = calendar.dateByAddingUnit(.CalendarUnitHour, value: hours, toDate: date, options: nil) + date = calendar.dateByAddingUnit(.CalendarUnitWeekOfMonth, value: weeks, toDate: date, options: nil) + date = calendar.dateByAddingUnit(.CalendarUnitMonth, value: months, toDate: date, options: nil) + date = calendar.dateByAddingUnit(.CalendarUnitYear, value: years, toDate: date, options: nil) return date } From 5c9d8cb980557100f5f23ac832399d870b089499 Mon Sep 17 00:00:00 2001 From: PGLongo Date: Fri, 27 Mar 2015 16:37:41 +0100 Subject: [PATCH 08/10] Saved NSFoundationVersionNumber to constant --- ExSwift/NSDate.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ExSwift/NSDate.swift b/ExSwift/NSDate.swift index 4fa22f5..e4ae3da 100644 --- a/ExSwift/NSDate.swift +++ b/ExSwift/NSDate.swift @@ -26,7 +26,8 @@ public extension NSDate { */ public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate { var calendar = NSCalendar.currentCalendar() - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1 || floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber10_9_2 ) { + let version = floor(NSFoundationVersionNumber) + if ( version <= NSFoundationVersionNumber_iOS_7_1 || version <= NSFoundationVersionNumber10_9_2 ) { var component = NSDateComponents() component.setValue(seconds, forComponent: .CalendarUnitSecond) var date : NSDate! = calendar.dateByAddingComponents(component, toDate: self, options: nil)! From 68d9f46db6fd49049b556a4608785a99c80081ad Mon Sep 17 00:00:00 2001 From: PGLongo Date: Fri, 3 Apr 2015 14:56:41 +0200 Subject: [PATCH 09/10] Fix hour and day order in iOS7 version of NSDate add --- ExSwift/NSDate.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ExSwift/NSDate.swift b/ExSwift/NSDate.swift index e4ae3da..db1a49b 100644 --- a/ExSwift/NSDate.swift +++ b/ExSwift/NSDate.swift @@ -24,27 +24,34 @@ public extension NSDate { :param: years number of years to add :returns: the NSDate computed */ - public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate { + public func add(seconds: Int = 0, minutes: Int = 0, hours: Int = 0, days: Int = 0, weeks: Int = 0, months: Int = 0, years: Int = 0) -> NSDate { var calendar = NSCalendar.currentCalendar() let version = floor(NSFoundationVersionNumber) if ( version <= NSFoundationVersionNumber_iOS_7_1 || version <= NSFoundationVersionNumber10_9_2 ) { var component = NSDateComponents() component.setValue(seconds, forComponent: .CalendarUnitSecond) + var date : NSDate! = calendar.dateByAddingComponents(component, toDate: self, options: nil)! component = NSDateComponents() component.setValue(minutes, forComponent: .CalendarUnitMinute) date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() - component.setValue(days, forComponent: .CalendarUnitDay) + component.setValue(hours, forComponent: .CalendarUnitHour) date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() - component.setValue(hours, forComponent: .CalendarUnitHour) + component.setValue(days, forComponent: .CalendarUnitDay) date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + + component = NSDateComponents() component.setValue(weeks, forComponent: .CalendarUnitWeekOfMonth) date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() component.setValue(months, forComponent: .CalendarUnitMonth) date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! + component = NSDateComponents() component.setValue(years, forComponent: .CalendarUnitYear) date = calendar.dateByAddingComponents(component, toDate: date, options: nil)! From d5a9092aa880ae37734173e0e4ca4f242e1b8989 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 6 Apr 2015 18:11:00 +0300 Subject: [PATCH 10/10] Added automatically generated change log file --- CHANGELOG.md | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3acb79a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,239 @@ +# Change Log + +## [Unreleased](https://github.com/pNre/ExSwift/tree/HEAD) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.9...HEAD) + +**Closed issues:** + +- NSDate addUnit stuff not working in ios7 [\#97](https://github.com/pNre/ExSwift/issues/97) + +- weak support [\#96](https://github.com/pNre/ExSwift/issues/96) + +- @synchronized support [\#95](https://github.com/pNre/ExSwift/issues/95) + +- string.toDouble\(\) should accept "1.23e4" [\#94](https://github.com/pNre/ExSwift/issues/94) + +- Compile fix for Swift 1.2 [\#90](https://github.com/pNre/ExSwift/issues/90) + +- Swift-1.2 branch causing Segmentation fault: 11 [\#81](https://github.com/pNre/ExSwift/issues/81) + +- Support for Swift 1.2 [\#80](https://github.com/pNre/ExSwift/issues/80) + +- Still breaks range literals [\#71](https://github.com/pNre/ExSwift/issues/71) + +- flatMap [\#62](https://github.com/pNre/ExSwift/issues/62) + +- Nil filter method on array [\#59](https://github.com/pNre/ExSwift/issues/59) + +- don't use array extension function [\#54](https://github.com/pNre/ExSwift/issues/54) + +- Documentation small issue [\#53](https://github.com/pNre/ExSwift/issues/53) + +- Spare the TakeSequence and TakeWhileSequence structs [\#52](https://github.com/pNre/ExSwift/issues/52) + +- No one is merging in changes [\#49](https://github.com/pNre/ExSwift/issues/49) + +- Swift Compile Error on Xcode 6.1 [\#38](https://github.com/pNre/ExSwift/issues/38) + +- ExSwift breaks range subscripting [\#32](https://github.com/pNre/ExSwift/issues/32) + +- skipWhile [\#31](https://github.com/pNre/ExSwift/issues/31) + +**Merged pull requests:** + +- Enhance Carthage Support [\#103](https://github.com/pNre/ExSwift/pull/103) ([nebhale](https://github.com/nebhale)) + +- Remove Deprecation Warnings [\#102](https://github.com/pNre/ExSwift/pull/102) ([nebhale](https://github.com/nebhale)) + +- Fix compatibility issue NSDate add [\#101](https://github.com/pNre/ExSwift/pull/101) ([PGLongo](https://github.com/PGLongo)) + +- Ex.cached for 1-arg functions. [\#93](https://github.com/pNre/ExSwift/pull/93) ([hiltonc](https://github.com/hiltonc)) + +- fixed for Xcode Version 6.3 beta 3 [\#89](https://github.com/pNre/ExSwift/pull/89) ([katopz](https://github.com/katopz)) + +- fix compiler error 'missing argument \#2' [\#88](https://github.com/pNre/ExSwift/pull/88) ([sebbean](https://github.com/sebbean)) + +- Format Number [\#86](https://github.com/pNre/ExSwift/pull/86) ([PGLongo](https://github.com/PGLongo)) + +- Fix compiler errors in second Xcode 6.3 beta \(6D532l\). [\#84](https://github.com/pNre/ExSwift/pull/84) ([JakobR](https://github.com/JakobR)) + +- Add Lisp's find method to Arrays. [\#83](https://github.com/pNre/ExSwift/pull/83) ([nickmshelley](https://github.com/nickmshelley)) + +- Add Bool extension [\#79](https://github.com/pNre/ExSwift/pull/79) ([davidman](https://github.com/davidman)) + +- Swift 1.2 \(Xcode 6.3\) support [\#78](https://github.com/pNre/ExSwift/pull/78) ([markusl](https://github.com/markusl)) + +- Made Framework and Unit Test iOS / OS X universal [\#76](https://github.com/pNre/ExSwift/pull/76) ([colemancda](https://github.com/colemancda)) + +- added method and tests [\#73](https://github.com/pNre/ExSwift/pull/73) ([michaeleisel](https://github.com/michaeleisel)) + +- added methods and tests [\#72](https://github.com/pNre/ExSwift/pull/72) ([michaeleisel](https://github.com/michaeleisel)) + +- added method and tests [\#70](https://github.com/pNre/ExSwift/pull/70) ([michaeleisel](https://github.com/michaeleisel)) + +- added method, tests, and whitespace changes [\#69](https://github.com/pNre/ExSwift/pull/69) ([michaeleisel](https://github.com/michaeleisel)) + +- Round to nearest [\#68](https://github.com/pNre/ExSwift/pull/68) ([michaeleisel](https://github.com/michaeleisel)) + +- added arithmetic methods [\#67](https://github.com/pNre/ExSwift/pull/67) ([michaeleisel](https://github.com/michaeleisel)) + +- added strideable methods [\#66](https://github.com/pNre/ExSwift/pull/66) ([michaeleisel](https://github.com/michaeleisel)) + +- removed unnecessary methods [\#65](https://github.com/pNre/ExSwift/pull/65) ([michaeleisel](https://github.com/michaeleisel)) + +- completely redid permutation generating [\#64](https://github.com/pNre/ExSwift/pull/64) ([michaeleisel](https://github.com/michaeleisel)) + +- Add shared schemes for installation by Carthage. [\#63](https://github.com/pNre/ExSwift/pull/63) ([yoichitgy](https://github.com/yoichitgy)) + +- Add getter and comparison to NSDate [\#61](https://github.com/pNre/ExSwift/pull/61) ([PGLongo](https://github.com/PGLongo)) + +- mapAccum for Array [\#60](https://github.com/pNre/ExSwift/pull/60) ([phatmann](https://github.com/phatmann)) + +- Added to\* methods to readme docs. [\#58](https://github.com/pNre/ExSwift/pull/58) ([mikeckennedy](https://github.com/mikeckennedy)) + +- Trimmed methods fail on string that contains only whitespace [\#57](https://github.com/pNre/ExSwift/pull/57) ([pizthewiz](https://github.com/pizthewiz)) + +- Add toNumeric \(e.g. toDouble\) conversions to string extensions [\#56](https://github.com/pNre/ExSwift/pull/56) ([mikeckennedy](https://github.com/mikeckennedy)) + +- Added overloaded ltrimmed and rtrimmed methods [\#55](https://github.com/pNre/ExSwift/pull/55) ([hhoangnl](https://github.com/hhoangnl)) + +- Update Dictionary.swift [\#51](https://github.com/pNre/ExSwift/pull/51) ([davidman](https://github.com/davidman)) + +- Added Charater extension [\#50](https://github.com/pNre/ExSwift/pull/50) ([cennydavidsson](https://github.com/cennydavidsson)) + +- Repeated permutations [\#48](https://github.com/pNre/ExSwift/pull/48) ([michaeleisel](https://github.com/michaeleisel)) + +- Added NSDate methods [\#47](https://github.com/pNre/ExSwift/pull/47) ([PGLongo](https://github.com/PGLongo)) + +- Repeated combinations [\#46](https://github.com/pNre/ExSwift/pull/46) ([michaeleisel](https://github.com/michaeleisel)) + +- Fill [\#45](https://github.com/pNre/ExSwift/pull/45) ([michaeleisel](https://github.com/michaeleisel)) + +- Transpose [\#44](https://github.com/pNre/ExSwift/pull/44) ([michaeleisel](https://github.com/michaeleisel)) + +- Permutations [\#43](https://github.com/pNre/ExSwift/pull/43) ([michaeleisel](https://github.com/michaeleisel)) + +- added combinations method [\#42](https://github.com/pNre/ExSwift/pull/42) ([michaeleisel](https://github.com/michaeleisel)) + +- Unique by method [\#41](https://github.com/pNre/ExSwift/pull/41) ([michaeleisel](https://github.com/michaeleisel)) + +- Added UIColor extension [\#39](https://github.com/pNre/ExSwift/pull/39) ([PGLongo](https://github.com/PGLongo)) + +- Added minBy and maxBy methods [\#37](https://github.com/pNre/ExSwift/pull/37) ([michaeleisel](https://github.com/michaeleisel)) + +- Add installation instruction [\#35](https://github.com/pNre/ExSwift/pull/35) ([kostiakoval](https://github.com/kostiakoval)) + +- the script can generation a Framework of StaticLibrary [\#30](https://github.com/pNre/ExSwift/pull/30) ([zhfish](https://github.com/zhfish)) + +## [0.1.9](https://github.com/pNre/ExSwift/tree/0.1.9) (2014-08-20) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.8...0.1.9) + +**Merged pull requests:** + +- Added count methods [\#27](https://github.com/pNre/ExSwift/pull/27) ([jmnavarro](https://github.com/jmnavarro)) + +## [0.1.8](https://github.com/pNre/ExSwift/tree/0.1.8) (2014-08-05) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.7...0.1.8) + +**Closed issues:** + +- ExSwift broken in beta 5 [\#26](https://github.com/pNre/ExSwift/issues/26) + +- Single index string subscripting results in compiler error [\#25](https://github.com/pNre/ExSwift/issues/25) + +- Array.indexOf not working with \[UInt\] [\#21](https://github.com/pNre/ExSwift/issues/21) + +**Merged pull requests:** + +- Changes =~ to take regular expression. [\#22](https://github.com/pNre/ExSwift/pull/22) ([nomothetis](https://github.com/nomothetis)) + +## [0.1.7](https://github.com/pNre/ExSwift/tree/0.1.7) (2014-07-25) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.6...0.1.7) + +**Closed issues:** + +- Breaks in Xcode6-Beta4 [\#19](https://github.com/pNre/ExSwift/issues/19) + +**Merged pull requests:** + +- Added access modifiers [\#20](https://github.com/pNre/ExSwift/pull/20) ([vmartinelli](https://github.com/vmartinelli)) + +## [0.1.6](https://github.com/pNre/ExSwift/tree/0.1.6) (2014-07-22) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.5...0.1.6) + +## [0.1.5](https://github.com/pNre/ExSwift/tree/0.1.5) (2014-07-19) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.4...0.1.5) + +**Closed issues:** + +- Support for Double / Integer [\#18](https://github.com/pNre/ExSwift/issues/18) + +- Help, got so many compile errors [\#17](https://github.com/pNre/ExSwift/issues/17) + +## [0.1.4](https://github.com/pNre/ExSwift/tree/0.1.4) (2014-07-07) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.3...0.1.4) + +**Merged pull requests:** + +- used shuffle\(\) to shuffle in shuffled\(\) [\#16](https://github.com/pNre/ExSwift/pull/16) ([natecook1000](https://github.com/natecook1000)) + +## [0.1.3](https://github.com/pNre/ExSwift/tree/0.1.3) (2014-07-03) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.2...0.1.3) + +**Merged pull requests:** + +- Sequence ops [\#15](https://github.com/pNre/ExSwift/pull/15) ([ColinEberhardt](https://github.com/ColinEberhardt)) + +- Added a toDictionary method [\#13](https://github.com/pNre/ExSwift/pull/13) ([ColinEberhardt](https://github.com/ColinEberhardt)) + +- Added a sortBy method [\#12](https://github.com/pNre/ExSwift/pull/12) ([ColinEberhardt](https://github.com/ColinEberhardt)) + +- Define iOS module with the same name as OS X, cleanup duplicate files [\#11](https://github.com/pNre/ExSwift/pull/11) ([garnett](https://github.com/garnett)) + +- Simplify partition tests [\#10](https://github.com/pNre/ExSwift/pull/10) ([zolrath](https://github.com/zolrath)) + +## [0.1.2](https://github.com/pNre/ExSwift/tree/0.1.2) (2014-06-18) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.1...0.1.2) + +**Fixed bugs:** + +- Compile error: Access String array by subscript [\#6](https://github.com/pNre/ExSwift/issues/6) + +**Closed issues:** + +- Result of indexOf, lastIndexOf should be an optional [\#8](https://github.com/pNre/ExSwift/issues/8) + +**Merged pull requests:** + +- Add .gitignore, add iOS Framework + tests target [\#7](https://github.com/pNre/ExSwift/pull/7) ([garnett](https://github.com/garnett)) + +- return Int? in indexOf, lastIndexOf [\#9](https://github.com/pNre/ExSwift/pull/9) ([garnett](https://github.com/garnett)) + +- Add partition, partitionAll, and partitionBy [\#5](https://github.com/pNre/ExSwift/pull/5) ([zolrath](https://github.com/zolrath)) + +- Add takeWhile and skipWhile to Array [\#4](https://github.com/pNre/ExSwift/pull/4) ([zolrath](https://github.com/zolrath)) + +## [0.1.1](https://github.com/pNre/ExSwift/tree/0.1.1) (2014-06-11) + +[Full Changelog](https://github.com/pNre/ExSwift/compare/0.1.0...0.1.1) + +**Merged pull requests:** + +- Use if let syntax for Dictionary {group, count}by [\#3](https://github.com/pNre/ExSwift/pull/3) ([zolrath](https://github.com/zolrath)) + +- Use if let syntax for groupBy and countBy [\#2](https://github.com/pNre/ExSwift/pull/2) ([zolrath](https://github.com/zolrath)) + +## [0.1.0](https://github.com/pNre/ExSwift/tree/0.1.0) (2014-06-10) + + + +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file