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.

Tuesday, October 11, 2011

Pages From 99% I liked

This piece on the power of uncertain times was a good read:

This one about 25 insights on how to be a better writer was also worth a read:

And this about how a talented executive learned to lead:

And last but not least, 12 attributes of a really great place to work:

Thursday, October 06, 2011

Android Application Trouble with "android.hardware.screen.landscape"

The Problem:

When you upload your APK to the Android Market it is flagged with an awful and mysterious permisison called "android.hardware.screen.landscape" and this limits your devices to a very small number.


The Issue:

You have a landscape application that does not support portrait. However, your application will run on many devices that are rotated even if they do not specifically have the landscape hardware (ie, no portrait mode?)


The Solution:

Add the following line to your AndroidManifest.xml and everything will be fine.




Notes


At some point Google added this as a filter during upload. It came on and off for a while depending on what SDK you use. Various people have posted / Tweet'd that it can be fixed with an SDK upgrade. That may or may not be true on your platform or at the time you read this.

Monday, July 25, 2011

Saturday, July 23, 2011

Android Development on Windows

If you are doing any Android development on Windows 7 OS you should install these Codecs:


They will really help you get around inside the media that Android APK are packaging, like OGG files.

Follow me on Twitter @corytrese