【问题标题】:List of Core Data attribute types?核心数据属性类型列表?
【发布时间】:2012-05-11 06:40:53
【问题描述】:

我搜索了 Core Data 属性类型,但没有成功。

当我打开我的实体和属性时,有几种类型:

  1. 整数
  2. 字符串
  3. 布尔值

等等

我很感兴趣是否有一些 Apple 页面解释了每个属性的使用类型。

例如,我需要一个属性类型,我将在其中保存大约 1000 个字符的字符串。对于这种类型的插入,我应该使用哪种属性类型?

感谢您的帮助

【问题讨论】:

    标签: iphone objective-c xcode core-data attributes


    【解决方案1】:

    NSAttributeDescriptionclass reference 常量部分给出:

    typedef enum {
    NSUndefinedAttributeType = 0,
    NSInteger16AttributeType = 100,
    NSInteger32AttributeType = 200,
    NSInteger64AttributeType = 300,
    NSDecimalAttributeType = 400,
    NSDoubleAttributeType = 500,
    NSFloatAttributeType = 600,
    NSStringAttributeType = 700,
    NSBooleanAttributeType = 800,
    NSDateAttributeType = 900,
    NSBinaryDataAttributeType = 1000,
    NSTransformableAttributeType = 1800,
    NSObjectIDAttributeType = 2000
    } NSAttributeType;
    

    【讨论】:

    • 你能告诉我有多少字符适合一位吗?现在我想我应该使用属性类型字符串来插入 1000 个字符的字符串。
    • @CroiOS 使用NSStringAttributeType 看起来是存储 1000 个字符的正确选择。对每个值大小的任何限制都可能取决于底层存储机制。
    • 你能告诉我1位能容纳多少个字符吗? (1 个字符?)
    • @CroiOS 不,唯一可能适合 1 位的是布尔值。使用 UTF-8 编码时,单个字符(通常)需要 1 到 3 个字节,使用 UTF-16 编码时需要 2 到 4 个字节。
    • 我怎样才能计算出哪种属性类型对应于哪种插入类型(来自上面的列表,大小以位为单位)?
    【解决方案2】:

    您可以找到列表here,具体描述在常量部分。

    Specifically, typedef enum {
    NSUndefinedAttributeType = 0,
    NSInteger16AttributeType = 100,
    NSInteger32AttributeType = 200,
    NSInteger64AttributeType = 300,
    NSDecimalAttributeType = 400,
    NSDoubleAttributeType = 500,
    NSFloatAttributeType = 600,
    NSStringAttributeType = 700,
    NSBooleanAttributeType = 800,
    NSDateAttributeType = 900,
    NSBinaryDataAttributeType = 1000,
    NSTransformableAttributeType = 1800,
    NSObjectIDAttributeType = 2000
    } NSAttributeType;
    

    这意味着您可以使用的类型是:

    未定义/瞬态、short、integer、long、float、double、NSDecimalNumber、NSString、Boolean、NSDate、NSData、值转换器和 id

    【讨论】:

    • 是否有任何链接可以解释有多少字符适合例如属性字符串?
    • @CroiOs - 它是无限的 - 请参阅 sqlite documentation
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多