swift-xattr是iOS/OSXSwift语言的可扩展文件属性封装器,可处理下列函数:setxattr,getxattr,listxattr,removexattr。
使用示例:
import Foundationvar errorOrNames = attributesNamesAtPath("/file.txt")if let names = errorOrNames.names { names.map { println($0) }}else { println(errorOrNames.error)}> com.apple.FinderInfo> com.apple.metadata:_kMDItemUserTagssetAttributeWithName("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> customvar errorOrData = dataForAttributeNamed("custom", atPath: "/file.txt")if let data = errorOrData.data { println(NSString(data: data, encoding: NSUTF8StringEncoding))}else { println(errorOrData.error)}> abcremoveAttributeNamed("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测试系统:Xcode6.3,iOS8.1.1,OSX10.10
评论