osx - SWIFT: NSURL Always either Nil or unusable -
so in swift app, have function selects folder/drive - want use nsurl string. however- when print nsurl comes "optional(file:///(stuff goes here)" when make string comes nil. there i'm doing wrong? code below
@ibaction func selectdrive(sender: anyobject) { var openpanel = nsopenpanel() openpanel.allowsmultipleselection = false openpanel.canchoosedirectories = true openpanel.cancreatedirectories = true openpanel.canchoosefiles = false openpanel.beginwithcompletionhandler { (result) -> void in if result == nsfilehandlingpanelokbutton { println(openpanel.url) self.url = openpanel.url! var loc = string(contentsofurl: self.url) println("location @ \(loc)") // var str = string(system("diskutil info \(loc) | grep uuid:")) } } }
i have following declared @ top
var url = nsurl() @iboutlet weak var drivelabel: nstextfield!
any appreciated. spent couple of hours last night trying either console output come string, trying convert nsurl string, trying delete entire app...
nsopenpanel
returns url file://
scheme, can string representation path
property
@ibaction func selectdrive(sender: anyobject) { var openpanel = nsopenpanel() openpanel.allowsmultipleselection = false openpanel.canchoosedirectories = true openpanel.cancreatedirectories = true openpanel.canchoosefiles = false openpanel.beginwithcompletionhandler { (result) -> void in if result == nsfilehandlingpanelokbutton { self.url = openpanel.url! println("location @ \(self.url.path!)") } } }
Comments
Post a Comment