Main

January 18, 2007

Cocoa manual binding to selection in NSArrayController

If I want to do this manually binding.jpg
I have to do this
    [vizController bind:@"runData"
               toObject:runsController
            withKeyPath:@"selection.self"
                options:nil];
My RTFM skills lack the voodoo to find where this is documented. Is there perhaps another way?

January 03, 2007

Coredata doubly-linked list

I just rewrote my model to be more sane and suddenly everything works. My next entry on this topic will be how to cleanly implement a doubly-linked list in coredata, I swear. I just need to write a few more unit tests to make sure I'm not missing a few potential edge cases that are giving me that creeping feeling...

I'll also give my thoughts on Rentzch's mogenerator (hint: awesome awesome awesome).

Test Suite '/Volumes/Docs/Users/jonathan/svnCheckouts/main/ipod/branches/xmlRefactorBranch/experiments/MOlinkedList/build/TestMoLinkedList.octest(Tests)' started at 2007-01-03 04:03:41 -0500
Test Suite 'testReorderObjects' started at 2007-01-03 04:03:41 -0500
Test Case '-[testReorderObjects testReorderObjects]' passed (0.000 seconds).
Test Suite 'testReorderObjects' finished at 2007-01-03 04:03:41 -0500.
Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.015) seconds

Test Suite 'TestIteration' started at 2007-01-03 04:03:41 -0500
Test Case '-[TestIteration testForwardIteration]' passed (0.000 seconds).
Test Case '-[TestIteration testReverseIteration]' passed (0.000 seconds).
Test Suite 'TestIteration' finished at 2007-01-03 04:03:41 -0500.
Executed 2 tests, with 0 failures (0 unexpected) in 0.000 (0.016) seconds

Test Suite 'TestNewObjectInsertions' started at 2007-01-03 04:03:41 -0500
Test Case '-[TestNewObjectInsertions testInsert]' passed (0.003 seconds).
Test Suite 'TestNewObjectInsertions' finished at 2007-01-03 04:03:41 -0500.
Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.008) seconds

Test Suite 'TestRemovingObjects' started at 2007-01-03 04:03:41 -0500
Test Case '-[TestRemovingObjects testRemovingObjects]' passed (0.000 seconds).
Test Suite 'TestRemovingObjects' finished at 2007-01-03 04:03:41 -0500.
Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.007) seconds

Test Suite '/Volumes/Docs/Users/jonathan/svnCheckouts/main/ipod/branches/xmlRefactorBranch/experiments/MOlinkedList/build/TestMoLinkedList.octest(Tests)' finished at 2007-01-03 04:03:41 -0500.
Executed 5 tests, with 0 failures (0 unexpected) in 0.003 (0.047) seconds


otest has exited with status 0.

December 13, 2006

Tease

The below means that my doubly-linked list experiment in coredata is starting to work. (Yes, Mark, I figured out the problem... IM/Email me for details!) :) I'm going to clean up the code, but first I'm going to write extensive unit tests... Later, I'll tell you WHY.

I'm such a tease.

Continue reading "Tease" »

September 23, 2006

More Data Smoothing fun and some Open GL

It's been an informative few weeks. While I feel like I've been using very thick unwaxed mental floss, I have been learning some new programming (and some data smoothing...) toys. A review of the OpenGL class at Big Nerd ranch is coming this weekend. I have my reasons for delaying this review. It was a great experience (don't worry Rocco); I just want to see if I can actually use what I've been learning in Atlanta to make something.

So! Below is an openGL rendering of the run data you saw in an earlier post. I'm getting closer to figuring out their smoothing tricks! What you are looking at is a moving average with a 14 point window. This gets us much closer to the Nike+ online graph, but we're not quite there yet. Next I try two things:
1. Throw out (or somehow attenuate) aberrant points.
2. Throw a best fit curve in there.

My goal is to be able to reproduce nike+apple's smoothing relatively reliably so that I can then present options (preferences...) to the user for data smoothing style in my cool new run logging application...

RunSmoothOpenGL.jpg

September 06, 2006

Nike data is smooooooooooth like budda

Looks like the Nike+ data gets... um ... just a little smoothing / averaging. Then again, I still need to test the data importer... You're looking at distance reported per 10 second interval. Raw data babeeee.


run.jpg

September 04, 2006

Loading files from the project directory

If you're (say) working on an xml parser and you want to load some test files from the project directory and perhaps you're using otest and the senTesting framework...

Set-up your tests in the normal way. (Apple has a pdf that tells you how to do this.)
Set the executable's path to that of your project. In my case the executable is "otest" because I'm testing a framework. (Note: The default path for the executable is the build directory, so I guess you could use ../xml/ if you need the path to be the build dir.)
In your test code (let's pretend my xml files are in a subdirectory of my project called xml), you can do something like this in your test code:


NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:\
[@"./xml/2006-08-28 14;14;17.xml" stringByStandardizingPath]];

Since -[NSString stringByStandardizingPath] knows that "./" means "this here directory, yo" it will expand the path for you. This makes your test code all kinds of happily portable for when you release source to the rest of th e world. <--- I'll be choosing a (GPL or LGPL) license and doing that sometime this week for those of you who want to use my super awesome nike+ ipod cocoa objective-c objc xml parser (The previous string is for Googlebot... chew on *that*)

September 01, 2006

cocoa xml parsing

Once you get the hang of it, the NSXmlParser isn't too hard. It's event based. This means that you have to think about your code in terms of each XML open and close tag as being an event that's triggered as your parser reads through the file from top to bottom.

My Nike+ cocoa XML parser and data model is working now. I still have some tweaks and additions to do and then I'll wrap it up in a framework and release it, probably under LGPL.

If you want to see it... this is the place to be.

I added a useful method to NSNumber today as well. If you're not new to objc like I am, feel free to pimp my code. It's below. :)

Continue reading "cocoa xml parsing" »

August 29, 2006

Guess What I'm doing?

You can see by the output of the xml parser that I ... ahem .. uh.. "pause" ... a lot when I'm "running"

What I think I know so far:
time (duration) measurements *.001 = seconds
Raw distance measurements are all in km
The user's distance unit preferences are used for string attributes "7:58 min/mi")
There is a Snapshot list (pauses, when you asked it for a report, powerSong playing) that (unfortunately) doesn't tell the time of the pause. (a pause pauses workout time)
There are Mile and Kilometer splits (!)
The extended data list includes kilometer distance at 10 second intervals.

Continue reading "Guess What I'm doing?" »

August 27, 2006

shhhhh, don't tell anybody

pyobjc is nice for introspection of cocoa objects. :)

NSString has some private regexp methods. Not so surprising, given that coredata lets us validate strings against regular expressions... As always with hidden functionality in apple classes: this might not always work the way you expect and might not even exist in past / future versions of the os...etc.

(UPDATE: this doesn't really behave as I would have expected. See code in the comments that does).

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *test = [[NSString alloc] initWithString:@"hello world"];
NSString *regexp = [[NSString alloc] initWithString:@"hello*"];
if ([test matchesPattern:regexp]) {
NSLog(@"%@ Matches %@", test, regexp);
} else {
NSLog(@"%@ Does not match %@", test, regexp);
}

[test release];
[regexp release];
[pool release];
return 0;
}

[Session started at 2006-08-27 15:01:02 -0400.]
2006-08-27 15:01:02.975 nsstringtest[2239] hello world Matches hello*

nsstringtest has exited with status 0.

July 10, 2006

Python from objective-C

I've been working on getting python objects to instantiate in objective-C and have put together a little demo app as a learning tool for myself. It may not be the best way to python from objc, but it works. I hope it's helpful.

http://www.jonathansaggau.com/cocoa-dev/test.tgz

XCode should build the bundle for you when you hit Build and Go. You'll see a bunch of stuff in the log window that shows you that the python object is firing on all cylinders and that calling the super class that's written in objc works as expected, etc. You'll want to look in the NIB file to see how it's all connected.

How it works:
I subclassed an objc object (JSAbstractTest) in python (Test.py), using of the NIB file to indicate the class hierarchy. You don't necessarily *have* to subclass in this way, you could use a protocol like Bob suggests on the pythonmac-SIG. The protocol method is cleaner, for instance, when you don't really want to implement any of the functionality of the class in objc. This will allow you to do things you might want to do in the compiled language while offloading some functionality to our friendly "batteries included" python. (This is such fun).

Also useful (http://pyobjc.sourceforge.net/doc/intro.php) so we know what the bridge is expecting:

* Python numbers (int, float, long ) are translated into NSNumber instances. Their identity is not preserved across the bridge.
* Python str is proxied using OC_PythonString, a subclass of NSString. A Python str may be used anywhere a NSString is expected, but unicode should be used whenever possible. OC_PythonString will use the default encoding of NSString, which is normally MacRoman but could be something else.
* Python unicode is proxied using OC_PythonUnicode , a subclass of NSString. A Python unicode may be used anywhere a NSString is expected.
* Python dict is proxied using OC_PythonDictionary, a subclass of NSMutableDictionary. A Python dict may be used anywhere an NSDictionary is expected.
* Python list and tuple are proxied using OC_PythonArray, a subclass of NSMutableArray. Python list or tuple objects may be used anywhere an NSArray is expected.
* Python objects that implement the Python buffer API, except for str and unicode, are proxied using OC_PythonData, a NSData subclass. Objects that implement the Python buffer API such as buffer, array.array, mmap.mmap, etc. may be used anywhere a NSData is expected.

Armed with the above information, I coaxed a UDP networking toy written in python to send messages to SuperCollider based on the activity of an image stream coming from my iSight through a quartz composer project. WOO HOO!)

(I've also posted this to pythonmac-SIG, where I'm sure to get comments to refine this post. In the meantime, take this with a grain of salt.)