更新时间:2023-11-29 10:25:46
现在有了,__auto_type.例如...
There is now, __auto_type. For example...
__auto_type test = @"Hello World";
...导致测试的类型为 NSString*.
...results in test having the type NSString*.
这是一篇不错的文章:
https://medium.com/@maicki/type-inference-with-auto-type-55a38ef56372
作者建议使用
#define let __auto_type const
#define var __auto_type
在您的应用程序中的某些共享标头中,以使使用更简洁.我个人对这种宏的用法有点警惕,但我已经这样做了一段时间,世界仍在转动……也许不太可能引起冲突的宏名称会更好.
in some shared header in your application to make the usage cleaner. I'm a bit wary of this kind of macro usage personally but I've been doing it for a while and the world is still turning... Maybe macro names less likely to cause a collision would be better.