我对Xcode 6.1 GM有一个奇怪的问题.
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)
Run Code Online (Sandbox Code Playgroud)
错误是在行中让texFontAttributes ...
Cannot convert the expression's type 'Dictionary' to type 'DictionaryLiteralConvertible'
Run Code Online (Sandbox Code Playgroud)
这段代码完美地运行到Xcode 6.1 GM.
当我尝试将textFontAttributes声明为NSDictionary错误消息更改为:
Cannot convert the expression's type …Run Code Online (Sandbox Code Playgroud) 我在Swift 2.0中遇到了AutoLayout的奇怪问题
self.webView = WKWebView()
self.view.addSubview(self.webView!)
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(self.webView, forKey: "webView")
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: 0, metrics: nil, views: viewBindingsDict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[webView]|", options: 0, metrics: nil, views: viewBindingsDict))
Run Code Online (Sandbox Code Playgroud)
我收到错误:
'String' is not convertible to 'StringLiteralConvertible'
Run Code Online (Sandbox Code Playgroud)
为"H:| [webView] |" 和"V:| [webView] |"
我不知道我是否遗漏了什么
我创建了NSApplication子类:
class MyApplication: NSApplication {
override func sendEvent(theEvent: NSEvent) {
if theEvent.type == NSEventType.KeyUp && (theEvent.modifierFlags & .CommandKeyMask).rawValue != 0 {
self.keyWindow?.sendEvent(theEvent)
} else {
super.sendEvent(theEvent)
}
}
}
Run Code Online (Sandbox Code Playgroud)
之后,我将Info.plist中的"Principal class"更改为MyApplication,最后在Main.storyboard的Application Scene中,我也将Application更改为MyApplication.
当我运行应用程序时,我得到以下消息:
class MyApplication: NSApplication {
override func sendEvent(theEvent: NSEvent) {
if theEvent.type == NSEventType.KeyUp && (theEvent.modifierFlags & .CommandKeyMask).rawValue != 0 {
self.keyWindow?.sendEvent(theEvent)
} else {
super.sendEvent(theEvent)
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄这个吗?