Calculator (CS193P)

…And per that last post, I finally have the code in the way that I want it.  I think I’ll eventually getting around to showing some screenshots of what’s happening with the memory leak, but I think I’ve gotten everything correct thus far.  I’m uploading the working code as an Xcode 4 project, without any sort of build data with it.  You may need to fire up your copy of Xcode and adjust the build settings to not use iOS 4.3 but provided the API doesn’t change too drastically, you should be good.  Grab that zip file, here.
Also, I’m leaving out the XIB files– I think you can grok your own interface design, no need to steal my binaries.  If you have any questions, I’d be happy to try and help you out but really…it’s all stuff explained in the lecture or in the Assignment 2 request sheet.

What I will do is expose a bit of code here that gave me the most frustration.  It was a class method designed to evaluate an algebraic expression by spawning a working copy of itself to sub the vales of the variables in and return a result.  It was a bit of work to get my head around abstractly, and I think the resulting code is quite efficient and nice (and doesn’t leak!).

+ (double)evaulateExpression:(id)anExpression usingVariableValues:(NSDictionary *)variables
double dubNum=0;
CalculatorBrain *workerBrain = [[CalculatorBrain alloc] init];
for(id item in anExpression)
if ([item isKindOfClass:[NSNumber class]])
NSNumber *workingNum =item;
[workerBrain setOperand:workingNum.doubleValue];
else if ([item isKindOfClass:[NSString class]])
NSString *workingString = item;
if ([workingString hasPrefix:VARIABLE_PREFIX]) {
NSString *subFromDict = [variables objectForKey:workingString];
[workerBrain setOperand:subFromDict.doubleValue];
dubNum = [workerBrain performOperation:item];
[workerBrain release];
return (dubNum);

Anyways, I’m proud enough that I’m heading on to Assignment 3 which implements a Graphing mode. Hopefully I’ll get the instruments post, as well as a bit of a video demonstration of the Calculator in action up here.

iOS 4 – Some Glitches…

iOS4 is out today and I gotta say I’m having a bit of a love/hate relationship here. First off, I lost my damn contacts. I didn’t actually lose them but when I went to use my smartphone in a smart manner it didn’t really work. I ended up having to do a hard-sync to a more out of date version of my cloud version of Google Contacts. Talk about frustrating…and to my knowledge this issue still isn’t solved. I also had some wonkiness in the Clock app of all things– titlebar flashed green as if I was in a call and it kinda got the timer numbers all screwy there. I did a hard reboot and all is good now…I think.

But on to the OS pack– it’s very fast on my 3GS. I like the new draw animations, and the addition of Folders for droppings Apps is great. Even the spellcheck is a nice addition because I’m tired of typing the word “ducking” all the time. Use your imagination.

Here’s my last gripe: Freaking multi-tasking. Apple, why would I want to leave the Settings app up, or Messaging? How about the damn Clock app? Why don’t you have a whitelist or at least a preference setting that would allow me to specify a “Never multitask” or “Always quit (for real)”?? I can only assume there’s an iOS4.1 update around the corner.

I noticed this release contains the same serial as the 4.0 GM Seed that we developers had access to. I had it loaded, but maybe I’ve got some glitches because of that…oh well.

More as it develops…