Skip to content

Instantly share code, notes, and snippets.

@maicoder
Forked from lexrus/swift-interview-outline.md
Created December 28, 2016 07:04
Show Gist options
  • Save maicoder/540b9db2fd16b8325f541ef6c66ad956 to your computer and use it in GitHub Desktop.
Save maicoder/540b9db2fd16b8325f541ef6c66ad956 to your computer and use it in GitHub Desktop.
Swift interview outline
  • Array 是 value type,使用 structs 实现
  • 数据类型没有隐式转换
  • 对于 String,count() 的复杂度是 O(n),每一个 Character 都是 unicode scalars 的序列
  • raw values 和 associated values 的区别
  • 如果必要,对于实现了 _ObjectiveCBridgeable 的 value types 会被自动桥接成 reference types
  • 讲一下 unowned 和 weak 的区别
  • 改 struct 的属性的方法名前要加 mutating,但如果这个 struct 用 let 声明的,改不了。修正:网友指出用 nonmutating set 也可以改属性。
  • nil 和 .None 的区别
  • capture list in closure
  • 举一个 guard ... where 的例子
  • 盲打十遍 infix operator ^^ { associativity right precedence 155 }
  • raw type 必须遵从 Equatable,且可以从 Int、String、Character 自面转换
  • 实现方法会覆盖 protocol extension 的方法
  • guard else 块中可以使用的 exit path 有: return, break, throw, 以及有 @noreturn 属性的方法如 fatalError(), abort()
  • 讲一下什么时候用 class,什么时候用 struct,为什么
  • 解释一下 generics 和它们解决的问题
  • 举一些必须隐式解包 optional 的例子
  • 解包的方法有哪些?
    • 强制解包 forced unwrapping
    • 隐式赋值解包 implicitly unwrapped variable declaration
    • 可选绑定 optional binding - if let
    • 绑定 optional binding - guard
    • 可选链 optional chaining
    • 可选模式匹配 optional pattern matching
    • 非空联合 nil coalescing - a ?? b
  • 怎样用 typealias 实现 generic ptotocols
  • const int number = 0; 和 let number = 0 的区别
  • struct 里的 static 和 class 里的 static 有什么区别;static 在 class 里等于 class final
  • 不能用 extension 添加 stored property
  • closure 是 reference type,它的 capture list 在赋值时会被复制
  • UInt(bitPattern: -1)
  • circular reference 和 retain cycle
  • 怎样实现 recursive enumeration? indirect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment