问题描述
我是 Objective-C
的新手,而我在整个非原子
时遇到了问题,强
,弱
等等。我想知道使用核心数据是否会出现任何问题
带 float
定义如下的值:
I'm new to Objective-C
and I'm having trouble with the whole nonatomic
, strong
, weak
, etc. I'm wondering if I will have any issues using Core Data
with float
values which are defined like so:
@property (nonatomic) float * rating;
@property (nonatomic) float * mRating;
我应该以不同方式声明吗?
Should I declare the differently?
推荐答案
是的,你应该声明它们没有星号:
Yes, you should declare them without asterisks:
@property (nonatomic) float rating;
@property (nonatomic) float mRating;
星号表示指针。所有Objective C类都用星号声明,因为实例是通过指针引用的。诸如 float
s, int
s等原语被定义为 values ,即没有星号。对于typedef-ed类型也是如此,例如 CGFloat
和 NSInteger
:这些类型的标量字段应该没有星号来定义。
Asterisks indicate pointers. All Objective C classes are declared with asterisks, because instances are referred to through pointers. Primitives such as float
s, int
s, etc. are defined as values, i.e. without asterisks. Same goes for typedef-ed types such as CGFloat
and NSInteger
: scalar fields of these types should be defined without an asterisk.
这篇关于在目标c中声明浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!