Questions tagged [copywithzone]

34 questions
79
votes
4 answers

Best practice when implementing copyWithZone:

I am trying to clear up a few things in my head about implementing copyWithZone:, can anyone comment on the following ... // 001: Crime is a subclass of NSObject. - (id)copyWithZone:(NSZone *)zone { Crime *newCrime = [[[self class]…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
63
votes
8 answers

[UILabel copyWithZone:]: unrecognized selector sent to instance

I feel like I'm banging my head against the wall here (and I'm ready to do that, frankly). I'm trying to set a background to the view. Background I need to set is an image and I'm using this code (which works perfectly fine in two other…
Aleks G
  • 56,435
  • 29
  • 168
  • 265
16
votes
2 answers

iPhone : (id)copyWithZone:(NSZone *)zone : what is "zone" for?

When implementing this method of NSCopying in a class to enable copy, what is the zone param use ? If I set a new object, I do not need to alloc it with allocWithZone as an alloc is just enough... I'm confused...
Oliver
  • 23,072
  • 33
  • 138
  • 230
7
votes
1 answer

How to implement properly mutableCopyWithZone and copyWithZone

I read others few topics about it, but still I'm lost. I want to create 2 kind of objects, one immutable with only "readonly" properties, and one mutable with only "readwrite" properties. Lets call them EXCar and EXMutableCar. EXCar is subclass of…
Tancrede Chazallet
  • 7,035
  • 6
  • 41
  • 62
5
votes
2 answers

Why don’t iOS classes adopt copyWithZone protocol to encourage active mem mgt?

Recently turning to iOS after having worked with Cocoa, I was startled to get a SIGABRT with the following error: “-[UIDeviceRGBColor copyWithZone:]: unrecognized selector sent to instance…” I had called “copy” on a UIColor. I looked at the class…
Wienke
  • 3,723
  • 27
  • 40
4
votes
1 answer

error: no visible @interface for 'NSObject' declares the selector 'copyWithZone:'

I want to allow deep copy of my class object and am trying to implement copyWithZone but the call to [super copyWithZone:zone] yields the error: error: no visible @interface for 'NSObject' declares the selector 'copyWithZone:' @interface…
Howard Spear
  • 551
  • 1
  • 5
  • 14
3
votes
1 answer

Problem when using UIColor RGB black as a key in an NSMutableDictionary

I can set UIColor objects as keys in an NSMutableDictionary all day long and everything is fine and happy... For instance: [myDict setObject:foo forKey:[UIColor redColor]]; That works just fine... UNLESS I try to use the following: UIColor *black…
The McG
  • 175
  • 2
  • 14
3
votes
1 answer

Correctly NSCopying a "parent" property so it points to its already copied parent

I have a class A that contains a property of class B. Class B has a weak reference to its "parent" class A. Both classes implement NSCopying. I don't know how exactly NSCopying should be implemented in class B. I see the two obvious choices: assign…
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
3
votes
2 answers

NSCollectionView in 10.6/Xcode 3.2

in Xcode 3.1.2 I used to load the nib of the NSCollectionViewItem in my subclass of NSCollectionViewItem like this: -(id)copyWithZone:(NSZone *)zone { id result = [super copyWithZone:zone]; [NSBundle loadNibNamed:@"PersonView"…
2
votes
1 answer

iOS copyWithZone unrecognized selector only when using device

I'm working on an iPad app that launches an initial screen only when there is certain data in a sqlite DB, something like this: if ((int)[MyStore sharedInstance].mode < 0) { self.connectionSettingsViewController =…
aprunedamtz
  • 169
  • 2
  • 10
2
votes
1 answer

copyWithZone: (deep copy) crash in subclass

I try to create a copying method confering to the protocol NSCopying. I have the following class: @interface Gene : NSObject { int firstAllele; int secondAllele; } with the method: -(id) copyWithZone:(NSZone*) zone { id…
Aranir
  • 41
  • 1
  • 3
2
votes
1 answer

Deep copy - are these two implementations of copyWithZone different?

I have seen two some a bit different ways for implementing copyWithZone. Are they different? 1st code: @interface Person : NSObject @property (nonatomic,weak) NSString *name; @property (nonatomic,weak) NSString *surname; @property…
user2553675
  • 495
  • 2
  • 5
  • 16
2
votes
1 answer

[MyClassName copyWithZone:]: unrecognized selector sent to instance?

I just implemented my class @interface ExampleNestedTablesViewController () { NSMutableArray *projectModelArray; NSMutableDictionary *sectionContentDictionary; } - (void)viewDidLoad { [super viewDidLoad]; ProjectModel *project1 =…
2
votes
2 answers

NSmanagedObject copyWithZone issues

I have a custom class Thing:NSManagedObject with an attribute of adminName. I am trying to create a copyWithZone function in this Thing class, but when I run the app it says setAdminName doesn't exist. In my implementation file I am using @dynamic…
jdog
  • 10,351
  • 29
  • 90
  • 165
1
vote
1 answer

copyWithZone return value ownership and retain count

I read in the apple documentation about copyWithZone : "The returned object is implicitly retained by the sender, who is responsible for releasing it". So if I write this : - (id)copyWithZone:(NSZone *)zone { MyObject* obj = [[[[self…
Oliver
  • 23,072
  • 33
  • 138
  • 230
1
2 3