closures - ObjC block in swift -


can me rewrite code in swift

    [segmentedcontrol1 settitleformatter:^nsattributedstring *(hmsegmentedcontrol *segmentedcontrol, nsstring *title, nsuinteger index, bool selected) { nsattributedstring *attstring = [[nsattributedstring alloc] initwithstring:title attributes:@{nsforegroundcolorattributename : [uicolor bluecolor]}]; return attstring; }]; 

part of hmsegmentedcontrol class:

    @interface hmsegmentedcontrol : uicontrol .... @property (nonatomic, copy) hmtitleformatterblock titleformatter; .... @end  typedef nsattributedstring *(^hmtitleformatterblock)(hmsegmentedcontrol *segmentedcontrol, nsstring *title, nsuinteger index, bool selected); 

my code is:

segmentedcontrol1.titleformatter = {(segmentedcontrol: hmsegmentedcontrol, title: nsstring, index: int, selected: bool) -> nsattributedstring in          } 

i error: "‘(hmsegmentedcontrol, nsstring, int, bool)->nsattributedstring’ not convertible ‘hmtitleformatterblock'"

yo mix swift , objective-c.

let titleformatterblock: hmtitleformatterblock = {(control: anyobject!, title: string!, index: uint, selected: bool) -> nsattributedstring in             let attstring = nsattributedstring(string: title, attributes: [nsforegroundcolorattributename: uicolor.bluecolor()                 ])             return attstring;         } segmentedcontrol.titleformatter = titleformatterblock 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -