Oh! Apple

My experience of using iPod Touch, iPod Classics, Mac OSX, Coding in XCode, or anything generally related to Apple

Monday, April 28, 2008

Another Objective C question.


------------
I am pretty new to Objective C, and instead code C# as day job.  iPhone SDK brought me to the Mac coding world.

Even though my ultimate goal is to write an iPhone application, I want to write my code in TDD (Test Driven Deployment) approach.  Because OCUnit doesn't seem to work too well with iPhone SDK beta 3 (I wonder if I have better luck with beta 4 which released today and I already installed it), so I created a regular Cocca application, and then use OCUnit with it.  My goal is to put all my logic in domain objects, have them all fully tested by OCUnit unit tests.  And then eventually use all the objects in the iPhone app.  In fact, I think this approach matches the philosophy  of MVC design pattern, which the domain model objects should be decoupled from the UI (view) and controller (plumping or glue).  Am I on the right track?

So I wrote my unit tests, and one of them looks like this:

- (void) testChordWithInvalidChordName_ShouldNot_BeInstantiated
{
NSString* chordNameToTest;
DeecayChord* newChordToTest;
BOOL isExceptionThrow;

@try
{
chordNameToTest = @"SS";
newChordToTest = [[DeecayChord alloc] initWith: chordNameToTest];


isExceptionThrow = NO;
}
@catch (NSException *e)
{
isExceptionThrow = YES;
}

STAssertTrue(isExceptionThrow, nil);

//[chordNameToTest release];
//[newChordToTest release];

@try
{
chordNameToTest = @"Eb";
newChordToTest = [[DeecayChord alloc] initWith: chordNameToTest];

isExceptionThrow = NO;
}
@catch (NSException *e)
{
isExceptionThrow = YES;
}

STAssertFalse(isExceptionThrow, nil);

[chordNameToTest release];
[newChordToTest release];
}

The code ran OK.  You might notice that I remarked out the two release statement in the middle.  If I unremarked then the code will failed, which got me slightly puzzled.  Maybe I don't quit understand how alloc and init works.  Here's my logic: when alloc got called, some new memory space was set aside for the object I instantiate, and that's why I need to release the memory I occupied at the end.  But since the DeecayChord object got allocated twice for two different objects, I probably need to release each instance once, and thus calls release twice. But instead the code didn't compile if I do so.

Obvious some assumptions I made was wrong, but should someone point out my logic flaw?

Thanks!



Saturday, April 05, 2008

OSX 10.4.8 on VMWare, my attempt

After getting sick and tired of coding on a laptop hot like a stove, I decided to try and see if I can run OSX 10.4.8 (mainly for XCode) on my Quad Core PC running Windows XP. I followed the procedures layout in this web site with the following a few additional steps. Notice that I am using VMWare Workstation 6.0.2 Build 50824:
  • I removed the floppy drive from the VMWare configuration because I don't have it.
  • I pressed [F2] right when the VM bootup, and then change the boot sequence to boot the optical drive first, and then the harddisk.
  • I need to a whole harddisk dedicated for the OSX. But because of VMWare's limitation, I only got to use 128Gb or my 160Gb harddisk .... well ....
  • I need to use the VMWare to repartition to harddisk again even thought it was partitioned by another OSX installation before.
After a few attempts, I finally got the VMWare running. It was a long process, for each failure take about 2 hours. And actually I am starting to doubt if it's worthy, for neither the iPhone SDK nor the XCode 3 works with OSX 10.4.8. In fact I am now downloading XCode 2.5 just so that I can justify keeping this OSX around.

Plus no proper VMWare tools means the performance is slow like hell. So .... you know what maybe I'll just dump this whole damn thing.

Friday, April 04, 2008

Posted a reply

I came across the site, and then post a reply there.

Damn Safari

I just found out that I can't install the new version of Safari because I am stuck with OSX 10.5.1 and Safari require OSX 10.5.2 ... Well, as if I really miss something ....


Thursday, April 03, 2008

Time to reinstall again ....

I've been stuck with the Interface Builder 3.1 Beta (Build 649) for days. I pretty much concluded that the beta version has problem taking a .h controller file. In a perfect world situation, I can use Open Class File to to open .h files and controller object will be created. That was NOT the case I was experiencing. In fact, I strongly believe that drag and drop a .h file in IB should also work, and once again it failed.

I realized that there's a tiny yellow exclaimation at the lower right hand corner of the IB object window, but when I double clicked it, I got no message at all.

I also had hard time getting the XCode 3.0 image I downloaded from Apple web site to work on my Mac OSX. I download it on a PC, and transfer it to the Mac side through network. I got image checksome error. Frustrated, I am planning to do that again in the office and download the image directly on the Mac side.

So now I am restoring the OS to the clean partition image. I will a clean environment NOT running XCode 3.1 beta but instead running XCode 3.0 the stable version. Hopefully I can learn enough on doing Mac OSX application, and then later translate my knowledge to the iPhone development. Dealing with bugging beta XCode 3.1 and beta IB 3.1 is just not funny at all.

And the strange thing is that no one on the Net seems to care. I couldn't find reference on others having problem with the interface builder with the iPhone SDK. Is it really because that they are using OSX 10.5.2 while I am still using OSX 10.5.1 ? Is it time to get a real Mac hardware? Well, at least I need to get some app developed first in order to justify my purchase, just like I want an iPhone app developed in order to justify my purchase of an iPhone.