swift-xattr文件属性处理功能扩展
swift-xattr 是 iOS/OSX Swift 语言的可扩展文件属性封装器,可处理下列函数:setxattr, getxattr, listxattr, removexattr。
使用示例:
import Foundation var errorOrNames = attributesNamesAtPath("/file.txt") if let names = errorOrNames.names { names.map { println($0) } } else { println(errorOrNames.error) } > com.apple.FinderInfo > com.apple.metadata:_kMDItemUserTags setAttributeWithName("custom", data: "abc".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, atPath: "/file.txt") errorOrNames = attributesNamesAtPath("/file.txt") if let names = errorOrNames.names { names.map { println($0) } } else { println(errorOrNames.error) } > com.apple.FinderInfo > com.apple.metadata:_kMDItemUserTags > custom var errorOrData = dataForAttributeNamed("custom", atPath: "/file.txt") if let data = errorOrData.data { println(NSString(data: data, encoding: NSUTF8StringEncoding)) } else { println(errorOrData.error) } > abc removeAttributeNamed("custom", atPath: "/file.txt") errorOrData = dataForAttributeNamed("custom", atPath: "/file.txt") if let data = errorOrData.data { println(NSString(data: data, encoding: NSUTF8StringEncoding)) } else { println(errorOrData.error) } > Attribute not found
测试系统:Xcode 6.3, iOS 8.1.1, OS X 10.10
评论