Skip to content

Commit 0dea15a

Browse files
authored
Merge branch 'master' into nscoder-doc
2 parents e45720b + 6ae998b commit 0dea15a

7 files changed

+36
-42
lines changed

Foundation/NSCoder.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ open class NSCoder : NSObject {
682682
///
683683
/// - Parameter key: The coder key.
684684
/// - Returns: A decoded object containing a property list.
685-
open func decodePropertyListForKey(_ key: String) -> Any? {
685+
open func decodePropertyList(forKey key: String) -> Any? {
686686
NSUnimplemented()
687687
}
688688

Foundation/NSError.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ public extension LocalizedError {
222222
/// NSErrorRecoveryAttempting, which is used by NSError when it
223223
/// attempts recovery from an error.
224224
class _NSErrorRecoveryAttempter {
225-
func attemptRecovery(fromError nsError: NSError,
225+
func attemptRecovery(fromError error: Error,
226226
optionIndex recoveryOptionIndex: Int) -> Bool {
227-
let error = nsError as Error as! RecoverableError
227+
let error = error as! RecoverableError
228228
return error.attemptRecovery(optionIndex: recoveryOptionIndex)
229229
}
230230
}

Foundation/NSGeometry.swift

+17-17
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ extension CGPoint: NSSpecialValueCoding {
4141
guard aDecoder.allowsKeyedCoding else {
4242
preconditionFailure("Unkeyed coding is unsupported.")
4343
}
44-
self = aDecoder.decodePointForKey("NS.pointval")
44+
self = aDecoder.decodePoint(forKey: "NS.pointval")
4545
}
4646

4747
func encodeWithCoder(_ aCoder: NSCoder) {
4848
guard aCoder.allowsKeyedCoding else {
4949
preconditionFailure("Unkeyed coding is unsupported.")
5050
}
51-
aCoder.encodePoint(self, forKey: "NS.pointval")
51+
aCoder.encode(self, forKey: "NS.pointval")
5252
}
5353

5454
static func objCType() -> String {
@@ -104,14 +104,14 @@ extension CGSize: NSSpecialValueCoding {
104104
guard aDecoder.allowsKeyedCoding else {
105105
preconditionFailure("Unkeyed coding is unsupported.")
106106
}
107-
self = aDecoder.decodeSizeForKey("NS.sizeval")
107+
self = aDecoder.decodeSize(forKey: "NS.sizeval")
108108
}
109109

110110
func encodeWithCoder(_ aCoder: NSCoder) {
111111
guard aCoder.allowsKeyedCoding else {
112112
preconditionFailure("Unkeyed coding is unsupported.")
113113
}
114-
aCoder.encodeSize(self, forKey: "NS.sizeval")
114+
aCoder.encode(self, forKey: "NS.sizeval")
115115
}
116116

117117
static func objCType() -> String {
@@ -186,14 +186,14 @@ extension CGRect: NSSpecialValueCoding {
186186
guard aDecoder.allowsKeyedCoding else {
187187
preconditionFailure("Unkeyed coding is unsupported.")
188188
}
189-
self = aDecoder.decodeRectForKey("NS.rectval")
189+
self = aDecoder.decodeRect(forKey: "NS.rectval")
190190
}
191191

192192
func encodeWithCoder(_ aCoder: NSCoder) {
193193
guard aCoder.allowsKeyedCoding else {
194194
preconditionFailure("Unkeyed coding is unsupported.")
195195
}
196-
aCoder.encodeRect(self, forKey: "NS.rectval")
196+
aCoder.encode(self, forKey: "NS.rectval")
197197
}
198198

199199
static func objCType() -> String {
@@ -807,7 +807,7 @@ extension NSValue {
807807

808808
extension NSCoder {
809809

810-
public func encodePoint(_ point: NSPoint) {
810+
public func encode(_ point: NSPoint) {
811811
self._encodeCGFloat(point.x)
812812
self._encodeCGFloat(point.y)
813813
}
@@ -816,7 +816,7 @@ extension NSCoder {
816816
return NSPoint(x: _decodeCGFloat(), y: _decodeCGFloat())
817817
}
818818

819-
public func encodeSize(_ size: NSSize) {
819+
public func encode(_ size: NSSize) {
820820
self._encodeCGFloat(size.width)
821821
self._encodeCGFloat(size.height)
822822
}
@@ -825,9 +825,9 @@ extension NSCoder {
825825
return NSSize(width: _decodeCGFloat(), height: _decodeCGFloat())
826826
}
827827

828-
public func encodeRect(_ rect: NSRect) {
829-
self.encodePoint(rect.origin)
830-
self.encodeSize(rect.size)
828+
public func encode(_ rect: NSRect) {
829+
self.encode(rect.origin)
830+
self.encode(rect.size)
831831
}
832832

833833
public func decodeRect() -> NSRect {
@@ -837,35 +837,35 @@ extension NSCoder {
837837

838838
extension NSCoder {
839839

840-
public func encodePoint(_ point: NSPoint, forKey key: String) {
840+
public func encode(_ point: NSPoint, forKey key: String) {
841841
self.encode(NSStringFromPoint(point)._bridgeToObjectiveC(), forKey: key)
842842
}
843843

844-
public func encodeSize(_ size: NSSize, forKey key: String) {
844+
public func encode(_ size: NSSize, forKey key: String) {
845845
self.encode(NSStringFromSize(size)._bridgeToObjectiveC(), forKey: key)
846846
}
847847

848-
public func encodeRect(_ rect: NSRect, forKey key: String) {
848+
public func encode(_ rect: NSRect, forKey key: String) {
849849
self.encode(NSStringFromRect(rect)._bridgeToObjectiveC(), forKey: key)
850850
}
851851

852-
public func decodePointForKey(_ key: String) -> NSPoint {
852+
public func decodePoint(forKey key: String) -> NSPoint {
853853
if let string = self.decodeObject(of: NSString.self, forKey: key) {
854854
return NSPointFromString(String._unconditionallyBridgeFromObjectiveC(string))
855855
} else {
856856
return NSPoint()
857857
}
858858
}
859859

860-
public func decodeSizeForKey(_ key: String) -> NSSize {
860+
public func decodeSize(forKey key: String) -> NSSize {
861861
if let string = self.decodeObject(of: NSString.self, forKey: key) {
862862
return NSSizeFromString(String._unconditionallyBridgeFromObjectiveC(string))
863863
} else {
864864
return NSSize()
865865
}
866866
}
867867

868-
public func decodeRectForKey(_ key: String) -> NSRect {
868+
public func decodeRect(forKey key: String) -> NSRect {
869869
if let string = self.decodeObject(of: NSString.self, forKey: key) {
870870
return NSRectFromString(String._unconditionallyBridgeFromObjectiveC(string))
871871
} else {

Foundation/NSKeyedArchiver.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,10 @@ open class NSKeyedArchiver : NSCoder {
483483
return objectToEncode
484484
}
485485

486-
// object replaced by NSObject.replacementObjectForKeyedArchiver
486+
// object replaced by NSObject.replacementObject(for:)
487487
// if it is replaced with nil, it cannot be further replaced
488488
if let ns = objectToEncode as? NSObject {
489-
objectToEncode = ns.replacementObjectForKeyedArchiver(self)
489+
objectToEncode = ns.replacementObject(for: self)
490490
if objectToEncode == nil {
491491
replaceObject(object!, withObject: nil)
492492
return nil
@@ -799,7 +799,7 @@ public protocol NSKeyedArchiverDelegate : class {
799799
// either returns this object or can return a different object to be encoded
800800
// instead. The delegate can also fiddle with the coder state. If the delegate
801801
// returns nil, nil is encoded. This method is called after the original object
802-
// may have replaced itself with replacementObjectForKeyedArchiver:.
802+
// may have replaced itself with replacementObject(for:).
803803
// This method is not called for an object once a replacement mapping has been
804804
// setup for that object (either explicitly, or because the object has previously
805805
// been encoded). This is also not called when nil is about to be encoded.

Foundation/NSKeyedUnarchiver.swift

+4-10
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,12 @@ open class NSKeyedUnarchiver : NSCoder {
669669
return _decodeObject(of: NSPropertyListClasses)
670670
}
671671

672-
open override func decodePropertyListForKey(_ key: String) -> Any? {
672+
open override func decodePropertyList(forKey key: String) -> Any? {
673673
return decodeObject(of: NSPropertyListClasses, forKey:key)
674674
}
675675

676676
/**
677-
Note that unlike decodePropertyListForKey(), _decodePropertyListForKey() decodes
677+
Note that unlike decodePropertyList(forKey:), _decodePropertyListForKey() decodes
678678
a property list in the current decoding context rather than as an object. It's
679679
also able to return value types.
680680
*/
@@ -863,15 +863,9 @@ open class NSKeyedUnarchiver : NSCoder {
863863
}
864864

865865
open class func unarchiveTopLevelObjectWithData(_ data: Data) throws -> Any? {
866-
var root : Any? = nil
867-
868866
let keyedUnarchiver = NSKeyedUnarchiver(forReadingWithData: data)
869-
do {
870-
try root = keyedUnarchiver.decodeTopLevelObject(forKey: NSKeyedArchiveRootObjectKey)
871-
keyedUnarchiver.finishDecoding()
872-
} catch {
873-
}
874-
867+
let root = try keyedUnarchiver.decodeTopLevelObject(forKey: NSKeyedArchiveRootObjectKey)
868+
keyedUnarchiver.finishDecoding()
875869
return root
876870
}
877871
}

Foundation/NSObject.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ open class NSObject : NSObjectProtocol, Equatable, Hashable {
260260
///
261261
/// - Parameter aCoder: The coder encoding the instance.
262262
/// - Returns: The object encode instead of the instance (if different).
263-
open func replacementObjectForCoder(_ aCoder: NSCoder) -> Any? {
263+
open func replacementObject(for aCoder: NSCoder) -> Any? {
264264
return self
265265
}
266266

@@ -284,8 +284,8 @@ open class NSObject : NSObjectProtocol, Equatable, Hashable {
284284
///
285285
/// - Parameter archiver: A keyed archiver creating an archive.
286286
/// - Returns: The object encode instead of the instance (if different).
287-
open func replacementObjectForKeyedArchiver(_ archiver: NSKeyedArchiver) -> Any? {
288-
return self.replacementObjectForCoder(archiver)
287+
open func replacementObject(for archiver: NSKeyedArchiver) -> Any? {
288+
return self.replacementObject(for: archiver as NSCoder)
289289
}
290290

291291
/// Overridden to return the names of classes that can be used to decode

Foundation/NSRunLoop.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public struct RunLoopMode : RawRepresentable, Equatable, Hashable, Comparable {
3333
public var hashValue: Int {
3434
return rawValue.hashValue
3535
}
36-
}
3736

38-
public func ==(lhs: RunLoopMode, rhs: RunLoopMode) -> Bool {
39-
return lhs.rawValue == rhs.rawValue
40-
}
37+
public static func ==(_ lhs: RunLoopMode, _ rhs: RunLoopMode) -> Bool {
38+
return lhs.rawValue == rhs.rawValue
39+
}
4140

42-
public func <(lhs: RunLoopMode, rhs: RunLoopMode) -> Bool {
43-
return lhs.rawValue < rhs.rawValue
41+
public static func <(_ lhs: RunLoopMode, _ rhs: RunLoopMode) -> Bool {
42+
return lhs.rawValue < rhs.rawValue
43+
}
4444
}
4545

4646

0 commit comments

Comments
 (0)