2718.us blog » objective c http://2718.us/blog Miscellaneous Technological Geekery Tue, 18 May 2010 02:42:55 +0000 en hourly 1 http://wordpress.org/?v=3.0.4 NSDocument beginSheet on a New Document http://2718.us/blog/2009/07/17/nsdocument-beginsheet-on-a-new-document/ http://2718.us/blog/2009/07/17/nsdocument-beginsheet-on-a-new-document/#comments Sat, 18 Jul 2009 02:49:43 +0000 2718.us http://2718.us/blog/?p=161 This took over an hour for me to hash out, in part because there are a few mailing list archives and whatnot that I came across while looking into this issue that led me down the wrong path.  I have an NSDocument subclass for which I want a sheet to display modal to the window on initialization of the window.  It seemed that no matter what I did to try to get it to work, what would happen was the sheet would show up detached from the document, then the document would show up on top of it.

… because I had “Visible At Launch” checked for the NSPanel that is my sheet in Interface Builder.  Unchecking that fixed everything, no RunLoop or otherwise delayed-running machinations needed.

]]>
http://2718.us/blog/2009/07/17/nsdocument-beginsheet-on-a-new-document/feed/ 0
XML-RPC and Mac Programming, Revisited http://2718.us/blog/2009/04/26/xml-rpc-and-mac-programming-revisited/ http://2718.us/blog/2009/04/26/xml-rpc-and-mac-programming-revisited/#comments Sun, 26 Apr 2009 05:59:02 +0000 2718.us http://2718.us/blog/?p=139 I might have been wrong, or at least not entirely right, when I said that AppleScript’s XML-RPC was doing something screwy with UTF8-encoded responses to XML-RPC requests.  I’m not sure if it’s LiveJournal (and other sites based on their code), or if it’s something inherent in XML-RPC, but whether I make the XML-RPC calls in AppleScript (with its built-in mechanism for calling XML-RPC), in Python (with xmlrpclib), or in Objective-C/Cocoa (using the XML-RPC framework from here), things that I was expecting to be UTF8 strings were instead coming through as binary data that needed to be decoded.

Beyond that point, however, AppleScript was severely lacking in that the form in which that data was stored made it entirely unusable–AppleScript couldn’t convert it, couldn’t pass it off to an Objective-C method, etc.  As suggested in my previous post, there was a way around it, and messy though it was, I went about implementing that fix and by and large it worked (though it exposed another minor bug elsewhere).  But it really bothered me.

So I went back to looking at trying to integrate Python code into my tangled web of AppleScript and Objective-C, since XML-RPC is fairly easy in Python, though not quite as easy as in AppleScript.  And, eventually, I succeeded in integrating a class written in Python into the program (documentation on using the PyObjC bridge in this direction is woefully inadequate), using a less ineligant means of fixing the binary UTF8 data—

unicode(theResult.data,'utf-8')

(and Python also allowed me to generically recurse through the entire return structure, which wasn’t possible in Applescript).  Unfortunately, this version was substantially slower than the broken-Unicode version and not particularly any faster (perhaps slower) than the AppleScript-fixed Unicode version.

This led me to look for a way to do the XML-RPC stuff in Objective-C.  Now, mind you, the single thing that enabled me to even think about writing a client for LJ for Mac was seeing just how easy AppleScript XML-RPC calls were.  While I didn’t particularly want to try Python, the XML-RPC calls there weren’t that much harder.  But going to Objective-C for XML-RPC…  that’s a fundamental change in the program.  At least, to me.

I did a lot of Googling and found that there are actually a few XML-RPC frameworks for Objective-C/Cocoa (the one I used by Eric Czarny, the one from Brent Simmons, the Mulle one, XMLRPCObjC, SOPE).  Supposedly, there’s a way to do it with Apple’s own Cocoa stuff, but the documentation is woefully inadequate (none of the frameworks have amazing and wonderful documentation, but Apple’s documentation is bad) and almost every mention of it that I found on mailing lists and discussion boards said it was broken.  In the end, my framework choice was largely dictated by licensing, though there were also some issues with usability and dependencies.  As with AppleScript and Python, the UTF8 strings weren’t coming through as strings, but as NSData objects, which are fairly easy to convert with

[[NSString alloc] initWithData:theObject encoding:NSUTF8StringEncoding]

Recursing through the entire returned structure wasn’t particularly any harder in Objective-C than in Python.

The best part is that the resulting client with Objective-C-based-XML-RPC feels faster than the non-Unicode AppleScript-based-XML-RPC client.  In vaguely-objective tests (determine a set of steps that constitute a test and record the total time for just the XML-RPC calls in those steps, run the test several times under each app, compare times), the new version is measurably faster than the old version.

Bottom lines: (1) expect a new version of asLJ in the next few days, as soon as I get feedback from my early testers; (2) expect another post or two about other things I’ve learned in rewriting the XML-RPC aspect of asLJ in Objective-C.

]]>
http://2718.us/blog/2009/04/26/xml-rpc-and-mac-programming-revisited/feed/ 0
asLJ: a Mac OS X 10.5+ LiveJournal Client http://2718.us/blog/2009/02/09/aslj/ http://2718.us/blog/2009/02/09/aslj/#comments Mon, 09 Feb 2009 08:24:18 +0000 2718.us http://2718.us/blog/?p=121 asLJ is a new client for Macs running Leopard that easily handles multiple accounts on LiveJournal and other LJ-based sites and facilitates cross-posting across accounts. Release notes and download link are in [info]aslj_client. The community for users is [info]aslj_users.

(As it is very LJ-centric, most of the information about it will be over at LJ, in the two places linked above, but there is a page for it here, as well.)

]]>
http://2718.us/blog/2009/02/09/aslj/feed/ 0
NCIDStatusBarMenu v0.1a Release Notes http://2718.us/blog/2007/10/14/ncidstatusbarmenu-v01a-release-notes/ http://2718.us/blog/2007/10/14/ncidstatusbarmenu-v01a-release-notes/#comments Mon, 15 Oct 2007 03:07:40 +0000 2718.us http://2718.us/blog/?p=49 Initial Release Notes for the first release of NCIDStatusBarMenu (copied into the blog)

  • This is the first thing I’ve ever written with Objective-C/Cocoa and the first OS X-native GUI app I’ve ever written. This is also the first release. There are probably bugs.
  • The preferences have no default settings yet.
  • The program won’t create the log file if it doesn’t exist.
  • If you don’t have Growl, you will be prompted to install it at some point. Install it.
  • The lookups to whocalled.us may make use of /usr/bin/curl, but I think that’s in the base install of OS X 10.4+
  • Requires OS X 10.4+
]]>
http://2718.us/blog/2007/10/14/ncidstatusbarmenu-v01a-release-notes/feed/ 0