Quick Explanation of SUBQUERY in NSPredicate Expression

And for people who don’t quite get what the documentation is saying, a SUBQUERY is essentially this: SUBQUERY(collection, variableName, predicateFormat) And could (simplistically) be implemented like this: id resultingCollection = …; //a new collection, either a mutable set or array NSMutableDictionary * substitutions = [NSMutableDictionary dictionary]; NSPredicate * p = [NSPredicate predicateWithFormat:predicateFormat]; for (id variable … Read more

What does @synthesize window=_window do?

Your properties almost always have a backing variable. What @synthesize searchBar = _searchBar; does is declare that the backing variable for your search bar will be called _searchBar. This allows you to decouple the name of the property from the name of your variable. In fact, if you don’t use @synthesize you don’t need to … Read more

Custom iPhone Keyboard

Here’s an idea: modify the existing keyboard to your own needs. First, register to be notified when it appears on screen: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modifyKeyboard:) name:UIKeyboardWillShowNotification object:nil]; Then, in your modifyKeyboard method: – (void)modifyKeyboard:(NSNotification *)notification { UIView *firstResponder = [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)]; for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) for (UIView *keyboard in [keyboardWindow … Read more

How to send Asynchronous URL Request?

you can use NSURLConnection class NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; and handle its response and errors using its delegate methods. – (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response – (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data – (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error – (void)connectionDidFinishLoading:(NSURLConnection *)connection You can find implementation of NSURLConnection Apple docs: Using NSURLConnection How … Read more

Creating a JSON Store For iPhone

When deciding what persistence to use, it’s important to remember that Core Data is first and foremost an object graph management system. It true function is to create the runtime model layer of Model-View-Controller design patterned apps. Persistence is actually a secondary and even optional function of Core Data. The major modeling/persistence concerns are the … Read more

loading images from a background thread using blocks

you could implement something like this in your cellForRowAtIndexPath: That way you load each image in the background and as soon as its loaded the corresponding cell is updated on the mainThread. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) { NSData *data0 = [NSData dataWithContentsOfURL:someURL]; UIImage *image = [UIImage imageWithData:data0]; dispatch_sync(dispatch_get_main_queue(), ^(void) { UIImageView* imageView = (UIImageView*)[cell viewWithTag:100]; imageView.image … Read more

how to take a screenshot of the iPhone programmatically?

The previous code assumes that the view to be captured lives on the main screen…it might not. Would this work to always capture the content of the main window? (warning: compiled in StackOverflow) – (UIImage *) captureScreen { UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [keyWindow.layer … Read more