ios - Confused about properties and ivars -
i realize there many property vs. ivar questions on here, after doing lot of research can't seem find clear answer.
i understand when declare property following, compiler automatically synthesizes backing ivar , 2 accessor methods you:
@property nsstring *mystring; what still confuses me is, mystring actual instance variable? reason inquire because can never access this:
nslog(@"value of mystring is: %@", mystring); you either have utilize backing ivar _mystring, or 1 of getter methods [self mystring] or self.mystring. i'm confused because utilize variable name plain , simple.
to top off, i've been told should not refer mystring property, , word property should used refer 2 accessor methods synthesized compiler when utilize @property directive.
would wrong "i have property called mystring" , , if wrong right way it?
any help clearing appreciated. i've been struggling solidifying thought of properties , ivars beingness different things day now.
here reply of questions -
is mystring actual instance variable? - no wrong "i have property called mystring" , , if wrong right way it? - no not wrong phone call it. so looks confuses naming conventions, if go through naming conventions behind properties -
when utilize @property syntax declare properties on object, described in “encapsulating data,” compiler automatically synthesizes relevant getter , setter methods (unless indicate otherwise). if need provide own accessor method implementations reason, it’s of import create sure utilize right method names property in order methods called through dot syntax, example.
unless specified otherwise, getter method should utilize same name property. property called firstname, accessor method should called firstname. exception rule boolean properties, getter method should start is. property called paused, example, getter method should called ispaused.
the setter method property should utilize form setpropertyname:. property called firstname, setter method should called setfirstname:; boolean property called paused, setter method should called setpaused:.
check developer website detailed description - https://developer.apple.com/library/ios/documentation/cocoa/conceptual/programmingwithobjectivec/conventions/conventions.html
ios objective-c xcode properties
No comments:
Post a Comment