Last active
December 14, 2015 03:59
-
-
Save jjaffeux/5024727 to your computer and use it in GitHub Desktop.
weird case with objc-keyword messages when defining singleton method
This file contains hidden or 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
class MyView < UIView | |
attr_accessor :state | |
end | |
class Test | |
def initialize(delegate) | |
delegate.controllerWithValue(1, someStringValue: nil) | |
end | |
end | |
class WrongTestDelegate | |
attr_accessor :someStringValue | |
def controllerWithValue(value, someStringValue: someStringValue) | |
myView = MyView.alloc.init | |
def myView.state | |
true | |
end | |
@someStringValue = someStringValue | |
end | |
end | |
class RightTestDelegate | |
attr_accessor :someStringValue | |
def controllerWithValue(value, someStringValue: someStringValue) | |
@someStringValue = someStringValue | |
end | |
end | |
class AppDelegate | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
# differences between wrong and right delegates | |
# are lines 14 to 17 | |
wrongDelegate = WrongTestDelegate.new | |
test = Test.new(wrongDelegate) | |
p wrongDelegate.someStringValue.nil? #false | |
p wrongDelegate #<WrongTestDelegate:0x763d9d0 @someStringValue={:someStringValue=>nil}> | |
rightDelegate = RightTestDelegate.new | |
test = Test.new(rightDelegate) | |
p rightDelegate.someStringValue.nil? #true | |
p rightDelegate ##<RightTestDelegate:0x7675590 @someStringValue=nil> | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment