“Invalid predicate: nil RHS” for second argument in NSPredicate format
This is my
print(searchTextField.text!) let predicate = NSPredicate(format: "student.schoolClass.id = %d AND (book.title CONTAINS[cd] %@ OR student.username CONTAINS[cd] %@)", currentSchoolClass.id, searchTextField.text!, searchTextField.text!)
The next thing I do is:
fetchedResultsController.fetchRequest.predicate = predicate print(fetchedResultsController.fetchRequest.predicate!) try! fetchedResultsController.performFetch() //here is the crash
The console output is:
j student.schoolClass.id == 1 AND (book.title CONTAINS[cd] nil OR student.username CONTAINS[cd] "j")
And crash info is:
CRASH: Invalid predicate: nil RHS
Isn’t it weird?
2 Solutions Collect From Internet About ““Invalid predicate: nil RHS” for second argument in NSPredicate format”
On all current iOS and OS X platforms, the C
int is a 32-bit integer,
and that is what the
%d format expects on the variable argument list.
If you pass a 64-bit integer then reading the next variable argument
will read the extra 4 zero bytes.
The following table shows which format is for which integer type:
Format C type Swift type ----------------------------------- %d int Int32 %ld long int Int %lld long long int Int64
and similarly for the unsigned types.
Alternatively, convert the integer to a
NSNumber object and use
%@ format, this works
for integers of all sizes. Example:
let value = 1234 let predicate = NSPredicate(format: "value = %@", value as NSNumber)
You’re inserting nil as there is nothing in searchTextField.
So that only it will shows as nil in predicate.
Check the value in the textfield.
Hope it helps..
- Check if an array contains all elements of another in Swift
- How to get indexpath in prepareForSegue
- “loaded nib but the view outlet was not set” exception
- How can I create a “hyperlink” with Swift?
- How to create Objective-C Protocol in new version of XCode Version 6.0.1 (6A317) for iOS
- “Copy this file to your authentication server” – Firebase Custom auth
- How to use Mailcore framework in my IOS project?
- SWIFT – Add image to alert view
- Saving image to Documents directory and retrieving for email attachment
- iOS: error in __connection_block_invoke_2: Connection interrupted
- set tableview cell corner radius swift 2.0
- Drop Shadow on UITextField text
- UINavigationBar background color not the exact UIColor I set it to
- iOS 7. Change page orientation only for one view controller
- How to set a timeout with AFNetworking