核心数据“使用基本数据类型的标量属性”复选框

时间:2021-07-24 13:27:27

When should I check "use scalar properties for primitive data types" during creating NSManagedObject objects?
What it will cost me (will my data base improve performance or be more lightweight)?

在创建NSManagedObject对象时,什么时候应该检查“为基本数据类型使用标量属性”?我将为此付出什么代价(我的数据库将提高性能还是更轻量级)?

2 个解决方案

#1


44  

Before iOS 5 and OSX 10.7 scalar properties can't be auto-generated and you had to add setter and getter implementations, which cause some penalty. Auto-generated properties are optimized. I'm not aware of any other penalties.

在ios5和osx10.7标量属性不能自动生成之前,必须添加setter和getter实现,这会导致一些惩罚。自动生成的属性进行了优化。我不知道还有其他处罚。

Scalar and non-scalar properties are represented by the same types in DB, so there will be no change in DB's size. 

标量属性和非标量属性在DB中由相同的类型表示,因此DB的大小没有变化。

You should choose when to use scalar depending on the way you're going to access these properties. For example, you will need to wrap scalar properties in cocoa object if you're going to add them to collection (NSArray, NSSet, NSDictionary).

您应该根据访问这些属性的方式选择何时使用标量。例如,如果要将标量属性添加到collection (NSArray、NSSet、NSDictionary),则需要将它们包装在cocoa对象中。

#2


24  

Core Data has support for many common data types like integers, floats, booleans, and so on. However, by default, the data model editor generates these attributes as NSNumber properties in the managed object subclasses. This often results in endless floatValue, boolValue, integerValue, or similar calls on these NSNumber objects in the application code.

Core Data支持许多常见的数据类型,如整数、浮点数、布尔值等等。但是,默认情况下,数据模型编辑器将这些属性作为NSNumber属性在托管对象子类中生成。这通常会导致在应用程序代码中对这些NSNumber对象进行无休止的floatValue、boolValue、integerValue或类似的调用。

But we can also just specify those properties with their correct scalar type, e.g. as int64_t, float_t, or BOOL, and it will work with Core Data. Xcode even has a little checkbox in the save dialogue of the NSManagedObject generator (“Use scalar properties for primitive data types”) which does this for you.

但是我们也可以用正确的标量类型来指定这些属性,例如int64_t、float_t或BOOL,它将与核心数据一起工作。Xcode甚至在NSManagedObject生成器的save对话框(“为基本数据类型使用标量属性”)中有一个小复选框,它可以为您实现这一点。

Source: objc.io - Data Models and Model Objects

来源:objc。io -数据模型和模型对象

#1


44  

Before iOS 5 and OSX 10.7 scalar properties can't be auto-generated and you had to add setter and getter implementations, which cause some penalty. Auto-generated properties are optimized. I'm not aware of any other penalties.

在ios5和osx10.7标量属性不能自动生成之前,必须添加setter和getter实现,这会导致一些惩罚。自动生成的属性进行了优化。我不知道还有其他处罚。

Scalar and non-scalar properties are represented by the same types in DB, so there will be no change in DB's size. 

标量属性和非标量属性在DB中由相同的类型表示,因此DB的大小没有变化。

You should choose when to use scalar depending on the way you're going to access these properties. For example, you will need to wrap scalar properties in cocoa object if you're going to add them to collection (NSArray, NSSet, NSDictionary).

您应该根据访问这些属性的方式选择何时使用标量。例如,如果要将标量属性添加到collection (NSArray、NSSet、NSDictionary),则需要将它们包装在cocoa对象中。

#2


24  

Core Data has support for many common data types like integers, floats, booleans, and so on. However, by default, the data model editor generates these attributes as NSNumber properties in the managed object subclasses. This often results in endless floatValue, boolValue, integerValue, or similar calls on these NSNumber objects in the application code.

Core Data支持许多常见的数据类型,如整数、浮点数、布尔值等等。但是,默认情况下,数据模型编辑器将这些属性作为NSNumber属性在托管对象子类中生成。这通常会导致在应用程序代码中对这些NSNumber对象进行无休止的floatValue、boolValue、integerValue或类似的调用。

But we can also just specify those properties with their correct scalar type, e.g. as int64_t, float_t, or BOOL, and it will work with Core Data. Xcode even has a little checkbox in the save dialogue of the NSManagedObject generator (“Use scalar properties for primitive data types”) which does this for you.

但是我们也可以用正确的标量类型来指定这些属性,例如int64_t、float_t或BOOL,它将与核心数据一起工作。Xcode甚至在NSManagedObject生成器的save对话框(“为基本数据类型使用标量属性”)中有一个小复选框,它可以为您实现这一点。

Source: objc.io - Data Models and Model Objects

来源:objc。io -数据模型和模型对象