SQLite Access in Objective-C and Cocoa - objective-c

I am in the process of learning Objective-C for Mac/iPhone development and decided to try and write something useful without looking at the bible (Aaron Hillegass: Cocoa Programming 3rd Edition).
I'm writing a simple puzzle game. The data that defines the levels is stored as a string in a SQLite database and read into a level object with this line of code:
tempLevel.levelData = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
I have two other lines that read in other properties from the database (integers this time, not strings) and they work fine so I am wondering if anyone can help me with the problem.
When this line of code executes I get the following error:
*** +[NSString stringWithUTF8String:]: NULL cString
I would greatly appreciate any help you can give. If you need any more information I would be glad to provide it.
Thanks!

Not really an answer, but there's no good reason to deal with sqlite directly when there are some great wrappers available:
http://cocoaheads.byu.edu/resources/sqlite

Most likely it is an error in compiledStatement. As a general point, you should check that you get an actual value from sqlite3_column_text first, since getting back NULL is often the "correct" response to what you ask for.

Related

Best way to store and reference a list of 3rd party API keys and constants in code?

I've got a list of constants for numbers api's that I'd like to collect in one location in code and am wondering about the best ways to do this. Here's what I have so far..
A static array with all the constants...
static NSDictionary* kApiConstants =
[NSDictionary dictionaryWithObjectsAndKeys:
#"crittercism-app-id", #"myAppId",
#"crittercism-key", #"myAppKey",
#"crittercism-secret", #"mySecretKey",
#"content-server-url-dev", #"http://my-dev-url/",
#"content-server-url-stg", #"http://my-staging-url",
#"content-server-url-pro", #"http://my-production-url",
nil];
I then have a macro for quick retrieval of items in the array...
#define MYAPIKEY(x) [kApiConstants objectForKey:x]
I like this setup. It makes code cleaner to read overall and makes merging easier for my purposes between branches in our git repo. One feature I would love to have at build/compile time is if a string is not in the dictionary then a build and/or compiler error would get flagged to indicate this.
I'm sure others have run into this situation before with so many 3rd party libraries, sdk's and what have you in a project it's hard to keep track of them all. For those willing to share what systems have you come up with to help with this?
In my case this is for an iOS project but the situation applies for any kind of project really.
What advantage do you see in using a dictionary over just making them constants on their own? Your wish:
One feature I would love to have at build/compile time is if a string is not in the dictionary then a build and/or compiler error would get flagged to indicate this.
would be solved by just making them constants in their own right.

XCode RSS Feed Won't parse properly

I followed a tutorial (which I'll link at the bottom) that I got from an old StackOverflow answer to parse an RSS feed into a UITableView. The tutorial is a bit outdated, but only a few methods were deprecated, and I replaced them with (what I hope are) the appropriate newer methods. However, I'm running into some trouble, not with the replaced methods, but with the parser not starting the parsing process. There are some NSLogs sprinkled throughout to give clues as to what is going on, and my parser isn't calling parseDidStartDocument:, it's just running and returning the last two NSLogs ("All Done!" and "stories array has %d items"). If someone could take a look at the code and tell me why it's not parsing, I would be very grateful. If you need to see some of my code, just let me know which parts you'd like to see, and I'd be happy to edit it in.
http://gigaom.com/apple/tutorial-build-a-simple-rss-reader-for-iphone/
oooh that tutorial is way out of date - written in 2008!
Try this tutorial, written for iOS5 instead.

Weird function names in Quartz Core: what gives?

Out of curiosity, what may the rationale behind these function names (found in Apple's Quartz Core framework) be?
ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv()
ZNK2CA6Render9Animation9next_timeEdRd()
ZN2CA11GenericRectIiE5insetEii()
Do you think the developers somehow encoded argument types in function names? How do you find yourself putting "EP19" in there in the course of day-to-day coding? In what circumstances do such barely readable function names actually help you read code and otherwise be more productive?
Thanks in advance for any hints, and Merry Christmas!
These 'mangled' names are automatically generated by the C++ compiler and indeed encode type information.

How do I create a Numbers spreadsheet using objective-c?

I'm writing a Cocoa application and I'd like to generate a Numbers spreadsheet from my application using Scripting Bridge. I've generated the Numbers.h file and linked the ScriptingBridge.framework per the directions in Apple's Documentation. Below is the code I'm using to try to simply create a Numbers document and save it.
NSString *path = #"/Users/username/Desktop/Test.numbers";
NumbersApplication *numbers = [SBApplication applicationWithBundleIdentifier:#"com.apple.iWork.Numbers"];
[numbers activate];
NumbersDocument *document = [[[numbers classForScriptingClass:#"document"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:project.title, #"name", nil]];
[[numbers documents] addObject:document];
[document saveAs:nil in:[NSURL URLWithString:path]];
The code compiles and runs and when I try the saveAs:in: method I get the following error:
-[SBProxyByClass saveAs:in:]: object has not been added to a container yet; selector not recognized [self = 0x2005912e0]
Is there something else I have to do besides adding the document to the [numbers documents] array?
I'm open to using AppleScript, but I'd prefer to using the Scripting Bridge if I can.
Ehh, Numbers scripting with SB; two black arts for the price of one. I would suggest trying to do it in AppleScript first, in order to narrow down the problem a bit.
If it breaks in AS too, then either you've phrased the commands wrongly or there's a problem in Numbers. Since most application scripters use AppleScript, you'll find it easier to get help if you can present code they'll recognise.
If it works, then either your translation of the commands to ObjC is incorrect or there's a problem in SB. Having a working example in AS will provide a starting point for figuring out where things are going wrong.
You might also look into objc-appscript, which provides a more reliable, less obfuscated alternative to SB. Its ASTranslate tool makes it easy to translate working AS commands to ObjC syntax.
Numbers doesn't yet support creation of documents via Applescript. You have to use GUI scripting. The new version of Numbers is supposed to be out Jan 6, 2011 and (hopefully) will fix its severely limited Applescript support.

Can I programatically get hold of the Autos/local variables that is shown when debugging?

Im trying to build an error-logger that loggs running values that is active in the function that caused the error. (just for fun so its not a critical problem)
When going in break-mode and looking at the locals-tab and autos-tab you can see all active variables (name, type and value), it would be useful to get hold of that for logging purposes when an error occur and on some other occasions.
For my example, I just want to find all local variables that are of type string and integer and store the name and value of them.
Is this possible with reflection? Any tips or pointers that get me closer to my goal would be very appreciated.
I have toyed with using expression on a specifik object (a structure) to create an automapper against a dataset, but I have not done anything like what I ask for above, so please make me happy and say its possible.
Thanks.
If you're looking to reproduce the behavior of the debugger, then you may want to be a debugger. See the Visual Studio Extensibility Learning Center. In particular, see the links under "Debuggers".