Skip to content

Commit e0ca8fb

Browse files
committed
[Foundation] Keep NS Updates due to changes in SE-0086
Second pass at updates for SE-0086 feedback <rdar://problem/26892977> Make sure NSOrderedSet keeps its NS <rdar://problem/26880016> NSBundleResourceRequest should keep its NS <rdar://problem/26892958> Make sure NSAttributedString keeps its NS <rdar://problem/26653694> NSCoder.decodeTopLevelObjectForKey does not follow naming guidelines <rdar://problem/27355801> Foundation should have a structural type for TextCheckingResult <rdar://problem/26770611> NSExpression naming is a bit awkward in swift <rdar://problem/26653451> NSCoder encodeDataObject is misleading <rdar://problem/26653653> NSCoder decodeObjectOfClass is redundant
1 parent b1bf920 commit e0ca8fb

File tree

8 files changed

+155
-74
lines changed

8 files changed

+155
-74
lines changed

apinotes/Foundation.apinotes

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Classes:
6868
SwiftName: dataWithContentsOfMappedFile(_:)
6969
MethodKind: Class
7070
- Name: NSCountedSet
71-
SwiftName: CountedSet
71+
SwiftName: NSCountedSet
7272
- Name: NSDate
7373
SwiftName: NSDate
7474
SwiftBridge: Date
@@ -173,6 +173,12 @@ Classes:
173173
- Selector: 'decodeIntForKey:'
174174
Availability: nonswift
175175
MethodKind: Instance
176+
- Selector: 'encodeDataObject:'
177+
SwiftName: encode(_:)
178+
MethodKind: Instance
179+
- Selector: 'decodeDataObject'
180+
SwiftName: decodeData()
181+
MethodKind: Instance
176182
- Name: NSNotification
177183
SwiftName: NSNotification
178184
SwiftBridge: Notification
@@ -756,6 +762,7 @@ Classes:
756762
SwiftName: isPartialStringValid(_:newEditingString:errorDescription:)
757763
MethodKind: Instance
758764
- Name: NSConditionLock
765+
SwiftName: NSConditionLock
759766
Methods:
760767
- Selector: 'tryLockWhenCondition:'
761768
SwiftName: tryLock(whenCondition:)
@@ -813,6 +820,7 @@ Classes:
813820
SwiftName: scanUpTo(_:into:)
814821
MethodKind: Instance
815822
- Name: NSTextCheckingResult
823+
SwiftName: NSTextCheckingResult
816824
Methods:
817825
- Selector: 'rangeAtIndex:'
818826
SwiftName: rangeAt(_:)
@@ -926,6 +934,9 @@ Classes:
926934
MethodKind: Instance
927935
- Name: NSUserDefaults
928936
Methods:
937+
- Selector: 'registerDefaults:'
938+
SwiftName: register(defaults:)
939+
MethodKind: Instance
929940
- Selector: 'setObject:forKey:'
930941
SwiftName: set(_:forKey:)
931942
MethodKind: Instance
@@ -972,7 +983,39 @@ Classes:
972983
SwiftName: NSMachPort
973984
- Name: NSOutputStream
974985
SwiftName: NSOutputStream
986+
- Name: NSRegularExpression
987+
SwiftName: NSRegularExpression
988+
- Name: NSComparisonPredicate
989+
SwiftName: NSComparisonPredicate
990+
- Name: NSCompoundPredicate
991+
SwiftName: NSCompoundPredicate
992+
- Name: NSPredicate
993+
SwiftName: NSPredicate
994+
- Name: NSMapTable
995+
SwiftName: NSMapTable
996+
- Name: NSHashTable
997+
SwiftName: NSHashTable
998+
- Name: NSPointerArray
999+
SwiftName: NSPointerArray
1000+
- Name: NSPointerFunctions
1001+
SwiftName: NSPointerFunctions
1002+
- Name: NSCache
1003+
SwiftName: NSCache
1004+
- Name: NSPurgeableData
1005+
SwiftName: NSPurgeableData
1006+
- Name: NSLock
1007+
SwiftName: NSLock
1008+
- Name: NSCondition
1009+
SwiftName: NSCondition
1010+
- Name: NSDistributedLock
1011+
SwiftName: NSDistributedLock
1012+
- Name: NSRecursiveLock
1013+
SwiftName: NSRecursiveLock
1014+
- Name: NSSortDescriptor
1015+
SwiftName: NSSortDescriptor
9751016
Protocols:
1017+
- Name: NSLocking
1018+
SwiftName: NSLocking
9761019
- Name: NSMetadataQueryDelegate
9771020
SwiftName: NSMetadataQueryDelegate
9781021
- Name: NSCopying
@@ -1015,6 +1058,7 @@ Protocols:
10151058
SwiftName: presentedSubitem(at:didResolve:)
10161059
MethodKind: Instance
10171060
- Name: NSDiscardableContent
1061+
SwiftName: NSDiscardableContent
10181062
Methods:
10191063
- Selector: beginContentAccess
10201064
SwiftName: beginContentAccess()
@@ -1034,6 +1078,8 @@ Protocols:
10341078
SwiftName: NSURLHandleClient
10351079
- Name: NSMachPortDelegate
10361080
SwiftName: NSMachPortDelegate
1081+
- Name: NSCacheDelegate
1082+
SwiftName: NSCacheDelegate
10371083
Tags:
10381084
- Name: NSActivityOptions
10391085
SwiftName: ProcessInfo.ActivityOptions
@@ -1074,13 +1120,13 @@ Tags:
10741120
- Name: NSDecodingFailurePolicy
10751121
SwiftName: NSCoder.DecodingFailurePolicy
10761122
- Name: NSComparisonPredicateOptions
1077-
SwiftName: ComparisonPredicate.Options
1123+
SwiftName: NSComparisonPredicate.Options
10781124
- Name: NSComparisonPredicateModifier
1079-
SwiftName: ComparisonPredicate.Modifier
1125+
SwiftName: NSComparisonPredicate.Modifier
10801126
- Name: NSPredicateOperatorType
1081-
SwiftName: ComparisonPredicate.Operator
1127+
SwiftName: NSComparisonPredicate.Operator
10821128
- Name: NSCompoundPredicateType
1083-
SwiftName: CompoundPredicate.LogicalType
1129+
SwiftName: NSCompoundPredicate.LogicalType
10841130
- Name: NSDateFormatterStyle
10851131
SwiftName: DateFormatter.Style
10861132
- Name: NSDateFormatterBehavior
@@ -1166,22 +1212,22 @@ Tags:
11661212
- Name: NSPropertyListFormat
11671213
SwiftName: PropertyListSerialization.PropertyListFormat
11681214
- Name: NSRegularExpressionOptions
1169-
SwiftName: RegularExpression.Options
1215+
SwiftName: NSRegularExpression.Options
11701216
- Name: NSMatchingOptions
1171-
SwiftName: RegularExpression.MatchingOptions
1217+
SwiftName: NSRegularExpression.MatchingOptions
11721218
- Name: NSMatchingFlags
1173-
SwiftName: RegularExpression.MatchingFlags
1219+
SwiftName: NSRegularExpression.MatchingFlags
11741220
- Name: NSStreamStatus
11751221
SwiftName: Stream.Status
11761222
- Name: NSStreamEvent
11771223
SwiftName: Stream.Event
11781224
- Name: NSTaskTerminationReason
11791225
SwiftName: Task.TerminationReason
11801226
- Name: NSTextCheckingType
1181-
SwiftName: TextCheckingResult.CheckingType
1227+
SwiftName: NSTextCheckingResult.CheckingType
11821228
- Name: NSTextCheckingTypes
11831229
Availability: nonswift
1184-
AvailabilityMsg: Use 'TextCheckingResult.CheckingType'
1230+
AvailabilityMsg: Use 'NSTextCheckingResult.CheckingType'
11851231
- Name: NSTimeZoneNameStyle
11861232
SwiftName: TimeZone.NameStyle
11871233
- Name: NSURLCacheStoragePolicy
@@ -1239,7 +1285,7 @@ Tags:
12391285
- Name: NSNetServiceOptions
12401286
SwiftName: NSNetService.Options
12411287
- Name: NSPointerFunctionsOptions
1242-
SwiftName: PointerFunctions.Options
1288+
SwiftName: NSPointerFunctions.Options
12431289
- Name: NSSearchPathDirectory
12441290
SwiftName: FileManager.SearchPathDirectory
12451291
- Name: NSSearchPathDomainMask
@@ -1351,6 +1397,14 @@ Typedefs:
13511397
SwiftName: URLFileProtection
13521398
- Name: NSURLBookmarkFileCreationOptions
13531399
SwiftName: NSURL.BookmarkFileCreationOptions
1400+
- Name: NSMapTableValueCallBacks
1401+
SwiftName: NSMapTableValueCallBacks
1402+
- Name: NSKeyValueOperator
1403+
SwiftName: NSKeyValueOperator
1404+
- Name: NSValueTransformerName
1405+
SwiftName: NSValueTransformerName
1406+
- Name: NSErrorDomain
1407+
SwiftName: NSErrorDomain
13541408
Globals:
13551409
- Name: NSAppleScriptErrorMessage
13561410
SwiftName: NSAppleScript.errorMessage
@@ -1383,11 +1437,11 @@ Globals:
13831437
- Name: NSTaskDidTerminateNotification
13841438
SwiftName: Task.didTerminateNotification
13851439
- Name: NSTextCheckingAllSystemTypes
1386-
SwiftName: TextCheckingResult.CheckingType.allSystemTypes
1440+
SwiftName: NSTextCheckingResult.CheckingType.allSystemTypes
13871441
- Name: NSTextCheckingAllCustomTypes
1388-
SwiftName: TextCheckingResult.CheckingType.allCustomTypes
1442+
SwiftName: NSTextCheckingResult.CheckingType.allCustomTypes
13891443
- Name: NSTextCheckingAllTypes
1390-
SwiftName: TextCheckingResult.CheckingType.allTypes
1444+
SwiftName: NSTextCheckingResult.CheckingType.allTypes
13911445
- Name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification
13921446
SwiftName: NSUbiquitousKeyValueStore.didChangeExternallyNotification
13931447
- Name: NSURLSessionTaskPriorityDefault

stdlib/public/SDK/CoreData/CoreData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ extension CocoaError {
272272

273273
/// For predicate-based validation, the predicate for the condition
274274
/// that failed to validate.
275-
public var validationPredicate: Predicate? {
276-
return userInfo[NSValidationPredicateErrorKey] as? Predicate
275+
public var validationPredicate: NSPredicate? {
276+
return userInfo[NSValidationPredicateErrorKey] as? NSPredicate
277277
}
278278

279279
/// The value for the key that failed to validate for a validation

stdlib/public/SDK/Foundation/Foundation.swift

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,17 @@ extension Dictionary : _ObjectiveCBridgeable {
611611
// TextChecking
612612
//===----------------------------------------------------------------------===//
613613

614-
extension TextCheckingResult.CheckingType {
615-
public static var allSystemTypes : TextCheckingResult.CheckingType {
616-
return TextCheckingResult.CheckingType(rawValue: 0xffffffff)
614+
extension NSTextCheckingResult.CheckingType {
615+
public static var allSystemTypes : NSTextCheckingResult.CheckingType {
616+
return NSTextCheckingResult.CheckingType(rawValue: 0xffffffff)
617617
}
618618

619-
public static var allCustomTypes : TextCheckingResult.CheckingType {
620-
return TextCheckingResult.CheckingType(rawValue: 0xffffffff << 32)
619+
public static var allCustomTypes : NSTextCheckingResult.CheckingType {
620+
return NSTextCheckingResult.CheckingType(rawValue: 0xffffffff << 32)
621621
}
622622

623-
public static var allTypes : TextCheckingResult.CheckingType {
624-
return TextCheckingResult.CheckingType(rawValue: UInt64.max)
623+
public static var allTypes : NSTextCheckingResult.CheckingType {
624+
return NSTextCheckingResult.CheckingType(rawValue: UInt64.max)
625625
}
626626
}
627627

@@ -1010,7 +1010,7 @@ func _convertErrorToNSError(_ error: Error) -> NSError {
10101010
// Variadic initializers and methods
10111011
//===----------------------------------------------------------------------===//
10121012

1013-
extension Predicate {
1013+
extension NSPredicate {
10141014
// + (NSPredicate *)predicateWithFormat:(NSString *)predicateFormat, ...;
10151015
public
10161016
convenience init(format predicateFormat: String, _ args: CVarArg...) {
@@ -1225,24 +1225,35 @@ internal func resolveError(_ error: NSError?) throws {
12251225
}
12261226

12271227
extension NSCoder {
1228+
@available(*, unavailable, renamed: "decodeObject(of:forKey:)")
12281229
public func decodeObjectOfClass<DecodedObjectType>(
12291230
_ cls: DecodedObjectType.Type, forKey key: String
1231+
) -> DecodedObjectType?
1232+
where DecodedObjectType : NSCoding, DecodedObjectType : NSObject {
1233+
fatalError("This API has been renamed")
1234+
}
1235+
1236+
public func decodeObject<DecodedObjectType>(
1237+
of cls: DecodedObjectType.Type, forKey key: String
12301238
) -> DecodedObjectType?
12311239
where DecodedObjectType : NSCoding, DecodedObjectType : NSObject {
12321240
let result = NS_Swift_NSCoder_decodeObjectOfClassForKey(self as AnyObject, cls as AnyObject, key as AnyObject, nil)
1233-
return result as! DecodedObjectType?
1241+
return result as? DecodedObjectType
12341242
}
12351243

1244+
@available(*, unavailable, renamed: "decodeObject(of:forKey:)")
12361245
@nonobjc
12371246
public func decodeObjectOfClasses(_ classes: NSSet?, forKey key: String) -> AnyObject? {
1238-
var classesAsNSObjects: Set<NSObject>? = nil
1247+
fatalError("This API has been renamed")
1248+
}
1249+
1250+
@nonobjc
1251+
public func decodeObject(of classes: [AnyClass]?, forKey key: String) -> AnyObject? {
1252+
var classesAsNSObjects: NSSet? = nil
12391253
if let theClasses = classes {
1240-
classesAsNSObjects =
1241-
Set(IteratorSequence(NSFastEnumerationIterator(theClasses)).map {
1242-
unsafeBitCast($0, to: NSObject.self)
1243-
})
1254+
classesAsNSObjects = NSSet(array: theClasses.map { $0 as AnyObject })
12441255
}
1245-
return self.__decodeObject(ofClasses: classesAsNSObjects, forKey: key)
1256+
return NS_Swift_NSCoder_decodeObjectOfClassesForKey(self as AnyObject, classesAsNSObjects, key as AnyObject, nil)
12461257
}
12471258

12481259
@available(OSX 10.11, iOS 9.0, *)
@@ -1253,29 +1264,51 @@ extension NSCoder {
12531264
return result
12541265
}
12551266

1256-
@available(OSX 10.11, iOS 9.0, *)
1267+
@available(*, unavailable, renamed: "decodeTopLevelObject(forKey:)")
12571268
public func decodeTopLevelObjectForKey(_ key: String) throws -> AnyObject? {
1269+
fatalError("This API has been renamed")
1270+
}
1271+
1272+
@available(OSX 10.11, iOS 9.0, *)
1273+
public func decodeTopLevelObject(forKey key: String) throws -> AnyObject? {
12581274
var error: NSError?
12591275
let result = NS_Swift_NSCoder_decodeObjectForKey(self as AnyObject, key as AnyObject, &error)
12601276
try resolveError(error)
12611277
return result
12621278
}
12631279

1264-
@available(OSX 10.11, iOS 9.0, *)
1280+
@available(*, unavailable, renamed: "decodeTopLevelObject(of:forKey:)")
12651281
public func decodeTopLevelObjectOfClass<DecodedObjectType>(
12661282
_ cls: DecodedObjectType.Type, forKey key: String
1283+
) throws -> DecodedObjectType?
1284+
where DecodedObjectType : NSCoding, DecodedObjectType : NSObject {
1285+
fatalError("This API has been renamed")
1286+
}
1287+
1288+
@available(OSX 10.11, iOS 9.0, *)
1289+
public func decodeTopLevelObject<DecodedObjectType>(
1290+
of cls: DecodedObjectType.Type, forKey key: String
12671291
) throws -> DecodedObjectType?
12681292
where DecodedObjectType : NSCoding, DecodedObjectType : NSObject {
12691293
var error: NSError?
12701294
let result = NS_Swift_NSCoder_decodeObjectOfClassForKey(self as AnyObject, cls as AnyObject, key as AnyObject, &error)
12711295
try resolveError(error)
1272-
return result as! DecodedObjectType?
1296+
return result as? DecodedObjectType
12731297
}
12741298

1275-
@available(OSX 10.11, iOS 9.0, *)
1299+
@available(*, unavailable, renamed: "decodeTopLevelObject(of:forKey:)")
12761300
public func decodeTopLevelObjectOfClasses(_ classes: NSSet?, forKey key: String) throws -> AnyObject? {
1277-
var error: NSError?
1278-
let result = NS_Swift_NSCoder_decodeObjectOfClassesForKey(self as AnyObject, classes, key as AnyObject, &error)
1301+
fatalError("This API has been renamed")
1302+
}
1303+
1304+
@available(OSX 10.11, iOS 9.0, *)
1305+
public func decodeTopLevelObject(of classes: [AnyClass]?, forKey key: String) throws -> AnyObject? {
1306+
var error: NSError? = nil
1307+
var classesAsNSObjects: NSSet? = nil
1308+
if let theClasses = classes {
1309+
classesAsNSObjects = NSSet(array: theClasses.map { $0 as AnyObject })
1310+
}
1311+
let result = NS_Swift_NSCoder_decodeObjectOfClassesForKey(self as AnyObject, classesAsNSObjects, key as AnyObject, &error)
12791312
try resolveError(error)
12801313
return result
12811314
}

test/1_stdlib/ErrorBridged.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func archiveAndUnarchiveObject<T: NSCoding where T: NSObject>(
7575
NSKeyedArchiver.archivedData(withRootObject: object)
7676
)
7777
unarchiver.requiresSecureCoding = true
78-
return unarchiver.decodeObjectOfClass(T.self, forKey: "root")
78+
return unarchiver.decodeObject(of: T.self, forKey: "root")
7979
}
8080
ErrorBridgingTests.test("NSCoding") {
8181
autoreleasepool {

test/1_stdlib/Foundation_NewGenericAPIs.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ func test_NSCoder_decodeObjectForKey(_ coder: NSCoder, key: String) {
2424
}
2525

2626
func test_NSCoder_decodeObjectOfClasses_forKey(
27-
_ coder: NSCoder, classes: NSSet?, key: String
27+
_ coder: NSCoder, classes: [AnyClass]?, key: String
2828
) {
29-
var r = coder.decodeObjectOfClasses(classes, forKey: key)
29+
var r = coder.decodeObject(of: classes, forKey: key)
3030
expectType(Optional<AnyObject>.self, &r)
3131
}
3232

3333
@available(iOS, introduced: 9.0)
3434
@available(OSX, introduced: 10.11)
3535
func test_NSCoder_decodeTopLevelObjectOfClasses_forKey_error(
36-
_ coder: NSCoder, classes: NSSet?, key: String
36+
_ coder: NSCoder, classes: [AnyClass]?, key: String
3737
) throws {
38-
var r = try coder.decodeTopLevelObjectOfClasses(classes, forKey: key)
38+
var r = try coder.decodeTopLevelObject(of: classes, forKey: key)
3939
expectType(Optional<AnyObject>.self, &r)
4040
}
4141

test/ClangModules/objc_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ extension Printing {
549549
func testSetInitializers() {
550550
let a: [AnyObject] = [NSObject()]
551551

552-
let _ = CountedSet(array: a)
552+
let _ = NSCountedSet(array: a)
553553
let _ = NSMutableSet(array: a)
554554
}
555555

test/Interpreter/SDK/Foundation_NSPredicate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88

99
// Test overlain variadic methods.
10-
let s = Predicate(format: "(lastName like[cd] %@) AND (birthday > %@)", "LLLL", "BBBB")
10+
let s = NSPredicate(format: "(lastName like[cd] %@) AND (birthday > %@)", "LLLL", "BBBB")
1111
print(s.predicateFormat)
1212

1313
// CHECK: lastName LIKE[cd] "LLLL" AND birthday > "BBBB"

0 commit comments

Comments
 (0)