2
Xcode와 Swift를 통해 OSX에서 열린 파일 대화 상자를 표시하려고했습니다. 그런 다음 파일 이름을 TextField에 넣기를 원했습니다. NSOpenPanel.URL을 문자열로 변환하려면 어떻게해야합니까?
내가@IBOutlet weak var lblFileName: NSTextField!
@IBAction func FileOpen(sender: AnyObject) {
var f:NSOpenPanel = NSOpenPanel()
f.title = "open that file"
f.allowsMultipleSelection = false
f.canChooseDirectories = false
f.runModal()
var thefile = f.URLs[0].absoluteString
println(thefile)
//failed: lblFileName.stringValue = thefile
lblFileName.stringValue = "I want this to be the filename!"
}
에 println (thefile) 근무 시작, 그래서는 URL 변수 "thefile"을 변환 그냥 문제였다 문자열과 실패 행사할 수있는 모든 시도는하지 않았다.
나는 그것이 내가 여기에 답변을 게시 할 것이라고 생각 했으므로 작동하도록 만들었습니다.
var thefile : NSString = f.URLs [0] .absoluteString! –