ios - as NSArray 和 as! NSArray 和 as NSArray! 有什么区别?
天蓬老师
天蓬老师 2017-04-18 09:39:26
0
1
419
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
小葫芦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!