tag:blogger.com,1999:blog-6864853053396532264.post4131547920727689228..comments2024-01-25T06:36:43.336-07:00Comments on Osmorphis: Copying pitfallsJEShttp://www.blogger.com/profile/05678402081101110580noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6864853053396532264.post-89426521088326972482011-03-11T07:39:28.826-07:002011-03-11T07:39:28.826-07:00gteat article.......i understand it now.gteat article.......i understand it now.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6864853053396532264.post-72501229445718994682009-03-20T17:46:00.000-06:002009-03-20T17:46:00.000-06:00JES, you are totally correct. I'm new to Objective...JES, you are totally correct. I'm new to Objective-C and I guess still didn't fully understand the difference between a shallow and deep copy. I was expecting a deep copy - this has cleared that up.<BR/><BR/>Thanks to you pointing that out, I fixed a bug in my program that's been annoying me for a few weeks now. I was using addObjectsFromArray and didn't realize I was getting a shallow copy when I was expecting a deep one. After adding copyWithZone and that crucial copyItems:YES everything is working as expected. I thank you for that!<BR/><BR/>I'm with you - not so sure why there are so many ways to get a shallow copy.Scotthttps://www.blogger.com/profile/07499382482255246608noreply@blogger.comtag:blogger.com,1999:blog-6864853053396532264.post-54262255658038534072009-03-19T22:28:00.000-06:002009-03-19T22:28:00.000-06:00I'm not sure if you're expecting a shallow or a de...I'm not sure if you're expecting a shallow or a deep copy. According to the docs, both addEntriesFromDictionary and addEntriesFromDictionary shallow copy the values. In other words, all it does is copy the pointers with a retain.<BR/><BR/>Here is the information quoted from the Apple reference docs:<BR/><BR/>Each value object from otherDictionary is sent a retain message before being added to the receiver. In contrast, each key object is copied (using copyWithZone:—keys must conform to the NSCopying protocol), and the copy is added to the receiver.<BR/><BR/>Similar text is for the NSArray. I don't know why the API has so many different ways to get a shallow copy.JEShttps://www.blogger.com/profile/05678402081101110580noreply@blogger.comtag:blogger.com,1999:blog-6864853053396532264.post-25093444205023390532009-03-19T20:13:00.000-06:002009-03-19T20:13:00.000-06:00Great write up. One question though:For your NSMut...Great write up. One question though:<BR/><BR/>For your NSMutableDictionary issues, why not use addEntriesFromDictionary? I do a similar thing where I need to add the contents of one mutable array to another (for what is essentially a copy). To accomplish this I init the second mutable array then use addObjectsFromArray. It seems NSMutableDictionary has a corresponding function called addEntriesFromDictionary.Scotthttps://www.blogger.com/profile/07499382482255246608noreply@blogger.com