EXC_BAD_ACCESS when building nspredicate

前端 未结 1 758
野性不改
野性不改 2020-11-29 10:25

I am calculating the number of months between a birthdate and today. With that number, I am building a predicate to fetch objects from core data. Although the number of mont

相关标签:
1条回答
  • 2020-11-29 10:34

    The issue is the placeholder, not with NSPredicate directly, but with initWithFormat: that is innerly called.

    %@ shouldn't be used with an int, use %d instead.

    So this line:

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"(alter_min_monat > %@)", months];
    

    Should be:

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"(alter_min_monat > %d)", months];
    

    Other linked information : String Programming Guide: String Format Specifiers

    0 讨论(0)
提交回复
热议问题