Swift 无法调用非函数类型的值';任何物体&引用;敏捷的

Swift 无法调用非函数类型的值';任何物体&引用;敏捷的,swift,cocoa,Swift,Cocoa,我正在尝试修复此错误,但没有看到解决方案。 在其他代码中工作!没道理 Support Class scrolled string:在滚动的视图中打印字符串 class ScrolledString: NSView{ var text: NSString = ""; init(frame frameRect: NSRect, string:NSString){ self.text = string super.init(frame: frameRect) } required

我正在尝试修复此错误,但没有看到解决方案。 在其他代码中工作!没道理

Support Class scrolled string:在滚动的视图中打印字符串

class ScrolledString: NSView{
var text: NSString = "";

init(frame frameRect: NSRect, string:NSString){
    self.text = string
    super.init(frame: frameRect)
}

required init?(coder: NSCoder) {
    self.text = ""
    super.init(coder:coder)
}

override func drawRect(dirtyRect: NSRect) {
    let font = NSFont(name: "Helvetica", size: 40.0)
    let attrs : [String: AnyObject] = [
        NSFontAttributeName: font!,
        NSForegroundColorAttributeName: NSColor.whiteColor()
    ]
    text.drawInRect(self.frame, withAttributes: attrs)
}
而在mainView中,我尝试添加一个滚动视图

let scrollStringContainer = NSScrollView(frame: NSRect(x: myRect.width*4/9, y: 0, width: myRect.width*8/9, height: myRect.height))
let view = NSView()
view.addSubview(ScrolledString(frame: scrollStringContainer.frame, string: self.name))
scrollStringContainer.documentView(view)
最后一行返回错误“无法调用nun函数类型'AnyObject'的值”。我只是想给scrollView添加一个视图

无主(不安全)var文档视图:任何对象?

documentView
是类型为
AnyObject
的可选属性,因此不能像函数一样调用它。我不清楚您是否打算使用
contentView
,如:

scrollStringContainer.contentView.addSubview(view)

至少您必须使用指定的初始值设定项初始化物理视图。