Question

Overview

  • I have a iOS project in which the view controller implementation which has become large and thought it would be better to break into categories based on the functionality
  • The outlets in the view controller implementation file are not available in the category's implementation file.

Note - I am using ARC (automatic reference counting)

Question

  1. I have an outlet to the textfield created in my view controller's implementation file. Now can I create another outlet to the same text field in my view controller category's implementation file ?
  2. Would it cause any memory not be released or any other memory issues (Both the outlets are going to be weak and non atomic) ?
  3. Is this acceptable from a design perspective or is there a better way to do it ?
  4. Can category's methods be accessed in view controller's implementation ? I can include the header file but I want to know if at runtime there would be any unpredictable behavior
Was it helpful?

Solution

If you need to access declared IBOutlet properties in the categories of your view controller class, why not declare them in the class header file so that they are available to your categories? The ability to declare properties and ivars in implementation files now is meant to hide messy details of your implementation, but not at the risk of making your code unmanageable. Your functional design seems sensible.

OTHER TIPS

  1. You can have as many outlets as you want, they are pointers that will allow you to modify the object trough them.

  2. If you are using arc and assuming you used the Interface Builder to create your text field then no, since you set them to weak it just means that these pointers wont count towards the retain count of the object, so the object will be kept alive as long as at least 1 strong pointer points to it. in this case the Interface builder's view is retaining it, when that view is deallocated so will the object be. Being non atomic means that its not tread safe but this doesn't matter for your purpose.

  3. It really depends on your program, since i cant picture it with your description i can only advice into trying to stick to the MVC model when developing on iOS. https://developer.apple.com/library/ios/#documentation/General/Conceptual/CocoaEncyclopedia/Model-View-Controller/Model-View-Controller.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top