Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:44:47+00:00 2026-06-01T04:44:47+00:00

I haven’t seemed to run into a problem yet, but I’m trying to make

  • 0

I haven’t seemed to run into a problem yet, but I’m trying to make sure I’m using some best practices.

Say I have a UITableViewController with a data source of an NSArray of MyObject objects. So in my UITableViewController I declare my data source like:

@property (strong, nonatomic) NSArray *dataSource;

Then after I touch a cell I want to push a new view that shows a detail view of something, using that cell’s MyObject. So in the new UIViewController I have this:

@property (strong, nonatomic) MyObject *myObject;

Now in the UITableViewController when a cell is touched:

MyObject *myObject = [[self dataSource] objectForIndex:[indexPath row]];
NewView *view = [[NewView alloc] initWithMyObject:myObject];
// ... push onto nav controller, etc

Basically what I’m afraid of is my array is declared with strong, MyObject in the detailed view is declared with strong, and who knows maybe there is another view with the same MyObject declared with strong.

Bottom line: is this the proper way to pass an object in between views? I haven’t really used a weak reference yet in my apps and I feel like that isn’t right. Any help or links to help would be amazing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:44:48+00:00Added an answer on June 1, 2026 at 4:44 am

    I think that what you need to understand is how arc works.

    Basically whatever has a strong pointer pointing to it will be retained.

    This works by adding a reference counter in the object so when you do this:

    @property (strong, nonatomic) MyObject *myObject;
    

    you create a STRONG pointer for myObject, (not the object).

    but when you do this

    MyObject *myObject = [[self dataSource] objectForIndex:[indexPath row]];
    

    you make this pointer increase the reference counting on whatever you have in the specified index from that data source.

    The important part is that as long as the pointer keeps pointing to this object it will be kept alive.

    About your concern with the views.

    Views created in the interface builder have their elements declared internally with strong pointers. This is when you want to use a weak reference. When you add your own IBOutlet to an element in the view it is good practice to make it weak. If you think about the reason logically, it basically means that you dont care about this interface builder element since you only want it to survive until the viewcontroller is deallocated.

    When you usually encounter retain cycles is when an object has a child object, and this child object has a STRONG reference to its parent.

    this is:

    Object A creates object B with a strong pointer

    Object B points to object A with a strong pointer

    A will keep B alive and B will keep A alive.

    This page will explain to you some basic stuff about how to avoid this kind of stuff:

    http://cocoawithlove.com/2009/07/rules-to-avoid-retain-cycles.html

    Also about passing objects between views, it is very very simple.

    First get a pointer from View 1 to View 2 (can be strong or weak depending on who should be keeping view 2 alive, if its from the IB Builder it should be weak if its programatically it should be strong)

    Second, make a property in view 2 (@property (strong, nonatomic) MyObject *myObject;)

    now it is as simple as:

    Self.view1Pointer.myObject = self.myOtherObject;
    

    Understand here how both views are strongly pointing to this object so the object will be kept alive as long as 1 of the views hasnt been deallocated.

    You wont create a retain cycle, you simply have the reference counting from that object set to 2.

    Note: When a view is deallocated, all of its pointers are set to nil so any object being pointed by them will decrease in its reference count. IF it reaches 0 it is deallocated. (in the previous case myobject will be 1 because another view is still pointing to it).

    The only scenario where you will create a retain cycle is if you manage to make myObject point strongly to View2 as well. So now they are keeping each other alive. (but as explained before you can make myObject point to view2 weakly which wont create a retain cycle).

    You can learn more about arc here:

    http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haven't found a solution to this problem yet, have tried some things... I have
I haven't actually built an app yet, but I'm confused by documentation on bind-attr.
haven't done much jquery and ran into a problem. I'd like to bind hover
Haven't seen anything about it here but it seems to solve one of the
I haven't used the STL much before, but I started to on this huffman
I haven't used ARC yet other than to deal with it when it forces
I haven't found a straight answer to how to make an animation in a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I haven't found any documentation on this or seen this done before, but is
I haven't worked with SQL Reporting much, however I have been trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.