Skip to content

Instantly share code, notes, and snippets.

@richardbuckle
richardbuckle / gist:e5205cdc9ad105741bb0
Last active August 29, 2015 14:03
fopen() fails with ENOENT but open() works. WTF?
Verbatim LLDB session with an iPad Air running iOS 7.1.1.
As you can see, "finPath", which is a const char*, is an absolute path.
Normally fopen(finPath, "r") works fine but sometimes after stress-testing the app gets into a state where it always fails with ENOENT.
How could fopen(finPath, "r") fail with ENOENT while open(finPath, O_RDONLY) succeeds?
Edit: forgot to say that no memory warnings were received during the stress test.
(lldb) p finPath
@richardbuckle
richardbuckle / gist:7189956
Created October 28, 2013 01:15
Answers for @mikeabdullah's hipster question "What is the only public class in the Cocoa frameworks that has no methods of its own?
I found:
NSMessagePort
NSURLSessionDataTask
NSURLSessionUploadTask
None of these were what Mike had in mind, which was NSFileSecurity.
I commented that NSFileSecurity was doubly interesting because it's in Foundation but not listed in "Foundation Framework Reference".
@richardbuckle
richardbuckle / gist:6038567
Created July 19, 2013 11:43
Use a nil-targeted action to message a view controller higher up the responder chain without introducing coupling
// in some parent view controller's header file
- (IBAction)yourActionNameHere:(id)sender;
// implementation does whatever you want
// Now, from any call site, as long as you're on the main thread
// just post an action to nil and it will be sent to the first responder,
// then all the way up the responder chain until it finds your view controller
[[UIApplication sharedApplication] sendAction:@selector(yourActionNameHere:)
@richardbuckle
richardbuckle / NoNSTableView tooltips
Created January 31, 2012 20:46
NSTableView delegate methods to prevent tooltips
- (BOOL)tableView:(NSTableView*)tableView shouldShowCellExpansionForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
{
return NO; // no tool tips
}
- (NSString*)tableView:(NSTableView*)aTableView toolTipForCell:(NSCell*)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation
{
return nil; // no tool tips
}
@richardbuckle
richardbuckle / Nonlocalised string regex.txt
Last active September 27, 2015 16:28
VERY quick and dirty regex to hunt for string literals that may need to be localised
(?<!Path:|Key:|NSLocalizedString\(|NibName:|NibNamed:|imageNamed:|PathComponent:|xpathQuery:|initForModel:|initWithDomain:|predicateWithFormat:|setDateFormat:|fontWithName:|entities:|sortBy:|NSClassFromString\(|NSLog\(|DLog\(|ALog\(|DebugLogging\()\s*(?!@"%@"|@"%d")@".+"
@richardbuckle
richardbuckle / shut down core data.m
Created September 23, 2011 22:29
Shut down a Core Data store prior to deleting the underlying file
- (void)closeDown {
NSArray *stores = [self.persistentStoreCoordinator persistentStores];
for (NSPersistentStore *store in stores) {
DebugLogging(@"Closing Core Data store at %@", [store URL]);
NSError *error = nil;
if (![self.persistentStoreCoordinator removePersistentStore:store error:&error]) {
DebugLogging(@"Unable to close Core Data store: error %@", [error localizedDescription]);
}
}
}