Skip to content

Commit 30eae71

Browse files
authored
Merge pull request #2272 from millenomi/nspredicate-freeze
Parity: NSPredicate and NSExpression
2 parents 5769b00 + 39a45c7 commit 30eae71

File tree

5 files changed

+133
-150
lines changed

5 files changed

+133
-150
lines changed

Foundation/NSComparisonPredicate.swift

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

10-
// 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 {
10+
// 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.
11+
@available(*, deprecated, message: "NSExpression and classes that rely on its functionality are unsupported in swift-corelibs-foundation: NSComparisonPredicate is unavailable.")
12+
open class NSComparisonPredicate : NSPredicate {
13+
14+
@available(*, unavailable, message: "NSComparisonPredicate is unsupported in swift-corelibs-foundation. Use a closure-based NSPredicate instead if possible.")
15+
public init(leftExpression lhs: NSExpression, rightExpression rhs: NSExpression, modifier: Modifier, type: Operator, options: Options) { NSUnsupported() }
16+
17+
@available(*, unavailable, message: "NSComparisonPredicate is unavailable.")
18+
open var predicateOperatorType: Operator { NSUnsupported() }
19+
20+
@available(*, unavailable, message: "NSComparisonPredicate is unavailable.")
21+
open var comparisonPredicateModifier: Modifier { NSUnsupported() }
22+
23+
@available(*, unavailable, message: "NSComparisonPredicate is unavailable.")
24+
open var leftExpression: NSExpression { NSUnsupported() }
25+
26+
@available(*, unavailable, message: "NSComparisonPredicate is unavailable.")
27+
open var rightExpression: NSExpression { NSUnsupported() }
28+
29+
@available(*, unavailable, message: "NSComparisonPredicate is unavailable.")
30+
open var options: Options { NSUnsupported() }
31+
1232
public struct Options : OptionSet {
1333
public let rawValue : UInt
1434
public init(rawValue: UInt) { self.rawValue = rawValue }
@@ -17,14 +37,14 @@ extension NSComparisonPredicate {
1737
public static let diacriticInsensitive = Options(rawValue : 0x2)
1838
public static let normalized = Options(rawValue : 0x4) /* Indicate that the strings to be compared have been preprocessed; this supersedes other options and is intended as a performance optimization option */
1939
}
20-
40+
2141
// Describes how the operator is modified: can be direct, ALL, or ANY
2242
public enum Modifier : UInt {
2343
case direct // Do a direct comparison
2444
case all // ALL toMany.x = y
2545
case any // ANY toMany.x = y
2646
}
27-
47+
2848
// Type basic set of operators defined. Most are obvious
2949
public enum Operator : UInt {
3050
case lessThan // compare: returns NSOrderedAscending
@@ -43,16 +63,3 @@ extension NSComparisonPredicate {
4363
}
4464
}
4565

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 {
48-
49-
public init(leftExpression lhs: NSExpression, rightExpression rhs: NSExpression, modifier: Modifier, type: Operator, options: Options) { NSUnimplemented() }
50-
public required init?(coder: NSCoder) { NSUnimplemented() }
51-
52-
open var predicateOperatorType: Operator { NSUnimplemented() }
53-
open var comparisonPredicateModifier: Modifier { NSUnimplemented() }
54-
open var leftExpression: NSExpression { NSUnimplemented() }
55-
open var rightExpression: NSExpression { NSUnimplemented() }
56-
open var options: Options { NSUnimplemented() }
57-
}
58-

Foundation/NSCompoundPredicate.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ open class NSCompoundPredicate : NSPredicate {
2828
self.subpredicates = subpredicates
2929
super.init(value: false)
3030
}
31-
32-
public required init?(coder: NSCoder) { NSUnimplemented() }
3331

3432
open var compoundPredicateType: LogicalType
3533
open var subpredicates: [NSPredicate]

Foundation/NSExpression.swift

Lines changed: 85 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,36 @@ extension NSExpression {
2828
}
2929
}
3030

31-
open class NSExpression : NSObject, NSSecureCoding, NSCopying {
32-
33-
public static var supportsSecureCoding: Bool {
34-
return true
35-
}
36-
37-
public required init?(coder aDecoder: NSCoder) {
38-
NSUnimplemented()
39-
}
40-
41-
open func encode(with aCoder: NSCoder) {
42-
NSUnimplemented()
43-
}
31+
@available(*, deprecated, message: "NSExpression is not available in swift-corelibs-foundation")
32+
open class NSExpression : NSObject, NSCopying {
4433

4534
open override func copy() -> Any {
4635
return copy(with: nil)
4736
}
4837

4938
open func copy(with zone: NSZone? = nil) -> Any {
50-
NSUnimplemented()
39+
NSUnsupported()
5140
}
52-
53-
public /*not inherited*/ init(format expressionFormat: String, argumentArray arguments: [Any]) { NSUnimplemented() }
54-
public /*not inherited*/ init(format expressionFormat: String, arguments argList: CVaListPointer) { NSUnimplemented() }
5541

56-
public /*not inherited*/ init(forConstantValue obj: Any?) { NSUnimplemented() } // Expression that returns a constant value
57-
open class func expressionForEvaluatedObject() -> NSExpression { NSUnimplemented() } // Expression that returns the object being evaluated
58-
public /*not inherited*/ init(forVariable string: String) { NSUnimplemented() } // Expression that pulls a value from the variable bindings dictionary
59-
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.
42+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
43+
public convenience init(format expressionFormat: String, argumentArray arguments: [Any]) { NSUnsupported() }
44+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
45+
public convenience init(format expressionFormat: String, arguments argList: CVaListPointer) { NSUnsupported() }
46+
47+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
48+
public convenience init(forConstantValue obj: Any?) { NSUnsupported() } // Expression that returns a constant value
49+
50+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
51+
open class func expressionForEvaluatedObject() -> NSExpression { NSUnsupported() } // Expression that returns the object being evaluated
52+
53+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
54+
public convenience init(forVariable string: String) { NSUnsupported() } // Expression that pulls a value from the variable bindings dictionary
55+
56+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
57+
public convenience init(forKeyPath keyPath: String) { NSUnsupported() } // Expression that invokes valueForKeyPath with keyPath
58+
59+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
60+
public convenience init(forFunction name: String, arguments parameters: [Any]) { NSUnsupported() } // 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.
6161
// Predefined functions are:
6262
// name parameter array contents returns
6363
//-------------------------------------------------------------------------------------------------------------------------------------
@@ -99,43 +99,77 @@ open class NSExpression : NSObject, NSSecureCoding, NSCopying {
9999
// two NSExpression instances representing CLLocations NSNumber
100100
// length: an NSExpression instance representing a string NSNumber
101101

102-
public /*not inherited*/ init(forAggregate subexpressions: [Any]) { NSUnimplemented() } // Expression that returns a collection containing the results of other expressions
103-
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
104-
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
105-
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.
108-
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
102+
103+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
104+
public convenience init(forAggregate subexpressions: [Any]) { NSUnsupported() } // Expression that returns a collection containing the results of other expressions
105+
106+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
107+
public convenience init(forUnionSet left: NSExpression, with right: NSExpression) { NSUnsupported() } // return an expression that will return the union of the collections expressed by left and right
108+
109+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
110+
public convenience init(forIntersectSet left: NSExpression, with right: NSExpression) { NSUnsupported() } // return an expression that will return the intersection of the collections expressed by left and right
111+
112+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
113+
public convenience init(forMinusSet left: NSExpression, with right: NSExpression) { NSUnsupported() } // return an expression that will return the disjunction of the collections expressed by left and right
114+
115+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
116+
public convenience init(forSubquery expression: NSExpression, usingIteratorVariable variable: String, predicate: Any) { NSUnsupported() } // 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
117+
118+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
119+
public convenience init(forFunction target: NSExpression, selectorName name: String, arguments parameters: [Any]?) { NSUnsupported() } // Expression that invokes the selector on target with parameters. Will throw at runtime if target does not implement selector or if parameters are wrong.
120+
121+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
122+
open class func expressionForAnyKey() -> NSExpression { NSUnsupported() }
123+
124+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
125+
public convenience init(block: @escaping (Any?, [Any], NSMutableDictionary?) -> Any, arguments: [NSExpression]?) { NSUnsupported() } // Expression that invokes the block with the parameters; note that block expressions are not encodable or representable as parseable strings.
126+
127+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
128+
public convenience init(forConditional predicate: Any, trueExpression: NSExpression, falseExpression: NSExpression) { NSUnsupported() } // Expression that will return the result of trueExpression or falseExpression depending on the value of predicate
111129

112-
public init(expressionType type: ExpressionType) { NSUnimplemented() }
130+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
131+
public init(expressionType type: ExpressionType) { NSUnsupported() }
113132

114133
// accessors for individual parameters - raise if not applicable
115-
open var expressionType: ExpressionType { NSUnimplemented() }
116-
open var constantValue: Any { NSUnimplemented() }
117-
open var keyPath: String { NSUnimplemented() }
118-
open var function: String { NSUnimplemented() }
119-
open var variable: String { NSUnimplemented() }
120-
/*@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)
121-
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
134+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
135+
open var expressionType: ExpressionType { NSUnsupported() }
136+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
137+
open var constantValue: Any { NSUnsupported() }
138+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
139+
open var keyPath: String { NSUnsupported() }
140+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
141+
open var function: String { NSUnsupported() }
142+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
143+
open var variable: String { NSUnsupported() }
144+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
145+
/*@NSCopying*/ open var operand: NSExpression { NSUnsupported() } // the object on which the selector will be invoked (the result of evaluating a key path or one of the defined functions)
146+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
147+
open var arguments: [NSExpression]? { NSUnsupported() } // array of expressions which will be passed as parameters during invocation of the selector on the operand of a function expression
122148

123-
open var collection: Any { NSUnimplemented() }
124-
/*@NSCopying*/ open var predicate: NSPredicate { NSUnimplemented() }
125-
/*@NSCopying*/ open var left: NSExpression { NSUnimplemented() } // expression which represents the left side of a set expression
126-
/*@NSCopying*/ open var right: NSExpression { NSUnimplemented() } // expression which represents the right side of a set expression
149+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
150+
open var collection: Any { NSUnsupported() }
151+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
152+
/*@NSCopying*/ open var predicate: NSPredicate { NSUnsupported() }
153+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
154+
/*@NSCopying*/ open var left: NSExpression { NSUnsupported() } // expression which represents the left side of a set expression
155+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
156+
/*@NSCopying*/ open var right: NSExpression { NSUnsupported() } // expression which represents the right side of a set expression
127157

128-
/*@NSCopying*/ open var `true`: NSExpression { NSUnimplemented() } // expression which will be evaluated if a conditional expression's predicate evaluates to true
129-
/*@NSCopying*/ open var `false`: NSExpression { NSUnimplemented() } // expression which will be evaluated if a conditional expression's predicate evaluates to false
158+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
159+
/*@NSCopying*/ open var `true`: NSExpression { NSUnsupported() } // expression which will be evaluated if a conditional expression's predicate evaluates to true
160+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
161+
/*@NSCopying*/ open var `false`: NSExpression { NSUnsupported() } // expression which will be evaluated if a conditional expression's predicate evaluates to false
130162

131-
open var expressionBlock: (Any?, [Any], NSMutableDictionary?) -> Any { NSUnimplemented() }
163+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
164+
open var expressionBlock: (Any?, [Any], NSMutableDictionary?) -> Any { NSUnsupported() }
132165

133166
// 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() }
167+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
168+
open func expressionValue(with object: Any?, context: NSMutableDictionary?) -> Any? { NSUnsupported() }
135169

136-
open func allowEvaluation() { NSUnimplemented() } // Force an expression which was securely decoded to allow evaluation
137-
}
170+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
171+
open func allowEvaluation() { NSUnsupported() } // Force an expression which was securely decoded to allow evaluation
138172

139-
extension NSExpression {
140-
public convenience init(format expressionFormat: String, _ args: CVarArg...) { NSUnimplemented() }
173+
@available(*, unavailable, message: "NSExpression is not available in swift-corelibs-foundation")
174+
public convenience init(format expressionFormat: String, _ args: CVarArg...) { NSUnsupported() }
141175
}

0 commit comments

Comments
 (0)