Reputation: 335
Trying to load contents of a directory into tableview.
Using: NSFileManager and NSTableView.
Getting Error Message in the last function:
'[AnyObject]?' does not have a member named 'subscript'
Do I miss something regarding Optionals?
Code:
import Cocoa
let fileManager = NSFileManager.defaultManager()
let folderURL = NSURL.fileURLWithPath("/Applications/")
var error : NSError? = nil
let folderContents: [AnyObject]? = fileManager.contentsOfDirectoryAtURL(folderURL!, includingPropertiesForKeys:nil, options:NSDirectoryEnumerationOptions(), error:&error)
class tonik: NSObject, NSTableViewDataSource {
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
folderContents?.count
}
func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
folderContents[row]
}
}
Upvotes: 1
Views: 559
Reputation: 335
Now it compiles.
I created object in xib file and table view, used the tonik class as datasource for the tableview, now I am getting message:
2015-01-10 07:21:18.420 ac3[6016:143038] *** Illegal NSTableView data source (). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:
but both functions are implemented.
Upvotes: 0