🐻一文鉴定是Swift的王者,还是青铜

9,749 阅读1分钟

希望看完此文后,你对自己Swift继续保持信心

Swift 内功劝退篇 : mp.weixin.qq.com/s/U95QmOOje…

要是谁能一口气读下来,可谓大成

本文内容源于Alamofire、GPUImage3源码阅读,发现一些陌生的知识点,紧紧是Swift指南中就有这么多不算熟悉的内容。吐槽下:相对于Alamofire来说,GPUImage3作者写的真的是很烂。

一、 协议 Protocol

  • ExpressibleByDictionaryLiteral
  • Sequence
  • Collection
  • CustomStringConvertible
  • Hashable Codable
  • Comparable
  • RangeReplaceableCollection

以上协议常见应用场景是什么,有什么作用?

二、@propertyWrapper

阅读以下代码,print 输出什么

	@propertyWrapper
	struct Wrapper<T> {
    	var wrappedValue: T

    	var projectedValue: Wrapper<T> { return self }

    	func foo() { print("Foo") }
	}
	struct HasWrapper {
    	@Wrapper var x = 0
    
    	func foo() {
    	    print(x) // `wrappedValue`
    	    print(_x) // wrapper type itself
    	    print($x) // `projectedValue`
    	}
	}

三、关键字

  • public open final
  • static class
  • mutating inout
  • infix operator
  • @dynamicMemberLookup
  • where
  • @dynamicCallable
  • @autoclosure
  • @escaping

以上关键字使用场景是什么?

四、高阶函数

  • Filter, Map, Reduce, flatmap, compactMap

有何异同?

五、其他

  • 柯里化 什么意思
  • POPOOP的区别
  • AnyAnyObject 区别
  • rethrowsthrows 有什么区别呢?
  • break return continue fallthough 在语句中的含义(switch、while、for)

六、思考

  • 泛型 T 与 Any有什么区别?该如何使用?

七、用Swift搭个服务器?

🐻搭建Swift服务器:Ubuntu16.04 + vapor + swift5.2.2 release

最后,欢迎各位神仙解答!

各位神仙解答直接丢在评论区,我整理后稍后更新答案!

加V备注:掘金;入群一起学习🐻