美文网首页
iOS面试小结

iOS面试小结

作者: 零纪年 | 来源:发表于2015-07-06 10:40 被阅读184次

1. @property (copy) NSMutableArray *array; 这样写有什么问题吗?

因为用了copy, 内部会深拷贝一次, 指针实际指向的是NSArray, 所以如果调用removeObject和addObject方法的话, 会unRecognized selector 

-copy, as implemented by mutable Cocoa classes, alwaysreturns their immutable counterparts. Thus, when an NSMutableArray is sent -copy, it returns an NSArray containing the same objects.

Becausewordshas the memory qualifiercopy, this line:

NSMutableArray *mutWords = [[NSMutableArray alloc] initWithArray:fixedWords];

self.words = mutWords;

Expands out to:

NSMutableArray *mutWords = [[NSMutableArray alloc] initWithArray:fixedWords];

self.words = [mutWords copy];

Given that NSMutableArray is a subclass of NSArray, the compiler doesn't complain, and you now have a ticking time bomb on your hands because NSArray does not recognize it's mutable subclass' methods (because it cannot mutate it's contents).

相关文章

  • 【iOS】面试小结_20171030

    title: 【iOS】面试小结_20171030date: 2017-11-09 00:01tags: iOSb...

  • iOS面试题之二

    这篇文章用来尝试回答落影大佬的面试题,原文:iOS面试小结[https://juejin.cn/post/6954...

  • iOS面试小结

    1. @property (copy) NSMutableArray *array; 这样写有什么问题吗? 因为用...

  • iOS面试小结

    前言 面试是职场中必经的一个步骤,在短短的几十分钟内去考察一个人的各项能力与综合素质,判断候选人与团队和团队匹配程...

  • iOS实录16:GCD使用小结(二)

    iOS实录16:GCD使用小结(二) iOS实录16:GCD使用小结(二)

  • iOS精华面试题分享

    作为iOS小白,总免不了各种面试,特将自己近期的几道面试题小结一下。同时也将无意闲逛时发现一位超级全面的面试总结分...

  • iOS面试小结(一)

    结束上海将近4年的iOS开发,今年回到了我们美丽的不像样的!我的家乡----大连!准备为家乡的互联网行业带来一丝新...

  • iOS面试题小结

    通过自己的工作经验和面试经历小结了一份iOS面试题 分享出来 欢迎指正和补充! 如果你懒得看文字, 可以直接浏览前...

  • 阿里腾讯头条美团等iOS面试总结

    阿里iOS面试总结 头条iOS面试总结 腾讯iOS面试总结 百度iOS面试总结 美团iOS面试总结

  • iOS TabBar在页面跳转时的隐藏与显示

    iOS 隐藏tabBar小结

网友评论

      本文标题:iOS面试小结

      本文链接:https://www.haomeiwen.com/subject/vrpyqttx.html