Created
May 25, 2012 03:32
-
-
Save eliaskg/2785598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)initWithName { | |
if (self = [super initWithDifferentName]) { | |
// Bla.. | |
} | |
} |
siuying
commented
May 25, 2012
That what I thought too but this throws the following error:
Terminating app due to uncaught exception 'NoMethodError', reason: 'app_delegate.rb:11:
in `initWithFancyName': super: no superclass method `initWithFancyName' for
#<SubClass:0x8ba1aa0> (NoMethodError)
Here is the sample project: http://cl.ly/Gt1q
class MyClass < ObjCClass
def initWithName
initWithDifferentName()
# do something
self
end
end
this should work, if you didn’t redefined initWithDifferentName() in our subclass, super will be called,
if you override the initWithDifferentName() method you will need to call super
class MyClass < ObjCClass
def initWithName
initWithDifferentName()
# do something
self
end
def initWithDifferentName()
super
# do something else
end
end
I think I got it, it's even easier than I thought:
class SubClass < NSObject
def initWithName
init
# do something
self
end
end
Thank you :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment