iOS 数组添加元素的正确姿势

2017-02-04  本文已影响2717人  小辉辉___

使用 addObjectsFromArray将数组添加到可变数组中是正确的方式


<__NSArrayM 0x1706461b0>(
<MMHResultFrame: 0x1039ea000>,
<MMHResultFrame: 0x104000000>,
<MMHResultFrame: 0x10408b400>,
<MMHResultFrame: 0x103838600>,
<MMHResultFrame: 0x104001800>,
<MMHResultFrame: 0x1040f2600>,
<MMHResultFrame: 0x10414fe00>,
<MMHResultFrame: 0x104191e00>,
<MMHResultFrame: 0x104103800>,
<MMHResultFrame: 0x10407dc00>
)

使用addObject将数组添加到可变数组中会出现如下打印信息,因为会添加一个新的数组而不是添加元素,会导致崩溃!

<__NSArrayM 0x170447560>(
<__NSArrayM 0x17084e880>(
<MMHResultFrame: 0x103827600>,
<MMHResultFrame: 0x103947000>,
<MMHResultFrame: 0x10394e200>,
<MMHResultFrame: 0x103a5d600>,
<MMHResultFrame: 0x103a8fe00>,
<MMHResultFrame: 0x1038f5400>,
<MMHResultFrame: 0x10397ac00>,
<MMHResultFrame: 0x103902200>,
<MMHResultFrame: 0x104149000>,
<MMHResultFrame: 0x10390d000>,
<MMHResultFrame: 0x103ab4600>
)

)

上一篇 下一篇

猜你喜欢

热点阅读