When is @property and @synthesize needed?

后端 未结 4 581
时光取名叫无心
时光取名叫无心 2021-01-03 16:38

When exactly do I have to add @property (nonatomic, retain) and @synthesize? Also, when is declaring IBOutlet someObject enough? How i

相关标签:
4条回答
  • 2021-01-03 17:20

    Highly recommended read: Using Properties in Objective-C Tutorial

    0 讨论(0)
  • 2021-01-03 17:20

    property is needed only when you need the access to the member variables through the objects of that particular class. If you want to change some label's text at run time, that too accessing the object of the View Controller, then only you will need to have property defined for it, else not.

    Outlet is just to make connection between an object from xib and a member from the class. If you want to give access to that member though object write property for it, else not.

    Have a look at this

    0 讨论(0)
  • 2021-01-03 17:35

    Its not needed if you dont want the variables or objects to be accessed outside the class by other objects.

    0 讨论(0)
  • 2021-01-03 17:41

    The pair (@property, @synthesize) will create the set/get methods used for accessing your ivars from other objects.

    In a usual view controller you don't need to define properties for your IBOutlets since they should normally only be accessed by the view controller they belong to.

    0 讨论(0)
提交回复
热议问题