Assigning to self in Objective C?!
I'm watching the videos from Stanford's iPhone development class. You can get them for free off of iTunes. In the third lecture it shows an implementation of the init method on a Person class which is bizarre. First, it specifies the return type as "id", which is basically saying it returns an object. That's an appropriate type declaration (I thought these were optional anyway? Why are we specifying that?) for a method on NSObject, but for an init method on Person isn't it obvious that the return type is Person?
By far the most disturbing aspect, though, is this line:
self = super init;
Assigning to self inside of an instance method?! Isn't this a bit crazy? What happens if this changes the type of object? What if the next statement accessing an instance variable? If the object changes, we no longer have that instance variable. This seems to be pure insanity to me and I think most OO languages would not allow something so ridiculous.
By far the most disturbing aspect, though, is this line:
self = super init;
Assigning to self inside of an instance method?! Isn't this a bit crazy? What happens if this changes the type of object? What if the next statement accessing an instance variable? If the object changes, we no longer have that instance variable. This seems to be pure insanity to me and I think most OO languages would not allow something so ridiculous.
