Skip to content

Foundation API Conformance Update: Miscellaneous #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
NSInvalidArgument("range \(r) extends beyond bounds \(bounds)")
}

if opts.contains(.FirstEqual) && opts.contains(.LastEqual) {
NSInvalidArgument("both NSBinarySearching.FirstEqual and NSBinarySearching.LastEqual options cannot be specified")
if opts.contains(.firstEqual) && opts.contains(.lastEqual) {
NSInvalidArgument("both NSBinarySearching.firstEqual and NSBinarySearching.lastEqual options cannot be specified")
}

let searchForInsertionIndex = opts.contains(.InsertionIndex)
let searchForInsertionIndex = opts.contains(.insertionIndex)

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

// common processing
let firstEqual = opts.contains(.FirstEqual)
let lastEqual = opts.contains(.LastEqual)
let firstEqual = opts.contains(.firstEqual)
let lastEqual = opts.contains(.lastEqual)
let anyEqual = !(firstEqual || lastEqual)

var result = NSNotFound
Expand Down Expand Up @@ -627,9 +627,9 @@ public struct NSBinarySearchingOptions : OptionSet {
public let rawValue : UInt
public init(rawValue: UInt) { self.rawValue = rawValue }

public static let FirstEqual = NSBinarySearchingOptions(rawValue: 1 << 8)
public static let LastEqual = NSBinarySearchingOptions(rawValue: 1 << 9)
public static let InsertionIndex = NSBinarySearchingOptions(rawValue: 1 << 10)
public static let firstEqual = NSBinarySearchingOptions(rawValue: 1 << 8)
public static let lastEqual = NSBinarySearchingOptions(rawValue: 1 << 9)
public static let insertionIndex = NSBinarySearchingOptions(rawValue: 1 << 10)
}

open class NSMutableArray : NSArray {
Expand Down
57 changes: 27 additions & 30 deletions Foundation/NSCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,36 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//


open class Cache: NSObject {
private class NSCacheEntry {
var key: AnyObject
var value: AnyObject
var cost: Int
var prevByCost: NSCacheEntry?
var nextByCost: NSCacheEntry?
init(key: AnyObject, value: AnyObject, cost: Int) {
self.key = key
self.value = value
self.cost = cost
}
private class NSCacheEntry<KeyType : AnyObject, ObjectType : AnyObject> {
var key: KeyType
var value: ObjectType
var cost: Int
var prevByCost: NSCacheEntry?
var nextByCost: NSCacheEntry?
init(key: KeyType, value: ObjectType, cost: Int) {
self.key = key
self.value = value
self.cost = cost
}

private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry>()
}

open class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject {
private var _entries = Dictionary<UnsafeRawPointer, NSCacheEntry<KeyType, ObjectType>>()
private let _lock = NSLock()
private var _totalCost = 0
private var _byCost: NSCacheEntry?
private var _byCost: NSCacheEntry<KeyType, ObjectType>?

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

public override init() {

}
public override init() {}

open weak var delegate: NSCacheDelegate?

open func object(forKey key: AnyObject) -> AnyObject? {
var object: AnyObject?
open func object(forKey key: KeyType) -> ObjectType? {
var object: ObjectType?

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

Expand All @@ -52,11 +49,11 @@ open class Cache: NSObject {
return object
}

open func setObject(_ obj: AnyObject, forKey key: AnyObject) {
open func setObject(_ obj: ObjectType, forKey key: KeyType) {
setObject(obj, forKey: key, cost: 0)
}

private func remove(_ entry: NSCacheEntry) {
private func remove(_ entry: NSCacheEntry<KeyType, ObjectType>) {
let oldPrev = entry.prevByCost
let oldNext = entry.nextByCost
oldPrev?.nextByCost = oldNext
Expand All @@ -66,7 +63,7 @@ open class Cache: NSObject {
}
}

private func insert(_ entry: NSCacheEntry) {
private func insert(_ entry: NSCacheEntry<KeyType, ObjectType>) {
if _byCost == nil {
_byCost = entry
} else {
Expand All @@ -83,7 +80,7 @@ open class Cache: NSObject {
}
}

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

_lock.lock()
Expand Down Expand Up @@ -111,7 +108,7 @@ open class Cache: NSObject {
}
_lock.unlock()

var toRemove = [NSCacheEntry]()
var toRemove = [NSCacheEntry<KeyType, ObjectType>]()

if purgeAmount > 0 {
_lock.lock()
Expand Down Expand Up @@ -146,7 +143,7 @@ open class Cache: NSObject {

if let del = delegate {
for entry in toRemove {
del.cache(self, willEvictObject: entry.value)
del.cache(unsafeBitCast(self, to:NSCache<AnyObject, AnyObject>.self), willEvictObject: entry.value)
}
}

Expand Down Expand Up @@ -177,12 +174,12 @@ open class Cache: NSObject {
}
}

public protocol NSCacheDelegate : class {
func cache(_ cache: Cache, willEvictObject obj: AnyObject)
public protocol NSCacheDelegate : NSObjectProtocol {
func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: AnyObject)
}

extension NSCacheDelegate {
func cache(_ cache: Cache, willEvictObject obj: AnyObject) {
func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: AnyObject) {
// Default implementation does nothing
}
}
9 changes: 3 additions & 6 deletions Foundation/NSComparisonPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//


// 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.
extension ComparisonPredicate {
extension NSComparisonPredicate {
public struct Options : OptionSet {
public let rawValue : UInt
public init(rawValue: UInt) { self.rawValue = rawValue }
Expand All @@ -21,15 +20,13 @@ extension ComparisonPredicate {

// Describes how the operator is modified: can be direct, ALL, or ANY
public enum Modifier : UInt {

case direct // Do a direct comparison
case all // ALL toMany.x = y
case any // ANY toMany.x = y
}

// Type basic set of operators defined. Most are obvious
public enum Operator : UInt {

case lessThan // compare: returns NSOrderedAscending
case lessThanOrEqualTo // compare: returns NSOrderedAscending || NSOrderedSame
case greaterThan // compare: returns NSOrderedDescending
Expand All @@ -45,9 +42,9 @@ extension ComparisonPredicate {
case between
}
}
// 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.

open class ComparisonPredicate : Predicate {
// 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.
open class NSComparisonPredicate : NSPredicate {

public init(leftExpression lhs: NSExpression, rightExpression rhs: NSExpression, modifier: Modifier, type: Operator, options: Options) { NSUnimplemented() }
public required init?(coder: NSCoder) { NSUnimplemented() }
Expand Down
20 changes: 10 additions & 10 deletions Foundation/NSCompoundPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@

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

extension CompoundPredicate {
extension NSCompoundPredicate {
public enum LogicalType : UInt {

case not
case and
case or
}
}

open class CompoundPredicate : Predicate {

public init(type: LogicalType, subpredicates: [Predicate]) {
open class NSCompoundPredicate : NSPredicate {
public init(type: LogicalType, subpredicates: [NSPredicate]) {
if type == .not && subpredicates.count == 0 {
preconditionFailure("Unsupported predicate count of \(subpredicates.count) for \(type)")
}

self.compoundPredicateType = type
self.subpredicates = subpredicates
super.init(value: false)
}

public required init?(coder: NSCoder) { NSUnimplemented() }

public let compoundPredicateType: LogicalType
public let subpredicates: [Predicate]
open var compoundPredicateType: LogicalType
open var subpredicates: [NSPredicate]

/*** Convenience Methods ***/
public convenience init(andPredicateWithSubpredicates subpredicates: [Predicate]) {
public convenience init(andPredicateWithSubpredicates subpredicates: [NSPredicate]) {
self.init(type: .and, subpredicates: subpredicates)
}
public convenience init(orPredicateWithSubpredicates subpredicates: [Predicate]) {
public convenience init(orPredicateWithSubpredicates subpredicates: [NSPredicate]) {
self.init(type: .or, subpredicates: subpredicates)
}
public convenience init(notPredicateWithSubpredicate predicate: Predicate) {
public convenience init(notPredicateWithSubpredicate predicate: NSPredicate) {
self.init(type: .not, subpredicates: [predicate])
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
return userInfo[NSLocalizedRecoveryOptionsErrorKey] as? [String]
}

open var recoveryAttempter: AnyObject? {
return userInfo[NSRecoveryAttempterErrorKey] as? AnyObject
open var recoveryAttempter: Any? {
return userInfo[NSRecoveryAttempterErrorKey]
}

open var helpAnchor: String? {
Expand Down
30 changes: 17 additions & 13 deletions Foundation/NSExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ open class NSExpression : NSObject, NSSecureCoding, NSCopying {
NSUnimplemented()
}

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

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

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

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

// accessors for individual parameters - raise if not applicable
open var expressionType: ExpressionType { NSUnimplemented() }
open var constantValue: AnyObject { NSUnimplemented() }
open var constantValue: Any { NSUnimplemented() }
open var keyPath: String { NSUnimplemented() }
open var function: String { NSUnimplemented() }
open var variable: String { NSUnimplemented() }
/*@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)
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

open var collection: AnyObject { NSUnimplemented() }
/*@NSCopying*/ open var predicate: Predicate { NSUnimplemented() }
open var collection: Any { NSUnimplemented() }
/*@NSCopying*/ open var predicate: NSPredicate { NSUnimplemented() }
/*@NSCopying*/ open var left: NSExpression { NSUnimplemented() } // expression which represents the left side of a set expression
/*@NSCopying*/ open var right: NSExpression { NSUnimplemented() } // expression which represents the right side of a set expression

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

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

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

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

extension NSExpression {
public convenience init(format expressionFormat: String, _ args: CVarArg...) { NSUnimplemented() }
}
Loading