Image preview for iOS

Ever wanted to have a simple way of previewing an image on iPhone ?
Maybe you have a thumbnail you wish to preview in a larger size ? Or you have a thumbnail downloaded from a url, and if you tap on the thumbnail you want to download the bigger version of the image and preview it ?
Well, you can do all this with this small component. ( download the code at the end of this article )

Let’s see what can you do with this component. In its simplest form, we can use the component to preview a UIImageView’s image:

INImagePreview *preview = [[INImagePreview alloc] init];

[preview previewImage:oneImageView.image parentView:mainView];

[preview release];

In this case we have a UIImageView named oneImageView. We are going to preview the image of this oneImageView. The mainView is going to hold the preview of the image. It looks like this:

The second – and maybe a more useful case is when we tap on a UIImageView but we want to download the bigger version of the thumbnail and display it. This can be achieved with something similar to this:

INImagePreview *preview = [[INImagePreview alloc] init];

[preview previewImageWithUrl:[NSURL URLWithString:@"http://moszi.net/dev/Home_files/server.jpg"]
                  parentView:mainView];

[preview release];

In this case INImagePreview will show a small UIActivityIndicator until the image is downloaded, then will show the downloaded image.

While this functionality is okay, probably what every developer would do as a next step is to add a UIButton or a UIControl on top of the UIImageView and invoke the code above to preview an image. This is why the next two category methods will be at hand:

[oneImageView previewImageWhenTouchedUpInsideUsingParentView:mainView];
[oneImageView previewUrlWhenTouchedUpInside:[NSURL URLWithString:
     @"http://moszi.net/dev/Home_files/server.jpg"] usingParentView:mainView];

 

The two UIImageView category methods will add functionality to the UIImageView so that when it’s tapped the appropriate image is previewed. The above category methods use Associative Storage (objc_setAssociatedObject) to add an INImagePreview instance to the UIImageView so the functionality can be executed later in time.

You can download the demo project attached to this article. If you like the component drop me a message ;)INImagePreview-Demo

iPhone Interview Questions

Interviewing people is always hard, since you have to assess the candidate in several ways. That includes the knowledge relevant to your industry, or if that person fits into your organization’s work style or habits, if the person can work under heavy workload – but interviewing candidates also means that you have to give a good impression about yourself and your company. The hard part is that you need to do this in a really short timeframe which complicates things a bit …
There are a couple of good books that focus this area, one of the books which i know and read is “96 Great Interview Questions to Ask before you hire” but there are a couple of good others as well.
Recently I was given the task of interviewing candidates for positions in iPhone development – and besides the fact that i wasn’t really sure how to approach and conduct an interview (that was the time when i bought the book i linked above) – i needed a bit of help on the actual technical questions i could ask on iOS development, but at that time there were no good resources i could find on this topic.

So I decided to write up a list of iphone interview questions that could serve as a good starting point for Objective-C and Cocoa development topics. Also i intend to update this list later when i will have more information to add – hoping to build a comprehensive list of technical questions.

So here it is – a list of possible iphone interview questions:
—- Objective-C related —-

  • identify basic OO concepts and the keywords Objective-C uses (interface, implementation, property, protocol, etc)
  • what is a designated initializer, what is the pattern for the initializers and why ( if (self = [super ...] ) )
  • basic memory management topics, like ownership retain/release/autorelease
    • what happens if you add your just created object to a mutable array, and you release your object
    • what happens if the array is released
    • what happens if you remove the object from the array, and you try to use it
  • trick: garbage collection on iPhone
  • autorelease pool usage
  • property declarations ( assign, nonatomic, readonly, retain, copy )
    • trick: ask about the nonexistent atomic keyword, what does atomic mean
    • ask on how to correctly implement a retaining setter property
    • ask about the circular reference problem and delegates being usually saved with assign rather then retain
  • what is the difference between the dot notation and using the square brackets
    • what happens when we invoke a method on a nil pointer
    • difference between nil and Nil
  • what is KVO and related theory + methods to use when observing
    • does KVO work with ivars too?
  • protocols – maybe: main difference between c#/java interface and protocols
    • what to do in a situation when a class doesn’t implement a method from a protocol
  • what about multiple class inheritance
  • what is fast enumeration
  • class methods vs instance methods
    • visibility of methods
  • what is an actual class in Objective-c (struct)
    • ask about the isa member
    • ask about isKindOfClass isMemberOfClass
  • root classes: NSObject, NSProxy
    • how does proxy-ing work
    • how to fake multiple class inheritance
  • id type
    • what happens during compilation if we invoke a method on an variable with the type id
    • what happens runtime if the method exists
    • what happens if the methods doesn’t exist
    • pro and cons of using the type id
    • what happens here(compile + runtime): NSString *s = [NSNumber numberWithInt:3]; int i = [s intValue];
  • what are class categories and the () category
  • what is an informal protocol
  • what is a delegate, how to create one, and use one
  • what is a selector, how to do a perform selector
    • how to delay executing a selector
    • what to do when the selector has more paramters (NSInvocation>
    • how to start a selector on a background thread
  • how to start a thread
    • what is the first thing to do on a thread (autorelease pool)
    • what is a runloop, and one very common place where it is used (timers, nsurlconnection)
  • how to download something from the internet
    • what is the difference between a synchronous and an asynchronous request
    • small task: explain how to download an image from the internet, and show this in an image view – all this after a button is tapped on the view
  • what are notifications, how to use them
  • what is a memory warning, how do we respond to it

—- A bit more advanced topics —-

  • when to use retainCount (never, and why)
  • why shouldn’t we invoke instance methods in an initializer and the dealloc
  • NSCoding, archiving
  • NSCopying, why can’t we simply use our own objects as key in a dictionary, what to do to solve the problem ( and the difference between a shallow and a deep copy)

—- UIKit related —-

  • what is a view, and a window
  • difference between a view’s bounds and frame
  • what is the resolution of the current available devices, difference between points and pixels (starting with iOS4)
  • what is the responder chain, becomeFirstResponder
  • what do IBOutlet and IBAction mean, what are they preprocessed to
  • how do tableviews function
  • what about multithreading and UIKit
  • what to do when the keyboard appears and hides some parts of the UI that are important
  • why should we release the outlets in viewDidUnload
  • what is awakeFromNib, what is the difference between a nib and a xib

—- CoreData —-

  • what is a context
  • what about multi threading and core data usage
  • what is an NSManagedObjectId – can we save it for later if the application was stopped
  • what types of stores does core data support
  • what is lazy loading, how does this relate to core data, situations when this can be handy
  • how to ready only a few attributes of an entity
  • what is an fetch result controller
  • how to synchronize contexts
  • how could one simulate an NSManagedObject (i’m thinking of the fact that all the properties are dynamic and not synthesized)

Okay – this probably is not a very organized list nor it is complete, but as i said i will get back and complete this list.
Also i would be really glad if you would drop a comment if you find this list useful, or want to add / correct something.