You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-22Lines changed: 25 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,9 @@ This should open a Finder window with the important files needed for PrediKit lo
114
114
The downside to this is that you can not update PrediKit easily. You would need to repeat these steps each time you wanna grab the latest and greatest! 😱
115
115
116
116
#Usage
117
+
118
+
***PSA: IF YOU HATE STRINGLY TYPED APIs LIKE I DO, THEN CHECK OUT THE SECTION ON SWIFT 3's #keyPath() AT THE BOTTOM OF THE README!!!***
119
+
117
120
PrediKit tries to make `NSPredicate` creation easy. **Heavily** inspired by [SnapKit's](https://github.com/SnapKit/SnapKit) API, the API for PrediKit is extremely similar for people who love it as much as I do. Check it out. This example creates a predicate used to fetch a `ManagedObject` from `CoreData`:
118
121
119
122
```swift
@@ -211,32 +214,32 @@ let predicate = NSPredicate(ManagedLegend.self) { includeIf in
211
214
}
212
215
```
213
216
214
-
#Selector Extension Pattern
215
-
Personally, I love using a variation of the [Selector Extension Pattern](https://medium.com/swift-programming/swift-selector-syntax-sugar-81c8a8b10df3#.bypt7blba)when using PrediKit. It allows you to avoid misspelling your property names when using the API. It also allows you to rename your selector properties at will. By renaming, every instance of that selector used by PrediKit should give you a compiler error so you don't miss a beat and can feel safe knowing you haven't missed any property names in a name change refactor. By creating a Selector extension like so:
217
+
##keyPath() + PrediKit = 💖
218
+
PrediKit becomes MUCH more expressive and safer when using Swift 3's #keyPath syntax. I don't know about you but I HATE stringly typed APIs. The best part of #keyPath is that you get autocompletion of your properties and a way to get sub properties without using PrediKit's `.member` functions:
216
219
217
220
```swift
218
-
importFoundation
221
+
let predicate =NSPredicate(ManagedLegend.self) { includeIf in
Personally, I love using a variation of the [Selector Extension Pattern](https://medium.com/swift-programming/swift-selector-syntax-sugar-81c8a8b10df3#.bypt7blba) when using PrediKit. It allows you to avoid misspelling your property names when using the API. It also allows you to rename your keypath properties at will. By renaming, every instance of that keyPath used by PrediKit should give you a compiler error so you don't miss a beat and can feel safe knowing you haven't missed any property names in a name change refactor. By creating a String extension like so:
233
232
234
-
staticlet title =Selector(.title)
235
-
staticlet birthdate =Selector(.birthdate)
236
-
staticlet age =Selector(.age)
237
-
staticlet friends =Selector(.friends)
238
-
staticlet isAwesome =Selector(.isAwesome)
239
-
staticlet isHungry =Selector(.isHungry)
233
+
```swift
234
+
importFoundation
235
+
236
+
extensionString {
237
+
staticlet title =#keyPath(Kraken.title)
238
+
staticlet birthdate =#keyPath(Kraken.birthdate)
239
+
staticlet age =#keyPath(Kraken.age)
240
+
staticlet friends =#keyPath(Kraken.friends)
241
+
staticlet isAwesome =#keyPath(Kraken.isAwesome)
242
+
staticlet isHungry =#keyPath(Kraken.isHungry)
240
243
}
241
244
```
242
245
@@ -245,7 +248,7 @@ PrediKit becomes a lot more expressive now:
245
248
```swift
246
249
//BEFORE
247
250
let predicate =NSPredicate(ManagedLegend.self) { includeIf in
0 commit comments