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
0
votes
0 answers

id to NSString

I have some NSURL *url and I want to get its GenerationId: NSDictionary *dictionary = [url resourceValuesForKeys:@[NSURLGenerationIdentifierKey] error:&error]; id generatonIdKey = dictionary[NSURLGenerationIdentifierKey]; //Returned as an id…
Sanich
  • 1,739
  • 6
  • 25
  • 43
0
votes
0 answers

Unexpected result of property `copy` attribute

I've implemented NSCopying for own class and when I use this class as a property with copy attribute I'm expecting that it should use [... copy]/[... copyWithZone:] method. But it returns a reference to the same object. But if I use copy attribute…
0
votes
3 answers

Make a copy of object with same address in swift

var empObj : EmployeeModel! var tempObj : EmployeeModel! tempObj = empObj.copy() as! EmployeeModel whenevr I am copy the empObj to tempObj it's memory address is changed.I want to prevent this any idea?
0
votes
2 answers

Expected method to read dictionary element not found on object of type 'id

I am trying to upgrade my app to Xcode 9.3.1 from 8 and have these errors: Expected method to read dictionary element not found on object of type 'id' My code is: // Normalize the blending mode to use for the key. // *** Error on next…
BTVC
  • 1
0
votes
1 answer

Why use toll-free bridging for collections with custom memory-management semantics?

In the book Effective Objective-C 2.0: 52 Specific Ways to Improve Your iOS and OS X Program there is an Item 49: Use Toll-Free Bridging for Collections with Custom Memory-Management Semantics This chapter mainly explains the importance of…
PinkiePie-Z
  • 525
  • 1
  • 6
  • 28
0
votes
1 answer

Shallow copy vs deep copy issue iOS Swift

I am facing issue to clone an object in swift 3. I want to duplicate/clone an object then want to modify it's value so that modification doesn't reflect on the actual object. Here is what I did. let patientInformation =…
A.Sen
  • 1
  • 2
0
votes
2 answers

Data Loss When Passing Object

I have an object @interface QuestionViewModel : NSObject @property (nonatomic, assign) NSInteger questionId; @property (nonatomic, strong) NSString *questionText; @property (nonatomic, assign) NSInteger questionNumber; @property (nonatomic, strong)…
0
votes
1 answer

Recursively creating an object and copying specific objects from an array in said object

So, I'm struggling a bit with my programming project. I have a object that stores player information, name, wins, losses. I proceed to use that object in another object (a bracket) that sets the values of the player information, after each loop it…
Duckzero
  • 25
  • 3
0
votes
0 answers

How does [NSDictionary copy] method work?

I just want to know the tech inside. Does it enumerate all key/value s or copy method is thread safe? If I'm doing [dict copy](dict is a NSMutableDictionary) on a background thread, and update dict on main thread, will it crash?…
Ypy
  • 56
  • 5
0
votes
1 answer

How to store data with id keys which are not NSCopying

I need to realize an interface that mimics MKMapView in some sense. Specifically, I need to support methods -(void)addAnnotation:(id)annotation; -(UIView *)viewForAnnotation:(id)annotation; Internally there is a mapping…
Nick
  • 3,205
  • 9
  • 57
  • 108
0
votes
1 answer

NSCopying Protocol Not Working

I am trying to copy an object, and I've implemented the NSCopying protocol, which looks like this: #MyActivity.h @interface MyActivity : MyModel { NSInteger activityId; NSInteger userId; NSInteger checkinId; NSString…
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
0
votes
1 answer

swift - NSCopying class

In Swift 2.1, how should I create a class conforming NSCopying protocol? I tried this: class TargetValue: NSObject, NSCopying { var value: Int? func copyWithZone(zone: NSZone) -> AnyObject { let copy = TargetValue() …
quanguyen
  • 1,443
  • 3
  • 17
  • 29
0
votes
1 answer

swift - HomeKit updateTargetValue of HMCharacteristicWriteAction crashes

I am trying to update target value of an action (HMCharacteristicWriteAction) but it always crashes with EXC_BAD_ACCESS (code=1, address=0x50). My code snippet: print("\(action) --> \(action.dynamicType)") //
quanguyen
  • 1,443
  • 3
  • 17
  • 29
0
votes
1 answer

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: -…
Daniel
  • 20,420
  • 10
  • 92
  • 149
0
votes
1 answer

NSDictionary to custom class

I've a custom class QBChatDialog object, that I'm storing in sqlite database like -(void)storeInDB:(QBChatDialog *)dialog { NSString *query = = [NSString stringWithFormat:@"INSERT INTO dialogs (dialog_id,last_message) VALUES…
Sikander
  • 447
  • 4
  • 26