我正在尝试设置取景器显示的彩色标签.我所知道的唯一功能是setResourceValue.但这需要本地化名称!
我可以想象我的母语和英语,但我不知道所有其他人.我不敢相信,这应该是这样的.
是转换函数,它采用像enum或int这样的标准参数并提供本地化的颜色名称?
我有一个运行的部分,但只有两种语言(德语和英语):
let colorNamesEN = [ "None", "Gray", "Green", "Purple", "Blue", "Yellow", "Red", "Orange" ]
let colorNamesDE = [ "", "Grau", "Grün", "Lila", "Blau", "Gelb", "Rot", "Orange" ]
public enum TagColors : Int8 {
case None = -1, Gray, Green, Purple, Blue, Yellow, Red, Orange, Max
}
//let theURL : NSURL = NSURL.fileURLWithPath("/Users/dirk/Documents/MyLOG.txt")
extension NSURL {
// e.g. theURL.setColors(0b01010101)
func tagColorValue(tagcolor : TagColors) -> UInt16 {
return 1 << UInt16(tagcolor.rawValue)
}
func addTagColor(tagcolor : TagColors) -> Bool { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码在文件头中写入一些数据(数据长度为 367 字节):
const char *attrName = [kAttributeForKey UTF8String];
const char *path = [filePath fileSystemRepresentation];
const uint8_t *myDataBytes = (const uint8_t*)[myData bytes];
int result = setxattr(path, attrName, myDataBytes, sizeof(myDataBytes), 0, 0);
Run Code Online (Sandbox Code Playgroud)
当我尝试阅读它时,结果有所不同:
const char *attrName = [kAttributeForKey UTF8String];
const char *path = [filePath fileSystemRepresentation];
int bufferLength = getxattr(path, attrName, NULL, 0, 0, 0);
char *buffer = malloc(bufferLength);
getxattr(path, attrName, buffer, bufferLength, 0, 0);
NSData *myData = [[NSData alloc] initWithBytes:buffer length:bufferLength];
free(buffer);
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何才能完成这项工作吗?提前致谢。