4 ms·
What i don't really see in the docs is how to calls to objective-c methods are sorted out. For instance, if I have an objective-c class with a method -(voi
by seanalltogether 12y ago
What i don't really see in the docs is how to calls to objective-c methods are sorted out. For instance, if I have an objective-c class with a method
-(void)addNumber:(NSNumber*)num withString:(NSString*)str;
How is this called in swift? Is it
myobj.addNumber(42, withString:"Hello World")?
- rmrfrmrf 12y agoIn AppleScriptObjC, Objective-C methods are converted from -(void)addNumber:(NSNumber)num withString:(NSString)str; to addNumber_withString(num, str) Swift could be different, though.
- ulhas_sm 12y agoThe whole function name is addNumber:withString: so if it has to be something, it might be myobj.addNumberWithString(42, "Hello world")
- octernion 12y agomyobj.addNumber(42, withString:"Hello World") edit: I see you removed your equals - your guess is now correct :) for more details, see this link on apple's docs (may change) https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4 https://developer.apple.com/library/prerelease/ios/documenta...
- msie 12y agoThere is a section in the docs about it. Similar to what you propose. https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4 https://developer.apple.com/library/prerelease/ios/documenta...
- seanalltogether 12y agoUIColor *color = [UIColor colorWithRed:0.5 green:0.0 blue:0.5 alpha:1.0]; let color = UIColor(red: 0.5, green: 0.0, blue: 0.5, alpha: 1.0) Wow, this just brings up more questions, is the compiler removing the "colorWith" semantics or do you write your own translator?
- octernion 12y agoI suspect they wrote a new init function specifically for Swift (as an extension), but I could be wrong.
- zenojevski 12y agoThey have a concept of implicit/explicit "external parameter names".
- jakejake 12y agoThe docs definitely indicate that some magic is occurring but they don't say exactly how. Perhaps If the first parameter contains the word "With"? They do explicitly state that initializers will get "init" and "initWith" stripped off and whatever follows becomes the first parameter. The fact that "colorWithRed" is translated to "red" might indicate that it is looking for the keyword "With"