Wednesday, July 04, 2012

Some iPhone Development Stuff

I was working on coding some Water-Fuel display systems that needed floating point numbers converted to a 2 decimal place display for the UI.


NSString* formattedNumber = [NSString stringWithFormat:@"%.02f", myFloat];
This came from a great Stackoverflow question here:
http://stackoverflow.com/questions/560517/make-a-float-only-show-two-decimal-places

When I'm making lots and lots of model objects from existing applications, I often want to generate Objective-C from JSON or GSON. I use http://tigerbears.com/objectify/ for that.

Trying to figure out some stuff about Apple's in-app purchasing system I learned a lot from reading http://www.raywenderlich.com/2797/introduction-to-in-app-purchases which is an excellent tutorial on an excellent site.

Wednesday, April 25, 2012

Controller Events in Android vs. iPhone

Android


  1. onCreate
  2. onStart
  3. onResume
  4. onPause
  5. onStop
  6. onDestroy
  7. onLowMemory

iPhone


  1. loadView
  2. viewDidLoad
  3. viewWillAppear
  4. viewDidAppear
  5. viewWillDisappear
  6. viewDidDisappear
  7. didReceiveMemoryWarning

Monday, April 23, 2012

Retrieve a File from iPhone Developer Device Sandbox

Here is a post discussing extracting files from an iPhone development device.

You basically use Organizer, browse to the Sandbox Application and click 'Export'

http://stackoverflow.com/questions/1548029/copy-a-file-from-iphone-sandbox-to-desktop

Remove the Frames Per Second FPS in Cocos2d Project

Sooner or later you will need to remove the FPS image in your Cocos2d project.

[[CCDirector sharedDirector] setDisplayFPS:NO];

I do this directly after i setOpenGLView.

Saturday, April 14, 2012

iPhone UIScrollView Seemed Really Hard Until

At least until I read this tutorial:

http://redartisan.com/2010/5/23/scrolling-with-uiscrollview

A lot of other tutorials make the process very unclear and skip over the realistic requirements of building "larger than window UIView" and this page on Red Artisan hits it perfectly.

Tuesday, April 10, 2012

Inserting and Deleting Data using FMDB


I have been using FMDB to manage the Star Traders RPG database files in iPhone.

There are two ways to run the -(void) executeUpdate; method, as outlined here:

http://www.icodeblog.com/2011/11/04/simple-sqlite-database-interaction-using-fmdb/

The page that got me started was this -- the key is the "open" method

Inserting And Deleting Data

Inserting data using sqlite is very straight forward. You can either build your strings and pass them in directly OR use the sqlite format using “?’s” and letting fmdb do the work. Below is an example of each:
// Building the string ourself
NSString *query = [NSString stringWithFormat:@"insert into user values ('%@', %d)",
@"brandontreb", 25];
[database executeUpdate:query];
 
// Let fmdb do the work
[database executeUpdate:@"insert into user(name, age) values(?,?)",
@"cruffenach",[NSNumber numberWithInt:25],nil];
Generally, the second route is preferred as fmdb will do some of the sanitizing for your (such as add slashes to single quotes).
Now that we have some data in our database, let’s delete it. The following code will delete all users with an age of 25:
[database executeUpdate:@"delete from user where age = 25"];
And that should remove both of the records that we inserted.

iPhone or iPad to Start Out?

I have been trying to decide -- should I start with making and testing an iPhone or an iPad application first?

I used this tutorial to convert from an iPhone application to one that ran on iPad and iPhone but the results were not very good.

http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html

Where Are the Best iPhone Tutorials?

Here are the ones I am finding most useful:

http://www.raywenderlich.com/tutorials

Which iPhone tutorials have you found most useful for development -- games or in general?

Android to iPhone -- Passing Data Between Controllers

In Android we use INTENT and in iPhone we use a few different techniques.

This link has two methods, passing into and passing out of. I'm using a database for most of my return values but I found the snippets below to be the most valuable.

http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers

Passing Data INTO a UIViewController
Of course we could skip right to the code:


For this example we will have ViewControllerA and ViewControllerB
To pass a BOOL value from ViewControllerA to ViewControllerB we would do the following.
1) in ViewControllerB.h create a property for the BOOL
@property(nonatomic) BOOL *isSomethingEnabled;
2) in ViewControllerA you need to tell it about ViewControllerB so use an
#import "ViewControllerB.h"
Then where you want to load the view eg. didSelectRowAtIndex or some IBAction you need to set the property in ViewControllerB before you push it onto nav stack.
ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib=@"ViewControllerB" bundle=nil];
viewControllerB.isSomethingEnabled = YES;
[self pushViewController:viewControllerB animated:YES];

More IPhone Development

If you need to replace the current controller in a UINavigationController this StackOverflow page has a lot of what you need:

http://stackoverflow.com/questions/410471/how-can-i-pop-a-view-from-a-uinavigationcontroller-and-replace-it-with-another-i

The important part is the code of course:


Once you do that prep, then just pop and push as normal. This code will instantly replace the top controller with another.
// locally store the navigation controller since
// self.navigationController will be nil once we are popped
UINavigationController *navController = self.navigationController;
// retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];
// Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:someViewController animated:NO];

Motivating Employees and Being a Great Boss

I have been very concerned about trying to be a "good leader" in my work.

One thing I have tried today is to locate key qualities that make a good boss and latch onto them.

Five Qualities of Remarkable Bosses

These qualities, however, can be difficult to find in yourself or in other leaders.

A common theme in the "how to motivate employees" pages I read is that it doesn't have to be expensive.


Another INC.com article lists an extensive list of ways to motivate employees:

But it isn't as long as this list, which is even longer than the last one:

All in all, good stuff to review for anyone who is trying to lead or thinking about leading.

Leading is motivating because without motivated troopers, you won't win a thing.

Monday, March 19, 2012

Making Quick Use of NSLog

This post has a lot of helpful pointers on using NSLog with Objective-C to dump objects and structures to the debugger console.

http://stackoverflow.com/questions/550195/is-it-possible-to-nslog-c-structs-like-cgrect-or-cgpoint

For those of us used to using Android logging away with "ToString()" methods is second nature and this is how I have been debugging / tracing my iOS applications.

I do appreciate that you can use IFDEF and DEBUG to control the code.


NSLog(@"%@", NSStringFromCGPoint(cgPoint));

...

NSStringFromCGPoint  NSStringFromCGSize  NSStringFromCGRect  

Monday, March 12, 2012

COCOS2D AND XCODE

I have been testing out Cocos2d and after installing it xCode started going crazy.

'New File' started crashing


I have installed cocos2d 1.0.1 on xCode 3.2.6, everything is okay, templates are installed and HelloWorld project compiles successfuly.
But when i need to create a new class,after clicking on "New File" i will get this error twice:
File: /SourceCache/DevToolsIDE/DevToolsIDE-1760/pbxinterface/Wizards.subproj/PBXWizardChooserWizard.m
Line: 1158
Object:
Method: _addWizardProxiesFromBaseSearchPath:subpath:
Assertion failed: _currentMultiWizard == nil


I had to delete any folder called cocos2d in both my user and system Libraries:

/Library/Application Support/Developer/Shared/Xcode/File Templates/



Adding References to Libraries in XCode

It did not work the way that I thought it would.

The tutorial I found that got me past the obvious issues was this:
http://www.theappcodeblog.com/2011/03/07/db-app-tutorial-part-1-create-a-database-using-sqlite/

This tutorial also helped:
http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_4_iPad_Application_(Xcode_4)

And this post was very, very useful figuring out which strategy to go with:
http://www.cocos2d-iphone.org/forum/topic/9308

First iOS Bug Cycle

I ran into a compile error today working on an iPhone application using Cocos2d.

The error was:

[CCTouchDispatcher addTargetDelegate:priority:swallowsTouches:]: unrecognized selector sent to instance

and I entered that into Google.

A few results down I found this link:

Which shows a fix that is totally irrelevant to my issue.

I later figured it out on my own. Learning iPhone development so far is fun, but slower than Android.