nscopying

NSManagedObject as NSDictionary key?

In my app, I have a NSDictionary whose keys should be instances of a subclass of NSManagedObject. The problem, however, is that NSManagedObject does not implement the NSCopying protocol which means that no Core Data objects / instances of NSManagedObject can be used as dictionary keys even though the -[hash] method works fine for them....

Why doesn't UIView (or it's subclasses) adopt the NSCopying Protocol?

Can a Cocoahead please explain why UIView and it's sub classes don't adopt the NSCopying Protocol? I can see, philosophically, why UITouch would not be copy compliant, as it's a very temporal object. By UIView, and it's subclasses, especially UIButton, seem like they should be able to be copied. Certainly Apple has good reasons for do...

Enabling the NSCopying protocol in a class

I have a class that has been derived from NSObject. How can copy be enabled like [object copy]? This is for an iPhone application. ...

Copy & mutableCopy?

What is the difference between the "copy" & "mutableCopy"? EDIT_001: My original post was a bit of a mess, partly due to a lack of understanding and partly due to a bit of pilot error on my part. Here is my attempt to better explain how "copy" & "mutableCopy" work. // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@...

make UIImage conform to the NSCopying protocol

Hello, The question is quite simple, I need to have an UIImage conform to NSCopying protocol but I have absolutely no idea on where to start to achieve this. Do you have any pointer to help me? Thanks in advance ...

Best practice for copying private instance vars with NSCopying

I might be missing something obvious here, but I'm implementing NSCopying on one of my objects. That object has private instance variables that are not exposed via getters, as they shouldn't be used outside the object. In my implementation of copyWithZone:, I need alloc/init the new instance, but also set up its state to match the curre...

When is NSCopying needed?

I know it's needed if your object will be used as a key in an NSDictionary. Are there any other times like this that NSCopying is required? If I think I don't need my model objects to conform to NSCopying, am I probably wrong? ...

write object copy back to a object

Hi I am trying to copy an object using the NSCopying protocol. I load the new controller on iphone and create a copy of a object. All the changes from TextFields are done on the copy. If the user wants to save I guess I have to somehow replace the original one with the copy.. But it does not take over the values... This is the part whe...

Proper way to copy a readonly NSMutableArray

I have an object with a readonly property that I am trying to implement NSCopying for. It has a mutableArray called "subConditions" (which holds "SubCondition" objects). I have made it readonly because I want callers to be able to change the data in the array, but not the array itself. This worked really well until it was time to write ...

UIView as dictionary key?

I want to have a NSDictionary that maps from UIViews to something else. However, since UIViews do not implement the NSCopying protocol, I can't use them directly as dictionary keys. ...

Copying Multi-Dimensional NSMutableArray

I'm currently working on a Sudoku application, the numbers are stored within a Multi-Dimensional NSMutableArray of NSNumbers. I keep an array in my SudokuGridView, for displaying the numbers in the grid. When it comes time to solve the puzzle, I pass a [grid numberGrid] to a subclass of NSOperation I've created that solves the puzzle. T...

NSCopyObject considered harmful?

In the Xcode documentation for NSCopyObject, the special considerations section states: This function is dangerous and very difficult to use correctly. It's use as part of copyWithZone: by any class that can be subclassed, is highly error prone. Under GC or when using Objective-C 2.0, the zone is completely ignored. This functio...

copy NSMutableArray item

I am copying a mutable array like this: //copy players' info into playerList from a dictionary playerList = [[NSMutableArray alloc] initWithArray:[params objectForKey:@"p"] copyItems:YES]; The items in the array implement copyWithZone like this: - (id)copyWithZone:(NSZone *)zone { PlayerInfo* copy = [[[self class] allocWithZone:zo...