How to print a NSInteger value from an NSManagedObject using NSLog

前端 未结 5 1356
北恋
北恋 2021-01-12 06:15

When I try to print an integer value to the console that is retrieved from an NSManagedObject, it displays a 6 or 8 digit value (the object ID?). However, if I use the debug

5条回答
  •  梦谈多话
    2021-01-12 06:46

    Depending on how the application is built, NSInteger might be 32 bits, or it might be 64 bits. If it's a 64-bit value, you'll need to do

    NSLog(@"sequence = %qi", sequence) 
    

    so that it correctly treats sequence as a 64-bit value. Note, however, that this won't work for 32-bit applications; as far as I'm aware, there's no single format specifier that will work to print an NSInteger in both 32-bit and 64-bit worlds.

提交回复
热议问题