Questions tagged [nscopying]

NSCopying is a protocol that provides a way to make a copy of an object.

NSCopying is a protocol that allows a class to make a copy of itself in whatever manner makes sense for that object. The only requirement is to implement copyWithZone:, which typically duplicates any relevant instance variables into a new instance. Other classes can make a copy of an object by calling copy, which is implemented by NSObject to simply call copyWithZone: on the receiver.

Apple Documentation for NSCopying

103 questions
1
vote
1 answer

Incompatible pointer types sending 'Class' to parameter of type 'id'

I have updated xcode and now I get the error message Incompatible pointer types sending 'Class' to parameter of type 'id' - (void)mapObjectClass:(Class)objectClass toCellClass:(Class)cellClass { [self.objectToCellMap setObject:cellClass…
Armin Nehzat
  • 418
  • 6
  • 13
1
vote
1 answer

UILocalNotification - mutable copying

Overview: I am copying an instance of UILocalNotification and making changes to it to the newly created instance Then I schedule the newly created instance of UILocalNotification How I am copying I am copying the instance of UILocalNotification…
user1046037
  • 16,755
  • 12
  • 92
  • 138
0
votes
2 answers

How to subclass UIButton to allow to copy and encode for archiving?

I have an app where I need to track the last button pressed at all times. So I have implemented this method: -(void) lastButtonPressed: (id)sender { lastButtonPressed = (UIButton *)sender; } Then when any button gets pressed I call: [self…
d.altman
  • 355
  • 4
  • 15
0
votes
1 answer

Can't copy NSMutableArray to property

I have read countless questions surrounding the copying of arrays on both this site and others, but none directly addresses the problem I'm having. I have declared and synthesized a property called arrXTurbulenceValues: @property (weak, nonatomic)…
0
votes
1 answer

data type not checked when copy method is used in assignment

I have a doubt regarding copy Overview: I have 2 classes namely Car and MutableCar Both these classes conform to the protocol NSCopying The method copy would return an instance of Car Question Why doesn't the compiler doesn't throw any…
user1046037
  • 16,755
  • 12
  • 92
  • 138
0
votes
1 answer

Save CoreData result array even after it is deleted from the CoreData

I want to save the records in an array and delete them from the CoreData. I have tried using NSCopying but it seems that copyWithZone doesn't work on NSManagedObject. I am really stuck, any help will be appreciated.
Saleh
  • 380
  • 3
  • 19
0
votes
1 answer

NSCopying and copyWithZone: - should they return [self retain] or something else?

I'm having a hard time understanding copyWithZone. I know it's supposed to return a copy, but if I add an object to a dictionary, it adds a 'copyWithZone' object to the dictionary. If I make an actual copy (that is, a new object), then the object…
AWF4vk
  • 5,810
  • 3
  • 37
  • 70
0
votes
0 answers

How to copy UIImageView?

I need to get a copy of UIImageView (essentially the same UIImageView only in a different variable and the lack of a link between them) I tried using the copy() method, but have crash my code let copyImageView = imageView?.copy() as?…
0
votes
1 answer

Add a NSXPCConnection as a key to a NSMutableDictionary

Edit: I solved this problem by adding the process identifier that is exposed from the NSXPCConnection class as that is unique per connection as the key. Problem: I'm facing a problem where I need to store a key-value pair in a NSMutableDictionary…
jormen651
  • 1
  • 1
0
votes
0 answers

NSMutableDictionary content objects comply to NSCopying protocol

I am on objective-c, macOS. I have an options Dictionary declared like this @property NSMutableDictionary* options Now the object containing the dictionary needs to be copied with copyWithZone including the options. I can invoke "copy" on the…
Pat_Morita
  • 3,355
  • 3
  • 25
  • 36
0
votes
3 answers

Memory Leak on device when using mutableCopy

I thought that I was really close to release this new App of mine when I ran into a dead end. My code works without memory leaks in the simulator (Xcode 4.0.2) but reports memory leaks on my devices. I think my issue is related to that I copy an…
Structurer
  • 694
  • 1
  • 10
  • 23
0
votes
1 answer

Copying a UIImageView subclass

I have several objects in an array. These objects are from a UIImageView subclass. These objects' class has several @synthesized properties. At some point I have to create a duplicate of an object in a given position on the array at a different…
Duck
  • 34,902
  • 47
  • 248
  • 470
0
votes
1 answer

Implementing Codable and NSManagedObject simultaneously in Swift

I have an order processing application I'm working on for my employers that was originally designed to get all data about orders, products, and clients dynamically from the API. So all of the objects and and all of the functions dealing with those…
A. L. Strine
  • 611
  • 1
  • 7
  • 23
0
votes
2 answers

copy objects from one NSMutableArray to another NSMutableArray

I am trying to understand copying objects from one NSMutableArray to another. Consider the following 2 scenarios: 1 - copying original to clone where changes in the clone will affect the original. 2 - copying original to clone where the changes in…
s2000coder
  • 913
  • 2
  • 15
  • 23
0
votes
1 answer

Swift 4 Copy an array of objects by value which have array inside

I'm trying to understand how the copy() function works in Swift 4. I have two classes which are structured like this: class Project { var id: Int var name: String var team: [Person]? init(id: Int, name: String, team: [Person]?) { …