Reputation: 57
If an app sets data in the UIPasteBoard of iOS, are they deep copied or shallow copied?
Upvotes: 1
Views: 481
Reputation: 57
UIPasteboard uses NSData to store the data. Hence, it is deep copy.
From the official documentation for "setData:forPasteboardType:"
"Use this method to put raw data on the pasteboard. For example, you could archive a graph of model objects and pass the resulting NSData object to a related app via a pasteboard using a custom pasteboard type. (To put objects—such as NSString, NSArray, NSDictionary, NSDate, NSNumber, UIImage, or NSURL objects—on the pasteboard, use the setValue:forPasteboardType: method.) This method writes data for the first item in the pasteboard. Calling this method replaces any items currently in the pasteboard."
Upvotes: 0
Reputation: 21726
If you ask about - (void)setData:(NSData *)data forPasteboardType:(NSString *)pasteboardType
than it is surely a Deep copy.
If you ask about strings
, URL's
, Colors
they are also Deep copied.
Only about the Images
I am preety sure that it uses the same CGImageRef
, because UImage does not implement NSCopying
protocol
You can test it just closing your application and see that data stays in the pasteboard.
Upvotes: 1