Sunday, 15 September 2013

objective c - NSString * Discards Qualifiers -



objective c - NSString * Discards Qualifiers -

why getting 'nsstring *' discards qualifiers on currenttextb on 3rd line "cfattributedstringsetatribute(currenttextb..."

cfattributedstringref currenttextb = cfattributedstringcreate(null, stringref, null); ctfontref font = ctfontcreatewithname((cfstringref)@"helvetica", 10.0f, nil); cfattributedstringsetattribute(currenttextb,cfrangemake(0, strlength-1),kctfontattributename,font);

the first argument cfattributedstringsetattribute() must mutable attributed string. example:

cfstringref stringref = cfstr("foo"); // create mutable attributed string cfstringref: cfmutableattributedstringref currenttextb = cfattributedstringcreatemutable(null, 0); cfattributedstringreplacestring(currenttextb, cfrangemake(0, 0), stringref); // set attribute: ctfontref font = ctfontcreatewithname(cfstr("helvetica"), 10.0f, null); cfattributedstringsetattribute(currenttextb, cfrangemake(0, cfattributedstringgetlength(currenttextb)), kctfontattributename,font);

alternatively, work foundation type nsmutableattributedstring "toll-free bridged" cfmutableattributedstringref , hence can used interchangeably:

nsstring *string = @"foo"; nsmutableattributedstring *currenttextb = [[nsmutableattributedstring alloc] initwithstring:string attributes:nil]; nsfont *font = [nsfont fontwithname:@"helvetica" size:10.0]; [currenttextb addattribute:nsfontattributename value:font range:nsmakerange(0, [string length])];

objective-c core-text

No comments:

Post a Comment