Pointers, primitives, and properties in Objective-C classes

I really need an explanation - I have a few questions, and now I'm all mixed up.

Here is a simple class interface:

#import <UIKit/UIKit.h>

@interface Car : NSObject{
    NSInteger carID;
    NSString *carName;
}

@property (nonatomic, assign) NSInteger carID;
@property (nonatomic, copy) NSString * carName;
@end
  • Why carIDnot declared as a pointer?
  • Why does he use "assign" to carIDinstead of "copy"?
  • Why even declare class members as pointers in the first place? (In my main program, my Car object will be used as a pointer.)
+3
source share
4 answers

NSInteger - typedef (int 32-, long 64-) - .

; "" ; , , .

: : Objective-C , ; , .

, ; , , - . , ( ( , )), ( ).

+5

carID . , , :

@property (nonatomic) NSInteger carID;

, "copy" - , [object copy], .

nonatomic, ( ). , .

+1

, !

, Objective-C int Pointer Int.

C

-int int.

-Pointer Int . , *. ?

Int , . ? , int. , ?

int Int?

0

, :

@property (nonatomic, copy) NSString * carName;

@property (nonatomic, retain) NSString * carName;

copy , , NSString . , ( ref).

, , , ( ). NSString , NSString. , . , .. (. , ..).

, !

0

Source: https://habr.com/ru/post/1712600/


All Articles