First of all, you must understand that the two exclamation marks as! and NSArray! represent different concepts. as! represents forced conversion, and NSArray! represents that this object must have a value and is not empty.
Bundle.main.loadNibNamed(nibName, owner: owner, options: options) The returned type is , [Any]?
This is the option type of Array, indicating that this value may be empty. That is nil.
So as! Array means to force the conversion of Array? into Array, so an alert will be reported because the compiler thinks that a nil value may appear and an error will occur. That is, the compiler believes that this type conversion will cause an error.
Using as Array! is equivalent to telling the compiler that the above returned value must not be empty, and this type conversion will definitely not cause problems. We have forced unpacking of nibs using!, and the function of as here is a type conversion function.
First of all, you must understand that the two exclamation marks as! and NSArray! represent different concepts. as! represents forced conversion, and NSArray! represents that this object must have a value and is not empty.
Bundle.main.loadNibNamed(nibName, owner: owner, options: options) The returned type is , [Any]?
This is the option type of Array, indicating that this value may be empty. That is nil.
So as! Array means to force the conversion of Array? into Array, so an alert will be reported because the compiler thinks that a nil value may appear and an error will occur. That is, the compiler believes that this type conversion will cause an error.
Using as Array! is equivalent to telling the compiler that the above returned value must not be empty, and this type conversion will definitely not cause problems. We have forced unpacking of nibs using!, and the function of as here is a type conversion function.