Tags
ios
Asked 8 years ago
5 Oct 2016
Views 2035
iPhone-coder

iPhone-coder posted

difference between NsArray and NsMutableArray

trying some code with iOS development. basically known with php .in php mostly only array but here to differ term NsArray and NsMutableArray.

so what is difference between NsArray and NsMutableArray ?
Mahesh Radadiya

Mahesh Radadiya
answered Nov 30 '-1 00:00

Mutable means one can modify it .

NsMutableArray is Array which can modifiable as per need. means you can add , remove or replace object form array,so NsMutableArray have

func insert(Any, at: Int) - insert given object to given index. - in php you do direct change of value at particular index like $array[$index]=$value

removeObject(at:) - remove object form given index. its like unset in php
add(_:) - Inserts a given object at the end of the array.in php . it same as push()
removeLastObject() - Removes the object with the highest-valued index in the array , its like pop() function in php
replaceObject(at:with:) - Replaces the object at index with an object. - in php you can use direct assign $array[$index]=$obj
many other function are there for add remove or replace for mutable array.

NsArray is not mutable means you can not modify after once it initialize .so it dont have add(_:) or removeLastObject or replaceObject function are there. this class have all function which is used to get meta data or data

Hope it help
Post Answer