Skip to content

Commit d49307a

Browse files
committed
Streamlining, documentation
1 parent a5ad892 commit d49307a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CoreDataQueryInterface/EntityType.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public func entityNameForClass(aClass: AnyClass, inManagedObjectModel managedObj
4646
dispatch_sync(EntityCacheQueue) {
4747
entityName = EntityCache[className]
4848
if entityName == nil {
49-
entityName = managedObjectModel.entities.filter({ $0.managedObjectClassName == className }).first!.name!
50-
if entityName != nil {
51-
EntityCache[className] = entityName
52-
}
49+
entityName = managedObjectModel.entities.filter{ $0.managedObjectClassName == className }.first?.name
50+
EntityCache[className] = entityName
5351
}
5452
}
5553
return entityName

CoreDataQueryInterface/PredicateBuilder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import Foundation
2828
Helper class to build predicates.
2929

3030
Use this class to bypass CDQI's type safety in filter expressions, if needed.
31+
Any type which implements `CustomExpressionConvertible` or its subclass
32+
`TypedExpressionConvertible` can be used here. Types such as `Int`, `String`,
33+
`NSNumber` and so on can be used directly.
3134
*/
3235
public struct PredicateBuilder {
3336
private init() {}

CoreDataQueryInterface/PredicateComparable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,15 @@ import Foundation
1111
/**
1212
Types which implement this protocol can appear on the left-hand
1313
side of an expression that generates a filter predicate.
14+
15+
- note: Without this type, CDQI can hijack Swift's built-in boolean
16+
expressions. For instance, an expression such as `import CoreDataQueryInterface;
17+
if x == 3 && y == 4 { print('ok') }` might not even compile because
18+
the compiler believes `x == 3 && y == 4` is trying to build `NSPredicate`
19+
instead of `Bool`. `PredicateComparable` prevents this from happening.
20+
21+
For this reason, `PredicateComparable` should be used very sparingly. I recommend
22+
never adding it to your own types unless you really know what you are doing. **Never**
23+
add it to any built-in Swift type such as `Int`, `String`, etc.
1424
*/
1525
public protocol PredicateComparable {}

0 commit comments

Comments
 (0)