4 ms·
UIColor *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
by seanalltogether 12y ago
UIColor *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"