Monday, May 23, 2011

Universal iOs Applications

I've spent this afternoon looking at building a universal application for an iPhone application.

First of all I would like to go on the record that I think in general this is a bad software engineering practice - at least in theory .

Having your code check to see if what kind of device it is running and then execute a different set of functions based on the answer feels very hackish to me - at least from a conceptual level.

However, from a user perspective it is sweet software magic that is incredibly awesome - especially when dealing with "markets" similar to what Apple and Google have. For example you only can buy an application once and it can be run on the iPhone or iPad. It's like getting two great applications for the price of one.

I finally decided to buckle down and work through this and as you may expect it is much easier than I expected it to be. I started by:

  • creating a brand new iPhone application
  • then clicked on Application in the top left pane
  • and selected "Universal" in the Deployment Target drop down

Here is a screen shot:

Once xCode runs through it's magic you get a new folder called iPad that contains a new "Window" called "MainWindow-iPad.xib".

Now if you run the application you will be able to run in full iPad mode but the layout will be used by both the iPhone and iPad emulator and that is not what I intended to happen... To get this to change first of all you need another ViewController for the iPad to run so go ahead and create one of those using:
File -> New -> New File... c'mon you know the rest...

So... how do we get our new controller instantiated? Probably have to link into the app delegate, check the InterfaceIdiom to find out what kind of device we're running right?

Nope - not at all. You can handle all of this magic in the Interface Designer. No code change is actually needed! Here is how to do it:
Click on the new "MainWindow-iPad.xib" that xCode created for us
Select the View object in the hierarchy
and change the class under the "Identity Inspector"




Now if you run it you will still get the old layout (and probably crash). What you have to do is tell interface builder to load a different nib file:


Now you can run either emulator and you will get the correct view controller magically instantiated and the correct nib will be laoded.

That doesn't feel very hackish at all now does it?

-A





Monday, February 21, 2011

Google Makes me feel like a Genius!

It's true, just about every time I work on my Android applications - I get that weird maniacal evil genius laugh... You know what I'm talking about - admit it.

If you use CBI you should know that there is a backup feature included that exports your collection as a CSV file [CSV is kind of like an open source spread sheet format].

I've been wanting to send the backup file to Google Docs for awhile now but haven't gotten around to it. Last week I downloaded the source to Google's Client API source code and have been tinkering around with it. And have it backing up my spreadsheet now.

I still have to get the restoration working but I think that will be even easier than the backup.... Maybe I'll post some code for posterity in a bit but right now I have to get back to my mad genius cackling....

Here is a link to my spreadsheet so you can check out the format: My Collection

Tell me what other Comic Book Application will let you do that!

-A


Tuesday, February 15, 2011

Objective C can really stink

Let me preface this by saying I am not a very good Objective C programmer. I come from a strong background in Java and enjoy Objective C becuase it's a new technology (for me) and it solves problems different from Java... well at least the API backed by Cocoa Touch solves them in a different way.

Coming from Java I will tell you this - Exception handling in Objective C is horrible! I've spent all morning dinking around trying to get a table view to display. I've been doing Objective C for 2 years now (not exclusively - but I'm not a complete newbie) so to be having problems with something this basic is pretty frustrating.

The problem really starts with me becoming more familiar with the language. As comfort levels increase I begin exploring how to solve things in slightly different ways... This is what happened today. I'm using a NavigationController to pop on a series of views (successfully until this morning).

I have this little block of boiler plate I toss around to pop a view on the NavController that looks like this:

NewViewController *vc = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
NSArray *items = [NSArray arrayWithObjects:@"Item 1", @"Item 2", @"Item 3", nil];
[vc setItems:items];
[vc setTitle:@"Items"];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
[items release];

Here is the logic behind the code -

  1. Create a new view controller
  2. Create a new list to slam into the table view for the view controller and pop it in
  3. Set the items array into the view controller
  4. push the view controller into the navigation controller
  5. releace the memory for the view controller as it is now owned by the navigation controller
  6. and release the array since it is now owned by the view controller

Even now just looking at the code I just figured out what the problem is - I'm not actually creating a new instance of the items array. So by releasing it - my new view controller crashes because it's retain call got mistakenly released by someone else.

Simple problem - no big deal at all. My frustration really is that the app just crashes without any type of error at all... just a *blip* application died... Occasionally it would spit out this error:

Program received signal: “EXC_BAD_ACCESS”.

Which is not helpful at all - basically that means we accessed memory that we shouldn't have.

I agree whole heartedly that this is not a problem with Objective C - it all comes from my ignorance and lack of experience - however, it is still very frustrating.

-A

Thursday, February 10, 2011

Anxious, Silly things

I have a 1st grader at home. She goes through boughts of anxiety here and there - nothing major but enough to be mildly concerning... At night she often makes sure the windows and doors are locked. Of course there is the general fear of the dark - and as of late does not want to go to school - because she misses her family...

Nothing major or probably outside of normal behavior - but I find myself going through all kinds of things in the morning to get her mind off of the looming drive to school - that often ends in tears...

Today she was rather sad so I drew a picture of her face and hair, in an attempt to get her to smile (no luck) but she did end up drawing in the body and crown(?!) to go with it...


The morning drop off went decent this morning - I'm not sure the picture helped but it was silly drawing on a anxious morning...

-A

Sunday, February 06, 2011

Best Wallpaper

So, I have this little app called Comic Book Inventory or CBI for short. CBI (as the name might imply) lets you inventory your comic book collection, once you get your collection added you can look up issues by Title, Author, Penciler, Inker, Colorist etc.

You can also do some pretty fancy things like find missing issues, get the weekly release list of comics, create a "pull list" (and lots more). My favorite feature of CBI is that you can set your android wallpaper to a comic book cover; actually you can select up to 4 covers and CBI will mash them together.

So here is one of my favorite desktops I've created lately: It's the cover of "Lady Mechanika" #0




Here is another desktop showing a multi-cover desktop.


If you haven't read Lady Mechanika you should check it out. It is creator owned comic published by Aspen Comics and owned by Joe Benitez.

There are only 2 issues out (#0 and #1) but so far the story and art are fantastic!

-Aaron