Skip to content

Commit 8faae96

Browse files
authored
Merge pull request #570 from apple/revert-567-pr-grabbag
Revert "Foundation API Conformance Update: Miscellaneous"
2 parents 8cad4be + c1297d1 commit 8faae96

28 files changed

+542
-690
lines changed

Foundation/NSArray.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
508508
NSInvalidArgument("range \(r) extends beyond bounds \(bounds)")
509509
}
510510

511-
if opts.contains(.firstEqual) && opts.contains(.lastEqual) {
512-
NSInvalidArgument("both NSBinarySearching.firstEqual and NSBinarySearching.lastEqual options cannot be specified")
511+
if opts.contains(.FirstEqual) && opts.contains(.LastEqual) {
512+
NSInvalidArgument("both NSBinarySearching.FirstEqual and NSBinarySearching.LastEqual options cannot be specified")
513513
}
514514

515-
let searchForInsertionIndex = opts.contains(.insertionIndex)
515+
let searchForInsertionIndex = opts.contains(.InsertionIndex)
516516

517517
// fringe cases
518518
if r.length == 0 {
@@ -530,8 +530,8 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
530530
}
531531

532532
// common processing
533-
let firstEqual = opts.contains(.firstEqual)
534-
let lastEqual = opts.contains(.lastEqual)
533+
let firstEqual = opts.contains(.FirstEqual)
534+
let lastEqual = opts.contains(.LastEqual)
535535
let anyEqual = !(firstEqual || lastEqual)
536536

537537
var result = NSNotFound
@@ -627,9 +627,9 @@ public struct NSBinarySearchingOptions : OptionSet {
627627
public let rawValue : UInt
628628
public init(rawValue: UInt) { self.rawValue = rawValue }
629629

630-
public static let firstEqual = NSBinarySearchingOptions(rawValue: 1 << 8)
631-
public static let lastEqual = NSBinarySearchingOptions(rawValue: 1 << 9)
632-
public static let insertionIndex = NSBinarySearchingOptions(rawValue: 1 << 10)
630+
public static let FirstEqual = NSBinarySearchingOptions(rawValue: 1 << 8)
631+
public static let LastEqual = NSBinarySearchingOptions(rawValue: 1 << 9)
632+
public static let InsertionIndex = NSBinarySearchingOptions(rawValue: 1 << 10)
633633
}
634634

635635
open class NSMutableArray : NSArray {

Foundation/NSCache.swift

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,39 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
private class NSCacheEntry<KeyType : AnyObject, ObjectType : AnyObject> {
11-
var key: KeyType
12-
var value: ObjectType
13-
var cost: Int
14-
var prevByCost: NSCacheEntry?
15-
var nextByCost: NSCacheEntry?
16-
init(key: KeyType, value: ObjectType, cost: Int) {
17-
self.key = key
18-
self.value = value
19-
self.cost = cost
20-
}
21-
}
2210

23-
open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
24-
private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry<KeyType, ObjectType>>()
11+
open class Cache: NSObject {
12+
private class NSCacheEntry {
13+
var key: AnyObject
14+
var value: AnyObject
15+
var cost: Int
16+
var prevByCost: NSCacheEntry?
17+
var nextByCost: NSCacheEntry?
18+
init(key: AnyObject, value: AnyObject, cost: Int) {
19+
self.key = key
20+
self.value = value
21+
self.cost = cost
22+
}
23+
}
24+
25+
private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry>()
2526
private let _lock = NSLock()
2627
private var _totalCost = 0
27-
private var _byCost: NSCacheEntry<KeyType, ObjectType>?
28+
private var _byCost: NSCacheEntry?
2829

2930
open var name: String = ""
3031
open var totalCostLimit: Int = -1 // limits are imprecise/not strict
3132
open var countLimit: Int = -1 // limits are imprecise/not strict
3233
open var evictsObjectsWithDiscardedContent: Bool = false
3334

34-
public override init() {}
35+
public override init() {
36+
37+
}
3538

3639
open weak var delegate: NSCacheDelegate?
3740

38-
open func object(forKey key: KeyType) -> ObjectType? {
39-
var object: ObjectType?
41+
open func object(forKey key: AnyObject) -> AnyObject? {
42+
var object: AnyObject?
4043

4144
let keyRef = unsafeBitCast(key, to: UnsafeRawPointer.self)
4245

@@ -49,11 +52,11 @@ open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
4952
return object
5053
}
5154

52-
open func setObject(_ obj: ObjectType, forKey key: KeyType) {
55+
open func setObject(_ obj: AnyObject, forKey key: AnyObject) {
5356
setObject(obj, forKey: key, cost: 0)
5457
}
5558

56-
private func remove(_ entry: NSCacheEntry<KeyType, ObjectType>) {
59+
private func remove(_ entry: NSCacheEntry) {
5760
let oldPrev = entry.prevByCost
5861
let oldNext = entry.nextByCost
5962
oldPrev?.nextByCost = oldNext
@@ -63,7 +66,7 @@ open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
6366
}
6467
}
6568

66-
private func insert(_ entry: NSCacheEntry<KeyType, ObjectType>) {
69+
private func insert(_ entry: NSCacheEntry) {
6770
if _byCost == nil {
6871
_byCost = entry
6972
} else {
@@ -80,7 +83,7 @@ open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
8083
}
8184
}
8285

83-
open func setObject(_ obj: ObjectType, forKey key: KeyType, cost g: Int) {
86+
open func setObject(_ obj: AnyObject, forKey key: AnyObject, cost g: Int) {
8487
let keyRef = unsafeBitCast(key, to: UnsafeRawPointer.self)
8588

8689
_lock.lock()
@@ -108,7 +111,7 @@ open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
108111
}
109112
_lock.unlock()
110113

111-
var toRemove = [NSCacheEntry<KeyType, ObjectType>]()
114+
var toRemove = [NSCacheEntry]()
112115

113116
if purgeAmount > 0 {
114117
_lock.lock()
@@ -143,7 +146,7 @@ open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
143146

144147
if let del = delegate {
145148
for entry in toRemove {
146-
del.cache(unsafeBitCast(self, to:NSCache<AnyObject, AnyObject>.self), willEvictObject: entry.value)
149+
del.cache(self, willEvictObject: entry.value)
147150
}
148151
}
149152

@@ -174,12 +177,12 @@ open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
174177
}
175178
}
176179

177-
public protocol NSCacheDelegate : NSObjectProtocol {
178-
func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: AnyObject)
180+
public protocol NSCacheDelegate : class {
181+
func cache(_ cache: Cache, willEvictObject obj: AnyObject)
179182
}
180183

181184
extension NSCacheDelegate {
182-
func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: AnyObject) {
185+
func cache(_ cache: Cache, willEvictObject obj: AnyObject) {
183186
// Default implementation does nothing
184187
}
185188
}

Foundation/NSComparisonPredicate.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10+
1011
// Flags(s) that can be passed to the factory to indicate that a operator operating on strings should do so in a case insensitive fashion.
11-
extension NSComparisonPredicate {
12+
extension ComparisonPredicate {
1213
public struct Options : OptionSet {
1314
public let rawValue : UInt
1415
public init(rawValue: UInt) { self.rawValue = rawValue }
@@ -20,13 +21,15 @@ extension NSComparisonPredicate {
2021

2122
// Describes how the operator is modified: can be direct, ALL, or ANY
2223
public enum Modifier : UInt {
24+
2325
case direct // Do a direct comparison
2426
case all // ALL toMany.x = y
2527
case any // ANY toMany.x = y
2628
}
2729

2830
// Type basic set of operators defined. Most are obvious
2931
public enum Operator : UInt {
32+
3033
case lessThan // compare: returns NSOrderedAscending
3134
case lessThanOrEqualTo // compare: returns NSOrderedAscending || NSOrderedSame
3235
case greaterThan // compare: returns NSOrderedDescending
@@ -42,9 +45,9 @@ extension NSComparisonPredicate {
4245
case between
4346
}
4447
}
45-
4648
// Comparison predicates are predicates which do some form of comparison between the results of two expressions and return a BOOL. They take an operator, a left expression, and a right expression, and return the result of invoking the operator with the results of evaluating the expressions.
47-
open class NSComparisonPredicate : NSPredicate {
49+
50+
open class ComparisonPredicate : Predicate {
4851

4952
public init(leftExpression lhs: NSExpression, rightExpression rhs: NSExpression, modifier: Modifier, type: Operator, options: Options) { NSUnimplemented() }
5053
public required init?(coder: NSCoder) { NSUnimplemented() }

Foundation/NSCompoundPredicate.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@
1010

1111
// Compound predicates are predicates which act on the results of evaluating other operators. We provide the basic boolean operators: AND, OR, and NOT.
1212

13-
extension NSCompoundPredicate {
13+
extension CompoundPredicate {
1414
public enum LogicalType : UInt {
15+
1516
case not
1617
case and
1718
case or
1819
}
1920
}
2021

21-
open class NSCompoundPredicate : NSPredicate {
22-
public init(type: LogicalType, subpredicates: [NSPredicate]) {
22+
open class CompoundPredicate : Predicate {
23+
24+
public init(type: LogicalType, subpredicates: [Predicate]) {
2325
if type == .not && subpredicates.count == 0 {
2426
preconditionFailure("Unsupported predicate count of \(subpredicates.count) for \(type)")
2527
}
26-
2728
self.compoundPredicateType = type
2829
self.subpredicates = subpredicates
2930
super.init(value: false)
3031
}
31-
3232
public required init?(coder: NSCoder) { NSUnimplemented() }
3333

34-
open var compoundPredicateType: LogicalType
35-
open var subpredicates: [NSPredicate]
34+
public let compoundPredicateType: LogicalType
35+
public let subpredicates: [Predicate]
3636

3737
/*** Convenience Methods ***/
38-
public convenience init(andPredicateWithSubpredicates subpredicates: [NSPredicate]) {
38+
public convenience init(andPredicateWithSubpredicates subpredicates: [Predicate]) {
3939
self.init(type: .and, subpredicates: subpredicates)
4040
}
41-
public convenience init(orPredicateWithSubpredicates subpredicates: [NSPredicate]) {
41+
public convenience init(orPredicateWithSubpredicates subpredicates: [Predicate]) {
4242
self.init(type: .or, subpredicates: subpredicates)
4343
}
44-
public convenience init(notPredicateWithSubpredicate predicate: NSPredicate) {
44+
public convenience init(notPredicateWithSubpredicate predicate: Predicate) {
4545
self.init(type: .not, subpredicates: [predicate])
4646
}
4747

Foundation/NSError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
145145
return userInfo[NSLocalizedRecoveryOptionsErrorKey] as? [String]
146146
}
147147

148-
open var recoveryAttempter: Any? {
149-
return userInfo[NSRecoveryAttempterErrorKey]
148+
open var recoveryAttempter: AnyObject? {
149+
return userInfo[NSRecoveryAttempterErrorKey] as? AnyObject
150150
}
151151

152152
open var helpAnchor: String? {

Foundation/NSExpression.swift

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ open class NSExpression : NSObject, NSSecureCoding, NSCopying {
5050
NSUnimplemented()
5151
}
5252

53-
public /*not inherited*/ init(format expressionFormat: String, argumentArray arguments: [Any]) { NSUnimplemented() }
54-
public /*not inherited*/ init(format expressionFormat: String, arguments argList: CVaListPointer) { NSUnimplemented() }
53+
public /*not inherited*/ init(format expressionFormat: String, argumentArray arguments: [AnyObject]) { NSUnimplemented() }
5554

56-
public /*not inherited*/ init(forConstantValue obj: Any?) { NSUnimplemented() } // Expression that returns a constant value
55+
public /*not inherited*/ init(forConstantValue obj: AnyObject?) { NSUnimplemented() } // Expression that returns a constant value
5756
open class func expressionForEvaluatedObject() -> NSExpression { NSUnimplemented() } // Expression that returns the object being evaluated
5857
public /*not inherited*/ init(forVariable string: String) { NSUnimplemented() } // Expression that pulls a value from the variable bindings dictionary
5958
public /*not inherited*/ init(forKeyPath keyPath: String) { NSUnimplemented() } // Expression that invokes valueForKeyPath with keyPath
60-
public /*not inherited*/ init(forFunction name: String, arguments parameters: [Any]) { NSUnimplemented() } // Expression that invokes one of the predefined functions. Will throw immediately if the selector is bad; will throw at runtime if the parameters are incorrect.
59+
public /*not inherited*/ init(forFunction name: String, arguments parameters: [AnyObject]) { NSUnimplemented() } // Expression that invokes one of the predefined functions. Will throw immediately if the selector is bad; will throw at runtime if the parameters are incorrect.
6160
// Predefined functions are:
6261
// name parameter array contents returns
6362
//-------------------------------------------------------------------------------------------------------------------------------------
@@ -99,43 +98,40 @@ open class NSExpression : NSObject, NSSecureCoding, NSCopying {
9998
// two NSExpression instances representing CLLocations NSNumber
10099
// length: an NSExpression instance representing a string NSNumber
101100

102-
public /*not inherited*/ init(forAggregate subexpressions: [Any]) { NSUnimplemented() } // Expression that returns a collection containing the results of other expressions
101+
public /*not inherited*/ init(forAggregate subexpressions: [AnyObject]) { NSUnimplemented() } // Expression that returns a collection containing the results of other expressions
103102
public /*not inherited*/ init(forUnionSet left: NSExpression, with right: NSExpression) { NSUnimplemented() } // return an expression that will return the union of the collections expressed by left and right
104103
public /*not inherited*/ init(forIntersectSet left: NSExpression, with right: NSExpression) { NSUnimplemented() } // return an expression that will return the intersection of the collections expressed by left and right
105104
public /*not inherited*/ init(forMinusSet left: NSExpression, with right: NSExpression) { NSUnimplemented() } // return an expression that will return the disjunction of the collections expressed by left and right
106-
public /*not inherited*/ init(forSubquery expression: NSExpression, usingIteratorVariable variable: String, predicate: Any) { NSUnimplemented() } // Expression that filters a collection by storing elements in the collection in the variable variable and keeping the elements for which qualifer returns true; variable is used as a local variable, and will shadow any instances of variable in the bindings dictionary, the variable is removed or the old value replaced once evaluation completes
107-
public /*not inherited*/ init(forFunction target: NSExpression, selectorName name: String, arguments parameters: [Any]?) { NSUnimplemented() } // Expression that invokes the selector on target with parameters. Will throw at runtime if target does not implement selector or if parameters are wrong.
105+
public /*not inherited*/ init(forSubquery expression: NSExpression, usingIteratorVariable variable: String, predicate: AnyObject) { NSUnimplemented() } // Expression that filters a collection by storing elements in the collection in the variable variable and keeping the elements for which qualifer returns true; variable is used as a local variable, and will shadow any instances of variable in the bindings dictionary, the variable is removed or the old value replaced once evaluation completes
106+
public /*not inherited*/ init(forFunction target: NSExpression, selectorName name: String, arguments parameters: [AnyObject]?) { NSUnimplemented() } // Expression that invokes the selector on target with parameters. Will throw at runtime if target does not implement selector or if parameters are wrong.
108107
open class func expressionForAnyKey() -> NSExpression { NSUnimplemented() }
109-
public /*not inherited*/ init(block: @escaping (Any?, [Any], NSMutableDictionary?) -> Any, arguments: [NSExpression]?) { NSUnimplemented() } // Expression that invokes the block with the parameters; note that block expressions are not encodable or representable as parseable strings.
110-
public /*not inherited*/ init(forConditional predicate: Any, trueExpression: NSExpression, falseExpression: NSExpression) { NSUnimplemented() } // Expression that will return the result of trueExpression or falseExpression depending on the value of predicate
108+
public /*not inherited*/ init(forBlock block: (AnyObject?, [AnyObject], NSMutableDictionary?) -> AnyObject, arguments: [NSExpression]?) { NSUnimplemented() } // Expression that invokes the block with the parameters; note that block expressions are not encodable or representable as parseable strings.
109+
public /*not inherited*/ init(forConditional predicate: Predicate, trueExpression: NSExpression, falseExpression: NSExpression) { NSUnimplemented() } // Expression that will return the result of trueExpression or falseExpression depending on the value of predicate
111110

112111
public init(expressionType type: ExpressionType) { NSUnimplemented() }
113112

114113
// accessors for individual parameters - raise if not applicable
115114
open var expressionType: ExpressionType { NSUnimplemented() }
116-
open var constantValue: Any { NSUnimplemented() }
115+
open var constantValue: AnyObject { NSUnimplemented() }
117116
open var keyPath: String { NSUnimplemented() }
118117
open var function: String { NSUnimplemented() }
119118
open var variable: String { NSUnimplemented() }
120119
/*@NSCopying*/ open var operand: NSExpression { NSUnimplemented() } // the object on which the selector will be invoked (the result of evaluating a key path or one of the defined functions)
121120
open var arguments: [NSExpression]? { NSUnimplemented() } // array of expressions which will be passed as parameters during invocation of the selector on the operand of a function expression
122121

123-
open var collection: Any { NSUnimplemented() }
124-
/*@NSCopying*/ open var predicate: NSPredicate { NSUnimplemented() }
122+
open var collection: AnyObject { NSUnimplemented() }
123+
/*@NSCopying*/ open var predicate: Predicate { NSUnimplemented() }
125124
/*@NSCopying*/ open var left: NSExpression { NSUnimplemented() } // expression which represents the left side of a set expression
126125
/*@NSCopying*/ open var right: NSExpression { NSUnimplemented() } // expression which represents the right side of a set expression
127126

128127
/*@NSCopying*/ open var `true`: NSExpression { NSUnimplemented() } // expression which will be evaluated if a conditional expression's predicate evaluates to true
129128
/*@NSCopying*/ open var `false`: NSExpression { NSUnimplemented() } // expression which will be evaluated if a conditional expression's predicate evaluates to false
130129

131-
open var expressionBlock: (Any?, [Any], NSMutableDictionary?) -> Any { NSUnimplemented() }
130+
open var expressionBlock: (AnyObject?, [AnyObject], NSMutableDictionary?) -> AnyObject { NSUnimplemented() }
132131

133132
// evaluate the expression using the object and bindings- note that context is mutable here and can be used by expressions to store temporary state for one predicate evaluation
134-
open func expressionValue(with object: Any?, context: NSMutableDictionary?) -> Any? { NSUnimplemented() }
133+
open func expressionValueWithObject(_ object: AnyObject?, context: NSMutableDictionary?) -> AnyObject { NSUnimplemented() }
135134

136135
open func allowEvaluation() { NSUnimplemented() } // Force an expression which was securely decoded to allow evaluation
137136
}
138137

139-
extension NSExpression {
140-
public convenience init(format expressionFormat: String, _ args: CVarArg...) { NSUnimplemented() }
141-
}

0 commit comments

Comments
 (0)