Creating NSPredicate dynamically by setting the key programmatically

后端 未结 2 1309
不知归路
不知归路 2021-02-06 05:28

Why does the former of following snippets work while not the latter ?

Snippet 1

NSPredicate *predicate = [NSPredicate predicateWithForma         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 05:55

    I got the following error even though my NSPredicate was formatted correctly.

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Insufficient arguments for conversion characters specified in format string.' site:stackoverflow.com
    

    Like a fool I forgot to pass a second argument to the predicate format (because there were two %@). I.e. NSPredicate(format:predicateFormat,argumentArray:[Date()]) has only one element in the array when it needs to be two: [Date(), Date()]

提交回复
热议问题