Skip to content

Commit a576188

Browse files
author
Sergey Minakov
committed
[NSPredicate] implemented missing cases of 'PredicateKind'. switched TODO with NSUnimplemented.
1 parent f95f908 commit a576188

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

Foundation/NSPredicate.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ open class NSPredicate : NSObject, NSSecureCoding, NSCopying {
1515
private enum PredicateKind {
1616
case boolean(Bool)
1717
case block((Any?, [String : Any]?) -> Bool)
18-
// TODO: case for init(format:argumentArray:)
19-
// TODO: case for init(fromMetadataQueryString:)
18+
case format(String)
19+
case metadataQuery(String)
2020
}
2121

2222
private let kind: PredicateKind
@@ -41,11 +41,17 @@ open class NSPredicate : NSObject, NSSecureCoding, NSCopying {
4141
preconditionFailure("Unkeyed coding is unsupported.")
4242
}
4343

44+
//TODO: store kind key for .boolean, .format, .metadataQuery
45+
4446
switch self.kind {
4547
case .boolean(let value):
4648
aCoder.encode(value, forKey: "NS.boolean.value")
4749
case .block:
4850
preconditionFailure("NSBlockPredicate cannot be encoded or decoded.")
51+
case .format:
52+
NSUnimplemented()
53+
case .metadataQuery:
54+
NSUnimplemented()
4955
}
5056
}
5157

@@ -59,6 +65,10 @@ open class NSPredicate : NSObject, NSSecureCoding, NSCopying {
5965
return NSPredicate(value: value)
6066
case .block(let block):
6167
return NSPredicate(block: block)
68+
case .format:
69+
NSUnimplemented()
70+
case .metadataQuery:
71+
NSUnimplemented()
6272
}
6373
}
6474

@@ -70,10 +80,12 @@ open class NSPredicate : NSObject, NSSecureCoding, NSCopying {
7080
switch (other.kind, self.kind) {
7181
case (.boolean(let otherBool), .boolean(let selfBool)):
7282
return otherBool == selfBool
73-
// TODO: case for init(format:argumentArray:)
74-
// TODO: case for init(fromMetadataQueryString:)
75-
// NSBlockPredicate returns false even for copy
83+
case (.format, .format):
84+
NSUnimplemented()
85+
case (.metadataQuery, .metadataQuery):
86+
NSUnimplemented()
7687
default:
88+
// NSBlockPredicate returns false even for copy
7789
return false
7890
}
7991
}
@@ -108,6 +120,10 @@ open class NSPredicate : NSObject, NSSecureCoding, NSCopying {
108120
// let address = unsafeBitCast(block, to: Int.self)
109121
// return String(format:"BLOCKPREDICATE(%2X)", address)
110122
return "BLOCKPREDICATE"
123+
case .format:
124+
NSUnimplemented()
125+
case .metadataQuery:
126+
NSUnimplemented()
111127
}
112128
}
113129

@@ -127,6 +143,10 @@ open class NSPredicate : NSObject, NSSecureCoding, NSCopying {
127143
return value
128144
case let .block(block):
129145
return block(object, bindings)
146+
case .format:
147+
NSUnimplemented()
148+
case .metadataQuery:
149+
NSUnimplemented()
130150
}
131151
} // single pass evaluation substituting variables from the bindings dictionary for any variable expressions encountered
132152

0 commit comments

Comments
 (0)