Skip to content

Commit d452b0e

Browse files
committed
Merge branch 'master' of github.com:apple/swift-corelibs-foundation
2 parents 208f26c + 12f9dd2 commit d452b0e

28 files changed

+684
-537
lines changed

Foundation/Data.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
270270
///
271271
/// - parameter reference: The instance of `NSData` that you wish to wrap. This instance will be copied by `struct Data`.
272272
public init(referencing reference: NSData) {
273+
// NOTE: don't fix this warning on Darwin -- linux will complain
273274
_wrapped = _SwiftNSData(immutableObject: reference.copy() as! AnyObject)
274275
}
275276

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

10-
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-
}
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
2320
}
24-
25-
private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry>()
21+
}
22+
23+
open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
24+
private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry<KeyType, ObjectType>>()
2625
private let _lock = NSLock()
2726
private var _totalCost = 0
28-
private var _byCost: NSCacheEntry?
27+
private var _byCost: NSCacheEntry<KeyType, ObjectType>?
2928

3029
open var name: String = ""
3130
open var totalCostLimit: Int = -1 // limits are imprecise/not strict
3231
open var countLimit: Int = -1 // limits are imprecise/not strict
3332
open var evictsObjectsWithDiscardedContent: Bool = false
3433

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

3936
open weak var delegate: NSCacheDelegate?
4037

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

4441
let keyRef = unsafeBitCast(key, to: UnsafeRawPointer.self)
4542

@@ -52,11 +49,11 @@ open class Cache: NSObject {
5249
return object
5350
}
5451

55-
open func setObject(_ obj: AnyObject, forKey key: AnyObject) {
52+
open func setObject(_ obj: ObjectType, forKey key: KeyType) {
5653
setObject(obj, forKey: key, cost: 0)
5754
}
5855

59-
private func remove(_ entry: NSCacheEntry) {
56+
private func remove(_ entry: NSCacheEntry<KeyType, ObjectType>) {
6057
let oldPrev = entry.prevByCost
6158
let oldNext = entry.nextByCost
6259
oldPrev?.nextByCost = oldNext
@@ -66,7 +63,7 @@ open class Cache: NSObject {
6663
}
6764
}
6865

69-
private func insert(_ entry: NSCacheEntry) {
66+
private func insert(_ entry: NSCacheEntry<KeyType, ObjectType>) {
7067
if _byCost == nil {
7168
_byCost = entry
7269
} else {
@@ -83,7 +80,7 @@ open class Cache: NSObject {
8380
}
8481
}
8582

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

8986
_lock.lock()
@@ -111,7 +108,7 @@ open class Cache: NSObject {
111108
}
112109
_lock.unlock()
113110

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

116113
if purgeAmount > 0 {
117114
_lock.lock()
@@ -146,7 +143,7 @@ open class Cache: NSObject {
146143

147144
if let del = delegate {
148145
for entry in toRemove {
149-
del.cache(self, willEvictObject: entry.value)
146+
del.cache(unsafeBitCast(self, to:NSCache<AnyObject, AnyObject>.self), willEvictObject: entry.value)
150147
}
151148
}
152149

@@ -177,12 +174,12 @@ open class Cache: NSObject {
177174
}
178175
}
179176

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

184181
extension NSCacheDelegate {
185-
func cache(_ cache: Cache, willEvictObject obj: AnyObject) {
182+
func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: AnyObject) {
186183
// Default implementation does nothing
187184
}
188185
}

Foundation/NSComparisonPredicate.swift

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

10-
1110
// 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.
12-
extension ComparisonPredicate {
11+
extension NSComparisonPredicate {
1312
public struct Options : OptionSet {
1413
public let rawValue : UInt
1514
public init(rawValue: UInt) { self.rawValue = rawValue }
@@ -21,15 +20,13 @@ extension ComparisonPredicate {
2120

2221
// Describes how the operator is modified: can be direct, ALL, or ANY
2322
public enum Modifier : UInt {
24-
2523
case direct // Do a direct comparison
2624
case all // ALL toMany.x = y
2725
case any // ANY toMany.x = y
2826
}
2927

3028
// Type basic set of operators defined. Most are obvious
3129
public enum Operator : UInt {
32-
3330
case lessThan // compare: returns NSOrderedAscending
3431
case lessThanOrEqualTo // compare: returns NSOrderedAscending || NSOrderedSame
3532
case greaterThan // compare: returns NSOrderedDescending
@@ -45,9 +42,9 @@ extension ComparisonPredicate {
4542
case between
4643
}
4744
}
48-
// 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.
4945

50-
open class ComparisonPredicate : Predicate {
46+
// 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 {
5148

5249
public init(leftExpression lhs: NSExpression, rightExpression rhs: NSExpression, modifier: Modifier, type: Operator, options: Options) { NSUnimplemented() }
5350
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 CompoundPredicate {
13+
extension NSCompoundPredicate {
1414
public enum LogicalType : UInt {
15-
1615
case not
1716
case and
1817
case or
1918
}
2019
}
2120

22-
open class CompoundPredicate : Predicate {
23-
24-
public init(type: LogicalType, subpredicates: [Predicate]) {
21+
open class NSCompoundPredicate : NSPredicate {
22+
public init(type: LogicalType, subpredicates: [NSPredicate]) {
2523
if type == .not && subpredicates.count == 0 {
2624
preconditionFailure("Unsupported predicate count of \(subpredicates.count) for \(type)")
2725
}
26+
2827
self.compoundPredicateType = type
2928
self.subpredicates = subpredicates
3029
super.init(value: false)
3130
}
31+
3232
public required init?(coder: NSCoder) { NSUnimplemented() }
3333

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

3737
/*** Convenience Methods ***/
38-
public convenience init(andPredicateWithSubpredicates subpredicates: [Predicate]) {
38+
public convenience init(andPredicateWithSubpredicates subpredicates: [NSPredicate]) {
3939
self.init(type: .and, subpredicates: subpredicates)
4040
}
41-
public convenience init(orPredicateWithSubpredicates subpredicates: [Predicate]) {
41+
public convenience init(orPredicateWithSubpredicates subpredicates: [NSPredicate]) {
4242
self.init(type: .or, subpredicates: subpredicates)
4343
}
44-
public convenience init(notPredicateWithSubpredicate predicate: Predicate) {
44+
public convenience init(notPredicateWithSubpredicate predicate: NSPredicate) {
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: AnyObject? {
149-
return userInfo[NSRecoveryAttempterErrorKey] as? AnyObject
148+
open var recoveryAttempter: Any? {
149+
return userInfo[NSRecoveryAttempterErrorKey]
150150
}
151151

152152
open var helpAnchor: String? {

Foundation/NSExpression.swift

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

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

55-
public /*not inherited*/ init(forConstantValue obj: AnyObject?) { NSUnimplemented() } // Expression that returns a constant value
56+
public /*not inherited*/ init(forConstantValue obj: Any?) { NSUnimplemented() } // Expression that returns a constant value
5657
open class func expressionForEvaluatedObject() -> NSExpression { NSUnimplemented() } // Expression that returns the object being evaluated
5758
public /*not inherited*/ init(forVariable string: String) { NSUnimplemented() } // Expression that pulls a value from the variable bindings dictionary
5859
public /*not inherited*/ init(forKeyPath keyPath: String) { NSUnimplemented() } // Expression that invokes valueForKeyPath with keyPath
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.
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.
6061
// Predefined functions are:
6162
// name parameter array contents returns
6263
//-------------------------------------------------------------------------------------------------------------------------------------
@@ -98,40 +99,43 @@ open class NSExpression : NSObject, NSSecureCoding, NSCopying {
9899
// two NSExpression instances representing CLLocations NSNumber
99100
// length: an NSExpression instance representing a string NSNumber
100101

101-
public /*not inherited*/ init(forAggregate subexpressions: [AnyObject]) { NSUnimplemented() } // Expression that returns a collection containing the results of other expressions
102+
public /*not inherited*/ init(forAggregate subexpressions: [Any]) { NSUnimplemented() } // Expression that returns a collection containing the results of other expressions
102103
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
103104
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
104105
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
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.
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.
107108
open class func expressionForAnyKey() -> NSExpression { NSUnimplemented() }
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
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
110111

111112
public init(expressionType type: ExpressionType) { NSUnimplemented() }
112113

113114
// accessors for individual parameters - raise if not applicable
114115
open var expressionType: ExpressionType { NSUnimplemented() }
115-
open var constantValue: AnyObject { NSUnimplemented() }
116+
open var constantValue: Any { NSUnimplemented() }
116117
open var keyPath: String { NSUnimplemented() }
117118
open var function: String { NSUnimplemented() }
118119
open var variable: String { NSUnimplemented() }
119120
/*@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)
120121
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
121122

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

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

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

132133
// 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
133-
open func expressionValueWithObject(_ object: AnyObject?, context: NSMutableDictionary?) -> AnyObject { NSUnimplemented() }
134+
open func expressionValue(with object: Any?, context: NSMutableDictionary?) -> Any? { NSUnimplemented() }
134135

135136
open func allowEvaluation() { NSUnimplemented() } // Force an expression which was securely decoded to allow evaluation
136137
}
137138

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

0 commit comments

Comments
 (0)