Skip to content

Commit 03f7a93

Browse files
author
Pushkar N Kulkarni
committed
Change the NSHTTPCookie API to the Darwin version
2 parents 05d1b6b + 5dcaadb commit 03f7a93

23 files changed

+674
-735
lines changed

Foundation/NSCache.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class NSCache : NSObject {
3838

3939
public weak var delegate: NSCacheDelegate?
4040

41-
public func objectForKey(_ key: AnyObject) -> AnyObject? {
41+
public func object(forKey key: AnyObject) -> AnyObject? {
4242
var object: AnyObject?
4343

4444
let keyRef = unsafeBitCast(key, to: UnsafePointer<Void>.self)
@@ -157,7 +157,7 @@ public class NSCache : NSObject {
157157
_lock.unlock()
158158
}
159159

160-
public func removeObjectForKey(_ key: AnyObject) {
160+
public func removeObject(forKey key: AnyObject) {
161161
let keyRef = unsafeBitCast(key, to: UnsafePointer<Void>.self)
162162

163163
_lock.lock()

Foundation/NSCalendar.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
814814
*/
815815
public func isDateInYesterday(_ date: NSDate) -> Bool {
816816
if let interval = rangeOfUnit(.Day, forDate: NSDate()) {
817-
let inYesterday = interval.start.dateByAddingTimeInterval(-60.0)
817+
let inYesterday = interval.start.addingTimeInterval(-60.0)
818818
return compareDate(date, toDate: inYesterday, toUnitGranularity: .Day) == .OrderedSame
819819
} else {
820820
return false
@@ -826,7 +826,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
826826
*/
827827
public func isDateInTomorrow(_ date: NSDate) -> Bool {
828828
if let interval = rangeOfUnit(.Day, forDate: NSDate()) {
829-
let inTomorrow = interval.end.dateByAddingTimeInterval(60.0)
829+
let inTomorrow = interval.end.addingTimeInterval(60.0)
830830
return compareDate(date, toDate: inTomorrow, toUnitGranularity: .Day) == .OrderedSame
831831
} else {
832832
return false
@@ -878,7 +878,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
878878
let comp = NSDateComponents()
879879
comp.weekday = range.start
880880
if let nextStart = nextDateAfterDate(date, matchingComponents: comp, options: options.union(.MatchNextTime)) {
881-
let start = nextStart.dateByAddingTimeInterval(range.onsetTime)
881+
let start = nextStart.addingTimeInterval(range.onsetTime)
882882
comp.weekday = range.end
883883
if let nextEnd = nextDateAfterDate(date, matchingComponents: comp, options: options.union(.MatchNextTime)) {
884884
var end = nextEnd
@@ -890,7 +890,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
890890
}
891891
}
892892
if range.ceaseTime > 0 {
893-
end = end.dateByAddingTimeInterval(range.ceaseTime)
893+
end = end.addingTimeInterval(range.ceaseTime)
894894
} else {
895895
if let dayEnd = rangeOfUnit(.Day, forDate: end) {
896896
end = startOfDayForDate(dayEnd.end)
@@ -1042,7 +1042,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
10421042
if opts.contains(.MatchStrictly) {
10431043
options.unionInPlace(.MatchStrictly)
10441044
}
1045-
if let result = nextDateAfterDate(range.start.dateByAddingTimeInterval(-0.5), matchingComponents: comps, options: options) {
1045+
if let result = nextDateAfterDate(range.start.addingTimeInterval(-0.5), matchingComponents: comps, options: options) {
10461046
if result.compare(range.start) == .OrderedAscending {
10471047
return nextDateAfterDate(range.start, matchingComponents: comps, options: options)
10481048
}

Foundation/NSData.swift

Lines changed: 49 additions & 49 deletions
Large diffs are not rendered by default.

Foundation/NSDate.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
3030

3131
public override func isEqual(_ object: AnyObject?) -> Bool {
3232
if let date = object as? NSDate {
33-
return isEqualToDate(date)
33+
return isEqual(to: date)
3434
} else {
3535
return false
3636
}
@@ -149,19 +149,19 @@ public class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
149149

150150
extension NSDate {
151151

152-
public func timeIntervalSinceDate(_ anotherDate: NSDate) -> NSTimeInterval {
152+
public func timeIntervalSince(_ anotherDate: NSDate) -> NSTimeInterval {
153153
return self.timeIntervalSinceReferenceDate - anotherDate.timeIntervalSinceReferenceDate
154154
}
155155

156156
public var timeIntervalSinceNow: NSTimeInterval {
157-
return timeIntervalSinceDate(NSDate())
157+
return timeIntervalSince(NSDate())
158158
}
159159

160160
public var timeIntervalSince1970: NSTimeInterval {
161161
return timeIntervalSinceReferenceDate + NSTimeIntervalSince1970
162162
}
163163

164-
public func dateByAddingTimeInterval(_ ti: NSTimeInterval) -> NSDate {
164+
public func addingTimeInterval(_ ti: NSTimeInterval) -> NSDate {
165165
return NSDate(timeIntervalSinceReferenceDate:_timeIntervalSinceReferenceDate + ti)
166166
}
167167

@@ -193,7 +193,7 @@ extension NSDate {
193193
}
194194
}
195195

196-
public func isEqualToDate(_ otherDate: NSDate) -> Bool {
196+
public func isEqual(to otherDate: NSDate) -> Bool {
197197
return timeIntervalSinceReferenceDate == otherDate.timeIntervalSinceReferenceDate
198198
}
199199
}

Foundation/NSDateFormatter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public class NSDateFormatter : NSFormatter {
4747

4848
public override func stringForObjectValue(_ obj: AnyObject) -> String? {
4949
guard let date = obj as? NSDate else { return nil }
50-
return stringFromDate(date)
50+
return string(from: date)
5151
}
5252

53-
public func stringFromDate(_ date: NSDate) -> String {
53+
public func string(from date: NSDate) -> String {
5454
return CFDateFormatterCreateStringWithDate(kCFAllocatorSystemDefault, _cfObject, date._cfObject)._swiftObject
5555
}
5656

@@ -65,14 +65,14 @@ public class NSDateFormatter : NSFormatter {
6565
return date
6666
}
6767

68-
public class func localizedStringFromDate(_ date: NSDate, dateStyle dstyle: NSDateFormatterStyle, timeStyle tstyle: NSDateFormatterStyle) -> String {
68+
public class func localizedString(from date: NSDate, dateStyle dstyle: NSDateFormatterStyle, timeStyle tstyle: NSDateFormatterStyle) -> String {
6969
let df = NSDateFormatter()
7070
df.dateStyle = dstyle
7171
df.timeStyle = tstyle
7272
return df.stringForObjectValue(date)!
7373
}
7474

75-
public class func dateFormatFromTemplate(_ tmplate: String, options opts: Int, locale: NSLocale?) -> String? {
75+
public class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: NSLocale?) -> String? {
7676
guard let res = CFDateFormatterCreateDateFormatFromTemplate(kCFAllocatorSystemDefault, tmplate._cfObject, CFOptionFlags(opts), locale?._cfObject) else {
7777
return nil
7878
}

Foundation/NSFileHandle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class NSFileHandle : NSObject, NSSecureCoding {
111111
}
112112

113113
public func writeData(_ data: NSData) {
114-
data.enumerateByteRangesUsingBlock() { (bytes, range, stop) in
114+
data.enumerateBytes() { (bytes, range, stop) in
115115
do {
116116
try NSData.writeToFileDescriptor(self._fd, path: nil, buf: bytes, length: range.length)
117117
} catch {

Foundation/NSFileManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ public class NSFileManager : NSObject {
680680

681681
public func createFile(atPath path: String, contents data: NSData?, attributes attr: [String : AnyObject]? = [:]) -> Bool {
682682
do {
683-
try (data ?? NSData()).writeToFile(path, options: .DataWritingAtomic)
683+
try (data ?? NSData()).write(toFile: path, options: .dataWritingAtomic)
684684
return true
685685
} catch _ {
686686
return false

0 commit comments

Comments
 (0)