Default values for primitive properties in Objective-C

pec*_*eco 0 properties objective-c ios

I have an NSObject class, which has some primitive properties:

MyClass.h

@interface MyClass: NSObject

@property (nonatomic, assign) BOOL boolProp;
@property (nonatomic, assign) NSInteger intProp;

@end
Run Code Online (Sandbox Code Playgroud)

MyClass.m

@implementation MyClass

// No init implemented

@end
Run Code Online (Sandbox Code Playgroud)

From what I experienced, when there is no init method, then the properties default to "reasonable" values (BOOL to NO, intProp to 0). Is this defined behaviour? If yes, is there any Apple documentation for this behaviour?

And*_*kha 5

至于Apple文档,请检查Object Initialization。它提到了你问题中提出的主题。例如

在分配期间对实例变量执行默认设置为零的初始化通常就足够了