自动提示宏

这个宏可以在使用keyPath时自动提示属性字符串,防止输入出现错误。

1
2
3
4
// 自动替换宏
#define keyPath(objc, keyPath) @(((void)objc.keyPath,#keyPath))
NSLog(@"%@", [keyPath(self.layer, position) class]); // NSTaggedPointerString
NSLog(@"%@", keyPath(self.layer, position)); // position
  • c语言字符串转objc字符串
1
2
3
4
// c语言字符串转objc字符串 
char *ch = "abc";
NSLog(@"%@", [@(ch) class]);
NSString *str = @(ch); // @()直接包装成objc对象