How do copy and mutableCopy apply to NSArray and NSMutableArray?

前端 未结 8 1819
时光取名叫无心
时光取名叫无心 2020-11-27 10:55

What is the difference between copy and mutableCopy when used on either an NSArray or an NSMutableArray?

This is

8条回答
  •  猫巷女王i
    2020-11-27 11:41

    -(id)copy always returns a immutable one & -(id)mutableCopy always returns a mutable object,that's it.
    

    You have to know the return type of these copying stuff and while declaring the new object which one will be assigned the return value must be of immutable or mutable one, otherwise compiler will show you error.

    The object which has been copied can not be modified using the new one,they are totally two different objects now.

提交回复
热议问题