objective c - How to choose the attributes of a @property in a nutshell? -
this question has answer here:
how know attribute add @property
?
i got @property (strong)
, @property (weak)
, think : strong
if class "owns" referred-to instance ; weak
if reference object existence not managed our current class.
if property created dragging-and-dropping interface builder, there cryptic unretain_unsafe
or so. sounds complicated me, believe xcode knows does...
i kind of understand
retain
,assign
kind of deprecated...and better (compulsory) use
copy
nsstring
attributes...but if want have
@property
int
orenum
?shall choose
weak
attribute if@property
points singleton ?
you see : so many questions theses attributes !
i thought nice have short , clear explanation of these attributes members here :)
a few notes in no particular order
weak
has additional features of being nil-ed out when referred-to object deallocated, never left dangling pointer garbage- it not compulsory use
copy
semanticsnsstring
property, highly recommended. whilensstring
immutable, property might set mutable string subclass, if don't want changing out under you, should usecopy
- the rule of thumb scalar property types pretty simple: not reference counted, neither
strong
norweak
applies. canreadonly
orreadwrite
, depending on need.
Comments
Post a Comment