Swift interview questions

Swift interview questions

I think the knowledge should be mastered, there is no practical significance.

  • The difference between class and struct
  • What are the ways in which code is reused (shared) without inheritance
  • What are the unique methods of Set?
  • To achieve a min function, return the two elements of the smaller elements
  • The role of map, filter, reduce
  • The difference between map and flatmap
  • What is copy on write
  • How to get the function name and line number of the current code
  • How to declare a protocol that can only be conform
  • Guard usage scenarios
  • Defer usage scenarios
  • The relationship and difference between String and NSString
  • How to get a String length
  • How to intercept a string of String
  • Usage and function of throws and rethrows
  • Try? And try! What does it mean
  • Role of associatedtype
  • When to use final
  • The difference between public and open
  • Declare an alias with only one parameter that does not return a value closure
  • Self usage scenarios
  • Role of dynamic
  • When to use @objc
  • Optional (optional) is achieved with what
  • How to customize index access
  • The role of?
  • Role of lazy
  • A type representation option that can be represented by several options (similar to UIViewAnimationOptions)
  • Role of inout
  • Error what to do if you want to be compatible with NSError
  • Which of the following codes are used in the syntax sugar [1, 2, 3].map{$0 * * 2}
  • What is a higher order function
  • How to solve the reference cycle
  • The following code will not collapse, say the reason var mutableArray = [1,2,3] for in (mutableArray) _ {mutableArray.removeLast}
  • How to add an extension to an element in a collection that is a string
  • What is the difference between keyword static and class when defining static methods


  • A Sequence index is not necessarily starting from 0?
  • What protocols are implemented in an array
  • How to customize pattern matching
  • Role of autoclosure
  • Compiler options whole module Optmization optimized what
  • What is the role of mutating in the following code struct Person {name: String {mutating get}} {return store}}
  • How to enable custom objects to support literal initialization
  • What is the difference between dynamic framework and static framework

Philosophical part

  • Why the array index will crash out of bounds, and the dictionary with subscript value when the key does not have a corresponding value, then the return is not broken nil.
  • A function of the parameter type as long as the number (Int, Float) can be, how to express.

Welcome to pay attention to my micro-blog: @ no story