object in object's constructor?!?!

Discussion in 'iOS Programming' started by Cdub16, Mar 15, 2010.

  1. Cdub16 macrumors member

    Joined:
    May 30, 2008
    #1
    ok so i have an object. lets say its called TestObject.
    in TestObject's constructor, one of its attributes is another TestObject.

    so lets say i do this after i have already made the TestObject class, constructer, getter setter methods, ect.


    Code:
    TestObject *testObject1 = [[TestObject alloc]initWithTestObject:testObject2];
    TestObject *testObject2 = [[TestObject alloc]initWithTestObject:testObject1];
    
    it complies correctly but when i try to access testObject1.testObject, it comes back as null, is this because of how i am accessing the object?
     
  2. cmaier macrumors G3

    Joined:
    Jul 25, 2007
    Location:
    California
    #2
    Can you show us the constructor? It sounds like you are recursing?

     
  3. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #3
    Well obviously testObject1.testObject is null. When you pass it into the constructor of testObject1, it doesn't exist!

    You're not showing all of the code involved though because I can't see how the above code could possibly exist unless you've already declared testObject2 somewhere else.
     
  4. Cdub16 thread starter macrumors member

    Joined:
    May 30, 2008
    #4
    o crap wait i did my constructer in my class wrong.

    ^^ ya i see what your saying i quicky wrote that but i had it right in my program. i screwed up the constructed my bad
     

Share This Page