2

I was asked this question during a technical discussion and can't seem to find answer anywhere.

The problem:

If I wrote methods by extending a core class (Lets say NSArray) which didn't exists in iOS 5 but were introduced in iOS 6.

What would happen to my application in the app store when the user upgrades to iOS 6? Would it crash? Would it be refer to foundation class? Would the runtime point to my function and everything will continue to work same?

Eg.

iOS 5.0

PGMyArray : NSArray

- (NSString) info; // convert and concatenate each object of the array into a string.

Now in iOS 6.0, Apple introduced the method publicly as part NSArray

NSArray

- (NSString) info; // Does exactly same as my method

What would happen when user upgrades to iOS 6.0 and my application calls

PGMyArray *myArray = [[NSArray alloc] init];
[myArray info];

My intelligent guess is, it would still be calling to PGMyArray-> info (after looking up from virtual table). However, I wasn't told the right answer and its bothering me for weeks now.

Any explanation / help is appreciated.

Mehmet Emre Portakal
  • 1,774
  • 21
  • 37
Vebz
  • 177
  • 1
  • 1
  • 8

3 Answers3

2

As you know any subclass can override an existing method. Even here you will end up with calling your method. i.e. Overriding it.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
0

That's why you shouldn't call it "info". You should use a three letter prefix (two letter prefixes are reserved by Apple), like abcInfo.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
0

You are extending the NSArray class, it means that if you implement a info method, YOUR method will be called, because you are ovveriding the default info method.

It is the same when you implement some methods like the viewDidLoad method. You have to implement it like this:

- (void)viewDidLoad {
    [super viewDidLoad];

    // Your initialization
}

You have to call the super method because you are overriding it, meaning that the super class viewDidLoad method is not called anymore.

Marco Pace
  • 3,820
  • 19
  • 38