16

Jul

Easiest way to download remote files for iOS

I updated and open-sourced a utility for downloading web-hosted files for iOS today. Using it is extremely easy and doesn't require any notifications or delegates. Only sexy block syntax.

First, you'll need to import it in your implementation file:

 #import "RemoteDataManager.h" 

Then you can:

 NSString *location = @"http://tailsmagazines.files.wordpress.com/2009/04/kitten.jpg?w=320&h=480"; [[RemoteDataManager sharedManager] getDataAtLocation:location withCallback:^(BOOL waiting, NSData *data){ if(waiting){ // if the data is not cached [loadingIndicator startAnimating]; } // when the data is available else{ [loadingIndicator stopAnimating]; imageView.image = [UIImage imageWithData:data]; } }]; 

The key thing to acknowledge here is that the Callback block may get

17

Jun

Konstructor: Easy TableViews for iOS

Creating TableViews is one of the many very verbose tasks in iOS development. Every attribute of the table and the cells has to be customized by implementing a different protocol method.

Not anymore

Thanks to the magic of blocks, the overly terse task can become something declarative, readable and even fun!

Here's an example of what it can be with Konstructor:

 self.tableCellHeight = 100.0; /* Create an array of data. You'll likely do this completely differently */ NSDictionary *gloves = [NSDictionary dictionaryWithObjectsAndKeys:@"Gloves", @"name", @"for your hands", @"caption", nil]; NSDictionary *muffs = [NSDictionary dictionaryWithObjectsAndKeys:@"Muffs", @"name", @"for your ears", @"caption",

22

Jan

AOL Instant Messenger .... What's going on?

I tried signing up for an AOL IM using an email address today. It would be my 5th or something ridiculous. I like to keep my life separated like tupperware.

Anyway, when I tried to do so, I got the following error with no explanation (How "Aol" of them:

10

Oct

NSOperation and NSURLConnection conflicts

The right way to use NSOperation, NSOperationQueue and NSURLConnection

I stumbled across a problem today when trying to make an asynchronous POST request to a server.

I created a request class by subclassing NSOperation and was calling it by adding it to an NSOperationQueue (more here) and within this class's (void)main method, I was creating an NSURLConnection like this:

 NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self] 

The problem I was experiencing was none of the NSURLConnection delegate callbacks were being fired.

After a little research I realized that when you create an NSURLConnection using the initWithRequest

10

Oct

Mocking paperclip with rspec

When using the S3 method of storage for paperclip, the last thing you want is to incur extra charges just for running your tests.

If you want to simply mock the storage aspect completely, and I'm not saying you do, but *if* you do, just do this:

@your_model.should_receive(:save_attached_files).and_return(true)

26

Aug

NSXMLParser doesn't fire - (void)parserDidEndDocument:(NSXMLParser *)parser

Today I ran into an issue where an NSXMLParser would not fire the parserDidEndDocument delegate method. I was parsing XML stored locally and it turned out to be an issue with a trailing newline at the end of the document.

To fix it, I made sure there was no newline at the end of the final closing XML tag. This seems lame of NSXMLParser or is there a convention I am just not aware of?

Nevertheless, I hope this helps someone.