Skip to content

Instantly share code, notes, and snippets.

View joericioppo's full-sized avatar

Joe Ricioppo joericioppo

View GitHub Profile
@mikeabdullah
mikeabdullah / gist:4740463
Last active January 6, 2024 07:31
Atomic file copying
- (BOOL)atomicCopyItemAtURL:(NSURL *)sourceURL
toURL:(NSURL *)destinationURL
error:(NSError **)outError
{
NSFileManager *manager = [NSFileManager defaultManager];
// First copy into a temporary location where failure doesn't matter
NSURL *tempDir = [manager URLForDirectory:NSItemReplacementDirectory
inDomain:NSUserDomainMask
appropriateForURL:destinationURL
@implementation UIControl (RepresentedObject)
static char kRepresentedObjectKey;
- (void)setRepresentedObject:(id<NSObject>)object{
id assocObject = [self representedObject];
if(assocObject != object){
[assocObject release];
objc_setAssociatedObject(self, &kRepresentedObjectKey, object, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}