Swiftui high code quality programming skills 01 use initialization injection instead of optional values

Knowledge fat2022-05-14 19:28:47

Series articles

  • 01 Use initialization injection instead of optional values
  • 02 Use filter/reduce/map Instead of for loop , More clear and intuitive
  • 03 Use multiline strings to reference
  • 04 Limit the number of parameters , Too many parameters , You can use custom types
  • 05 Use the higher-order functions provided by the standard library
  • 06 Purely static types avoid using classes , Use enumeration
  • 07 Avoid using NSObject
  • 08 Use before closing let

1. Use initialization injection instead of optional values

///
class Info {
var num: Int?
}
let info = Info()
info.num = 1
///
class Info {
let num: Int
init(num: Int) {
self.num = num
}
}
let info = Info(num: 1)

thank
Similar articles

2022-05-14