Are private variables in Objective-C strong?

So the search around Stack Overflow seems to be how to make private variables in Objective-C:

@interface ClassName()
{
@private
    NSArray* private;
}
@property (strong, nonatomic) NSArray* public;
@end

Now I'm embarrassed. A property is declared as (strong, nonatomic), but the private variable has nothing of the kind. So how does the arc know if it is strong or not?

+5
source share
3 answers

In the case of a property, ownership of the associated instance variable implies ownership of the property:

See http://clang.llvm.org/docs/AutomaticReferenceCounting.html :

, , , , , @synthesize. , ; .

, Objective-C :

, , __strong.

, LLVM 4.0 (Xcode 4.4) @synthesize , .

+8

__strong.

Apple ARC ( ):

__ strong -

:

ARC -

, ivar @synthesize. . , -, , , , ivar.

+11

@property ARC. , . , .

A way to make it private (and strong) is to declare it strong in the category inside the .m file.

// .h
// nothing

// .m
@interface ClassName()
@property (strong, nonatomic) NSArray* myStrongPrivateProperty;
@end

// that it
+3
source

All Articles