Swift报错:Missing argument for parameter 'coder' in call Insert 'coder: <#NSCoder#

933 阅读1分钟

Missing argument for parameter 'coder' in call Insert 'coder: <#NSCoder#>'

Value of optional type 'Model?' must be unwrapped to a value of type 'Model' Coalesce using '??' to provide a default when the optional value contains 'nil' Force-unwrap using '!' to abort execution if the optional value contains 'nil'

两个大大大警告

image.png

不要理会fix,简直越舔越乱

解决:

发现没有在自定义类Model里面 没有写 构造函数


复习一下:

构造函数

构造函数的作用

  • 分配空间 alloc
  • 设置初始值 init

如果一个类中定义了必选属性,必须通过构造函数为这些必选属性分配空间并且设置初始值

/// `重写`父类的构造函数
override init() {
    super.init()
}