Swift - Drawing text with drawInRect:withAttributes: -



Swift - Drawing text with drawInRect:withAttributes: -

i have unusual problem xcode 6.1 gm.

let text: nsstring = "a" allow font = nsfont(name: "helvetica bold", size: 14.0) allow textrect: nsrect = nsmakerect(5, 3, 125, 18) allow textstyle = nsmutableparagraphstyle.defaultparagraphstyle().mutablecopy() nsmutableparagraphstyle textstyle.alignment = nstextalignment.lefttextalignment allow textcolor = nscolor(calibratedred: 0.147, green: 0.222, blue: 0.162, alpha: 1.0) allow textfontattributes = [ nsfontattributename: font, nsforegroundcolorattributename: textcolor, nsparagraphstyleattributename: textstyle ] text.drawinrect(nsoffsetrect(textrect, 0, 1), withattributes: textfontattributes)

error in line allow texfontattributes...

cannot convert expression's type 'dictionary' type 'dictionaryliteralconvertible'

this code worked until xcode 6.1 gm.

when i'm tried declare textfontattributes nsdictionary error message changed to:

cannot convert expression's type 'nsdictionary' type 'nsstring!'

i have no thought how solve problem :(

the problem font optional because convenience contructors homecoming optional values, font needs unwrapped value in dictionary:

if allow actualfont = font { allow textfontattributes = [ nsfontattributename: actualfont, nsforegroundcolorattributename: textcolor, nsparagraphstyleattributename: textstyle ] text.drawinrect(nsoffsetrect(textrect, 0, 1), withattributes: textfontattributes) }

swift

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -