Declaring floats in objective c

后端 未结 2 1562
谎友^
谎友^ 2021-01-04 10:52

I\'m new to Objective-C and I\'m having trouble with the whole nonatomic, strong, weak, etc. I\'m wondering if I will hav

相关标签:
2条回答
  • 2021-01-04 10:55

    You should definitely lose the *, unless you are meaning to create a pointer. Outside of that it looks great!

    0 讨论(0)
  • 2021-01-04 11:07

    Yes, you should declare them without asterisks:

    @property (nonatomic) float rating;
    @property (nonatomic) float mRating;
    

    Asterisks indicate pointers. All Objective C classes are declared with asterisks, because instances are referred to through pointers. Primitives such as floats, ints, 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.

    0 讨论(0)
提交回复
热议问题