Ho strani problemi con Xcode 6.1 GM.Swift - Disegno di testo con drawInRect: withAttributes:
let text: NSString = "A"
let font = NSFont(name: "Helvetica Bold", size: 14.0)
let textRect: NSRect = NSMakeRect(5, 3, 125, 18)
let textStyle = NSMutableParagraphStyle.defaultParagraphStyle().mutableCopy() as NSMutableParagraphStyle
textStyle.alignment = NSTextAlignment.LeftTextAlignment
let textColor = NSColor(calibratedRed: 0.147, green: 0.222, blue: 0.162, alpha: 1.0)
let textFontAttributes = [
NSFontAttributeName: font,
NSForegroundColorAttributeName: textColor,
NSParagraphStyleAttributeName: textStyle
]
text.drawInRect(NSOffsetRect(textRect, 0, 1), withAttributes: textFontAttributes)
errore è in linea lascia texFontAttributes ...
Cannot convert the expression's type 'Dictionary' to type 'DictionaryLiteralConvertible'
Questo codice è funzionato perfettamente fino a quando Xcode 6.1 GM.
Quando sto cercato di dichiarare textFontAttributes come messaggio di errore NSDictionary viene modificato in:
Cannot convert the expression's type 'NSDictionary' to type 'NSString!'
non ho idea di come risolvere questo problema :(
Non so perché, ma 'drawAtPoint: withAttributes:', 'drawInRect: withAttributes:', 'drawWithRect: opzioni: attributi:', ' sizeWithAttributes: 'e' boundingRectWithSize: options: attributes: 'sono" Non disponibile in Swift " – JDS
@JDS Non è disponibile non in Swift ma Swift's * String * type. Puoi chiamare questi metodi su * NSString * come ha fatto l'OP. – Blaszard