2017-03-12 1 views
1

MacOSの属性は、
AppleはAPI財団> FileManagerの>をsetAttributes(_を持ってswift3 、ofItemAtPath path:String)throwファイルを設定して、迅速かつMacOSの使用が

ファイルの作成日時などを設定します。 > ofItem path:String)を処理できるのは<ですが、最初の部分は私に困惑しています。

APIは「true」を返すと言いますが、迅速な返品は無効です。 'creationDate'という名前の属性があります。アンダースコア '_'の意味は何ですか?
私は「属性」だと思うが、私は多くのバリエーションを試してみましたそして今、私は困惑していると私は必要とされるかわからない可変辞書

var myAttributesDictionary = [FileAttributeKey : Date]() 
myAttributesDictionary[FileAttributeKey.creationDate] = myDateObject 

let fm = FileManger() 
let xxx = fm.setAttributes(myAttributesDictionary:[FileAttributeKey : creationDate], ofItemAtPath myPath) 

です。私はコンパイルするsetAttributes行を得ることができません

答えて

0

私は質問を投稿する前に、答えを探していました。 質問を探しに行ったときに答えが見つかりました。

let mypath = "/path/to/file" 
let myDateObject = NSDate()  // NSDate() is todays date 

let attributes = [FileAttributeKey.creationDate: myDateObject] 

do { 
     try FileManager.default.setAttributes(attributes, ofItemAtPath: myPath) 
    } 
    catch 
    { 
     print(error) 
    } 
関連する問題