gpt4 book ai didi

iphone - 如何判断 Core Data 的 NSNumber 属性的类型

转载 作者:行者123 更新时间:2023-12-03 18:38:42 24 4
gpt4 key购买 nike

我有一个使用 Core Data 的 iOS 4 项目。当我设计核心数据模型时,属性有Integer 64Integer 32Integer 16Decimal double 浮点 bool

但是在生成的NSManagedObject子类中,它们都是NSNumber*。因此,当我使用它时,如何判断 NSNumberlongdoublefloat ,还是一个 BOOL

最佳答案

NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:myManagedObjectContext];
NSAttributeDescription *attribute = [[entity attributesByName] objectForKey:@"myAttribute"];
if ([attribute attributeType] == NSInteger32AttributeType) {
// We have an Integer32
// ...
}

检查 NSAttributeDescription.h header ,了解除 NSInteger32AttributeType 之外的其他有效属性类型。

关于iphone - 如何判断 Core Data 的 NSNumber 属性的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5745587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com