Tuesday, 15 February 2011

ios - Swift Extension Not working -



ios - Swift Extension Not working -

i've added extension uicolor colors utilize throughout app. here's example:

extension uicolor { func applightgraycolor() -> uicolor { homecoming uicolor(red: 190.0/255.0, green: 190.0/255.0, blue: 190.0/255.0, alpha: 1.0) } func grayscalecolor(grayscale : cgfloat) -> uicolor { homecoming uicolor(red: grayscale/255.0, green: grayscale/255.0, blue: grayscale/255.0, alpha: 1.0) } }

however, when seek phone call it, way i've been able compile without errors this:

uinavigationbar.appearance().bartintcolor = uicolor.applightgraycolor(uicolor())()

here's autocomplete:

what doing wrong?

you have added instance method, want class method

extension uicolor { class func applightgraycolor() -> uicolor { homecoming uicolor(red: 190.0/255.0, green: 190.0/255.0, blue: 190.0/255.0, alpha: 1.0) } class func grayscalecolor(grayscale : cgfloat) -> uicolor { homecoming uicolor(red: grayscale/255.0, green: grayscale/255.0, blue: grayscale/255.0, alpha: 1.0) } }

ios swift xcode6 objective-c-category

No comments:

Post a Comment