Aaron to Wall: Frack You
These are the moments that keep you going, that sustain you through the impossible times. Just now, I’ve solved the stupid saving problem. And my God, it’s simple simple simple.You need to use one of three methods to enact a Save motion; the most common appears to be dataOfType:error:. That’s the one that I used, and indeed that’s appropriate for this situation. I’ve got a wired-up Save command, and the contents of an instance variable that I want to stuff into a file.
The Wall
Flush from my unexpected success with the “junk data” coming from my calculator class, I decided to step back and take care of some of the boring bits: document opening and saving, undo, printing, copy and paste, and drag and drop. This is the stuff that people expect to be able to do with any Mac application, so I have to make sure it’s there!
I started with saving. Maybe because it seems so simple in the Hillegass book, I thought this wouldn’t be a problem.
A Wasted Day?
When I set out writing this blog, I wanted to ensure that I was writing some code every day, even if only a little. Work has been slow lately, so this hasn’t been too hard to accomplish. Sadly, I’d also expected to be making more progress in a day than I accomplished today. Still, perhaps the failures are as worth recording as the successes.In this case, I was setting out to knock off some more of the bugs that afflicted my initial implementation.
Searching NSString Before the Insertion Point
Although I was gratified to have achieved my basic objective — getting a mathematical expression as a string to actually spit out a numerical answer — it felt like a kludge. The biggest sacrifice I made right away was to limit my calculations to appearing as the last bit of text in the document. Recall my method for grabbing the expression string:
aRange = [[self string] rangeOfString:newline options:(NSBackwardsSearch)];
The [self string] means that I’m looking at the whole contents of the NSTextView, going backwards till I find a carriage return.
Making the Left Side of = My Bitch
That’s really what it comes down to. Whatever the user has entered into Napkin, if they hit the “=” sign, I want to snatch up the equation they put in and spit back an answer. That’s easier said than done, since there are a lot of situations that I have to contend with. Some that occur to me include:
(2+3)/7 = My age is 2008 – 1973 =
For now, I’m only going to be dealing with the first example, where the only thing on a line is the calculation.