I have a singleton class. In this class, i am holding an array of songs. This array should not change! in my app when i choose a song from my song list, the current song is inserted to another variable. This var is Song type ( the array is array of songs ). so when i am writing
_myDataMgr._currSong = [_myDataMgr.songArray objectAtIndex:index];
Every time i will change this currSong Variable the songArray will change because currSong is point to this array. so my question is how i can create a copy of this currSong? i know somthing about NSCopy but i dont know how to use it really. thank you all.
P.S: _myDataMgr is the singleton
You should make your class conform to the
NSCopyingprotocol.Then, implement the method
copyWithZone:When you need a copy of your instance, just call
copy. (I recommend to call this when you’re inserting the songs into the array in the singleton class.)