Is there no default(T) in Swift?

前端 未结 3 2235
感情败类
感情败类 2021-02-18 22:40

I\'m trying to port the Matrix example from Swift book to be generic.

Here\'s what I got so far:

struct Matrix {
    let rows: Int, columns: Int         


        
3条回答
  •  独厮守ぢ
    2021-02-18 23:19

    There isn't. Swift forces you to specify the default value, just like then you handle variables and fields. The only case where Swift has a concept of default value is for optional types, where it's nil (Optional.None).

提交回复
热议问题