After struggling with formulae that convert degrees longitude and latitude to meters, I found a much better way to get annotations to fit on a Map View, thanks to this site:
http://codisllc.com/blog/zoom-mkmapview-to-fit-annotations/
Core Data is really great, but if your app crashes without warning it can be a major headache. Replacing the default error handling code with this more involved approach saved me hours of time debugging:
http://www.designcodeexecute.com/2009/08/28/iphone-sdk-coredata-debugging-error-1560-1570
This is an easy one to seasoned X-coders, but one that tripped me up a few times when I first got started.
BAD CODE:
-(void) makePhotoFromImage: (UIImage )image;
ERROR:
can not use an object as parameter to a method
TRANSLATION
You probably forgot the “pointer” asterisk in your declaration. Should be:
-(void) makePhotoFromImage: (UIImage *)image;
I’m pretty new at Xcode and Objective C, so there may not be a one-to-one correspondence here between errors and the most probable cause, but this helps me so it may help you.
This will be a work in progress; I’ll keep adding as I go.
CODE (from header declarations): CreatorHuntView *detailController;
ERROR: error: expected specifier-qualifier-list before ‘CreatorHuntView’
TRANSLATION/PROBABLE CAUSE: You forgot to import the file in the header file; e.g. #import “CreatorHuntView.h”
Check out this blog entry on Designweenie if you are a Mac user that uses OmniGraffle to design mySQL databases.
One important note: you will need to run AppleScript Editor in 32-bit mode if you are using Snow Leopard (Mac OS X 10.6). Check the 32 bit box in the Get Info box of the application.
Although I started writing this as a cheat-sheet for myself (after many hours of struggling with this by trial-and-error), I figured it would be helpful for other iPhone developers who’d like to take a mySQL database online and migrate it to their current iPhone project. While other tutorials cover how to read the database into the application from the coding point-of-view, this is just to make sure you get your data uncompromised from your existing mySQL database into a new SQLite DB that your iPhone app can read.
First of all, here’s what I am currently using; I am including versions in case that’s relevant to your situation:
You can try other solutions for importing the data into a SQLite format, but I’ve had the best luck with Mauricio Piacentini’s SQLite Database Browser. Other options you might want to try include a Firefox plugin.
Here are the steps, using SQLite Database Browser:
CREATE TABLE dictionary ( id int(11) NOT NULL auto_increment, word varchar(100) NOT NULL, adjective tinyint(1) NOT NULL default '0' COMMENT 'is an adjective', noun tinyint(1) NOT NULL default '0' COMMENT 'is a noun ', intro tinyint(1) NOT NULL default '0' COMMENT 'is an intro', PRIMARY KEY (id), UNIQUE KEY words (word) );
You’ll want to edit this to remove pretty much everything but the most basic information and normalize the data types to SQLite 3 Data Types, which are TEXT, NUMERIC, INTEGER, REAL, or BLOB. Your CREATE TABLE should look something like this:
CREATE TABLE dictionary( id INTEGER PRIMARY KEY ASC, word TEXT, adjective INTEGER, noun INTEGER, intro TEXT );
I was using id as a primary key so I’ve added “PRIMARY KEY ASC” after “id INTEGER”. (Primary Keys are aliases to row IDs in SQLite, if you have questions read this.)
However, I’ve noticed that the SQLite Database browser exports SQL in the even more simplified format with no datatype specification as such, which also seemed to work for me and may work just as well for your needs:
CREATE TABLE dictionary (id, word, adjective, noun, intro);
you're
you''re
INSERT INTO dictionary VALUES(305, 'ne''er-do-well', 0, 1, 0);
BEGIN TRANSACTION;
COMMIT;
Again these steps were derived mostly by trial-and-error, so there may be issues particular to your DB that these guidelines didn’t solve. Please feel free to add any corrections, tips, and questions to the comments area.
Also, I know that with the iPhone OS 3.0, Core Data can take care of a lot of database functionality for you. I’d love to hear how people made the transition, and especially how anyone got a pre-existing SQL database into a Core Data store.