本章内容概览:Swift编程规范、资料推荐
上一节:【iOS】08_Swift自带协议、Codable、网络状态检查、动画、安全、工程、工具
下一节:【iOS】10_Combine
同系列文章请查看:快乐码元 - iOS篇
1.编程规范
多用静态特性。swift 在编译期间所做的优化比 OC 要多,这是由于他的静态派发、泛型特化、写时复制这些静态特性决定的。另外通过 final 和 private 这样的表示可将动态特性转化为静态方式,编译开启 WMO 可以自动推导出哪些动态派发可转化为静态派发。
如何避免崩溃?
- 字典:用结构体替代
- Any:可用泛型或关联关联类型替代
- as? :少用 AnyObject,多用泛型或不透明类型
- !:要少用
好的实践?
少用继承,多用 protocol
多用 extension 对自己代码进行管理
2.资料推荐
书单
- 《Thinking in SwiftUI》
- 《Swift 进阶》
- 《函数式Swift》
- 《深入解析Mac OS X & iOS操作系统》
- 《LLVM Techniques, Tips, and Best Practices Clang and Middle-End Libraries》
- 《Learn LLVM 12》
- 《Crafting Interpreters》
- 《TCP/IP Illustrated》
- 《松本行弘的程序世界》
- 《现代操作系统》
- 《深入理解计算机系统》
- 《程序员的自我修养》
- 《Head First 设计模式》
参考资料:
- A Swift Tour- Apple:https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html#//apple_ref/doc/uid/TP40014097-CH2-ID1
- 菜鸟教程:https://www.runoob.com/swift/swift-enumerations.html
- 在线网站:https://onlineswiftplayground.com/
- SwiftGG:https://swiftgg.gitbook.io/swift/huan-ying-shi-yong-swift
- 斯坦福yt教程:https://www.youtube.com/watch?v=bqu6BquVi2M
- Apple官方40mins教程:https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
Tips: Please indicate the source and original author when reprinting or quoting this article.