Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Alice is a class. Bob is a subclass of Alice. Alice has a method in which a variable named Carol is declared. In Bob's implementation, the aforementioned method is overridden. I want Bob to be able to access Carol. Considering I can safely modify Alice's files, what is the best way to approach this problem?

By the way, I am using the iOS 7 SDK.
 

JohnsonK

macrumors regular
Mar 6, 2014
142
0
I don't know if its just me but thing thing of alice and bob is confusing and by the end of your post I don't know who is who anymore.

But you mean to call super?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
Alice is a class.
Code:
// Code #1
@interface Alice : NSObject

@end
Bob is a subclass of Alice.
Code:
// Code #2
@interface Bob : Alice

@end

Alice has a method in which a variable named Carol is declared.
Scratch code #1. Replace with:
Code:
// Code #3
@interface Alice : NSObject

-(void) aMethod;

@end

@implementation Alice

-(void) aMethod
{
   // declare Carol here
}

@end


In Bob's implementation, the aforementioned method is overridden. I want Bob to be able to access Carol.
Code:
// Code #4
@implementation Bob

-(void) aMethod
{
   // access Carol here
}

@end

Considering I can safely modify Alice's files, what is the best way to approach this problem?
It's impossible to say from your description alone.

This is because in code #3, where Carol is declared inside aMethod, there are several different ways of "declaring Carol". In some of them, it's not possible at all to declare Carol in a way that makes it accessible in Bob, except by changing the lifetime of Carol. In others, the lifetime of Carol is fine, but the scope would need to changed to make Carol accessible to Bob. So it depends entirely on exactly what the actual code is that "declares Carol". Since you didn't post code, no one knows the answer.

If you had posted actual example code for Alice, as in code #3, with actual syntactically correct code for the body of aMethod, it would be simple to answer the question. Because then we could see the actual code in question.

As it now stands, I have to post code I wrote using your description, which may or may not accurately reflect what you think the description says. Furthermore, I have no clear idea what your intent is for declaring Carol. Carol could be an automatic variable, it could be a local static variable, it could be an extern variable, it could even be an instance variable. Those are four distinct possibilities, and each one has a different solution.

When you post actual code, we can see what you're talking about.

When you don't, we have to guess what the code is, and hope your description is complete and accurate. When the description is incomplete or inaccurate, the question is unanswerable until you either provide code that's complete and accurate, or someone else provides code that you affirm is accurate.

Finally, none of the code I wrote was difficult, so I don't see why you're incapable of providing it.
 
Last edited:

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Code:
// Code #1
@interface Alice : NSObject

@end
Code:
// Code #2
@interface Bob : Alice

@end


Scratch code #1. Replace with:
Code:
// Code #3
@interface Alice : NSObject

-(void) aMethod;

@end

@implementation Alice

-(void) aMethod
{
   // declare Carol here
}

@end



Code:
// Code #4
@implementation Bob

-(void) aMethod
{
   // access Carol here
}

@end

You are correct.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.