“Invalid predicate: nil RHS” for second argument in NSPredicate format

后端 未结 2 1127
南旧
南旧 2020-12-11 13:06

This is my NSPredicate:

print(searchTextField.text!)
let predicate = NSPredicate(format: \"student.schoolClass.id = %d AND (book.title CONTAINS[         


        
相关标签:
2条回答
  • 2020-12-11 13:55

    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..

    0 讨论(0)
  • 2020-12-11 14:06

    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 the %@ format, this works for integers of all sizes. Example:

    let value = 1234
    let predicate = NSPredicate(format: "value = %@", value as NSNumber)
    
    0 讨论(0)
提交回复
热议问题