开发者

how should I perform calculations/updates to an NSNumber attribute in my Core Data entity?

开发者 https://www.devze.com 2023-02-25 17:35 出处:网络
So I understand you need NSNumber to save integers in Core Data. My question is what is the best technique for accessing the integers here, performing maths, and then updating?

So I understand you need NSNumber to save integers in Core Data.

My question is what is the best technique for accessing the integers here, performing maths, and then updating?

For example should you basically always convert the NSNumber to an NSInteger straight away (using the NSNumber intValue method I would guess), d开发者_StackOverflow中文版o maths/calculations, and then at the last minute create a new NSNumber and save back to core data?


You are right, Greg. Since we get the values to be plotted from the array which is either NSArray or NSMutableArray, we cant store integer in NSArray, because int is not an object. Whereas, NSNumber is an object. and thats why we convert it to NSNumber and store it after doing the calculations.

Also, as Eric mentioned in one of his answers, For the plot data, you can provide any NSNumber instance. Core Plot supports NSDecimalNumber as well and will use higher-precision calculations when drawing the graph, although this comes at a performance cost.

0

精彩评论

暂无评论...
验证码 换一张
取 消