V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
shawndev
V2EX  ›  iDev

xcode 8 已经支持了 C, Cpp, ObjC 的类型推导。

  •  
  •   shawndev · 2017-10-22 13:28:22 +08:00 · 5018 次点击
    这是一个创建于 2375 天前的主题,其中的信息可能已经有所发展或是发生改变。
    不会贴图所以贴一个自己的微博详情。http://weibo.com/1832164643/Frxz3lJPb?ref=home

    现在支持

    __auto_type person = [Person new];
    __auto_type name = @"Jack";
    person.name = name;

    如果加上宏定义
    #define let __auto_type const
    #define var __auto_type

    就可以实现类似 swift 的写法。
    var person = [Person new];
    var name = @"Jack";
    person.name = name;


    这里有一篇类似小技巧介绍的文章 https://pspdfkit.com/blog/2017/even-swiftier-objective-c/
    7 条回复    2017-10-23 12:48:28 +08:00
    yingtl
        1
    yingtl  
       2017-10-22 17:33:45 +08:00
    这是 clang 的工作的么?
    还有为什么 javascript 要拼命加类型
    这里又要想法设法弄类型推导
    cljnnn
        2
    cljnnn  
       2017-10-22 21:24:50 +08:00
    @yingtl 类型对大型系统比较重要,所以 javascript 想要加上类型。
    类型推导并不是放弃类型,而是让类型声明更简单。
    C++ 11 以前, 你得写 std::vector<std::string>::iterator i=vs.begin(); ,现在只用写 auto i=vs.begin(); 让生活更美满。
    当 i 变量确定类型后,你对 i 再进行这样的赋值 i=1;是不允许的。但是在无类型语言如 JavaScript 是允许的。
    cljnnn
        3
    cljnnn  
       2017-10-22 21:34:42 +08:00
    @cljnnn 自更正一下,JavaScript 也是类型语言,解释型弱类型语言。
    araraloren
        4
    araraloren  
       2017-10-23 08:27:55 +08:00
    这是又一次改变世界? (滑稽
    araraloren
        5
    araraloren  
       2017-10-23 08:30:41 +08:00
    @cljnnn 要类型说来还是为了性能,类型推导只是好吃的语法糖
    CoCoMcRee
        6
    CoCoMcRee  
       2017-10-23 09:14:35 +08:00
    我还特地去看了一眼我的 Xcode 版本...现在是用 9 了啊
    shawndev
        7
    shawndev  
    OP
       2017-10-23 12:48:28 +08:00
    @CoCoMcRee 没有看 changelog 的习惯,所以刚注意到这个特性。如果已经知道了可以忽略,很少在代码里见到别人这么写所以分享一下。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1236 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:27 · PVG 07:27 · LAX 16:27 · JFK 19:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.