When the triangled shape doesn’t fit in the round hole


I’m writing some iPhony stuff while thinking in Java. I wanna stream an HTTP request over the wire. In Java I’d inject an OutputStream into my class or method and just start writing to it byte by byte. Objective C Cocoa wants to set up RunLoops, setup delegates, and rely on callbacks that pass buffers into the NSOutputStream API. I set on fire and jumped through all of these hoops (after dousing my briefs in Kerosene) but I’m still not getting any data on my stream! Is it because I’m trying to force things to work like Java? Help?

Here’s my test method and impl logic:


-(void) testStreamWriting {
	NSOutputStream *stream = [[NSOutputStream alloc] initToMemory];
	[stream setDelegate:myStreamDelegate];
	[stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
	[stream open];
	NSData *_data = [stream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
	STAssertNotNil(_data, @"Stream delegate should have written data");
	[stream close];
	[stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
	[stream release];
	[data release];
}

@implementation MyStreamDelegate
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
	switch (streamEvent) {
		case NSStreamEventHasSpaceAvailable:
		{
			const uint8_t stuff[2] = {1,2};
			[theStream write:stuff maxLength:2];
			break;
		}
		default:
			break;
	}
}

@end

OCMock Works in an iPhone Project!


I hit a bit of a snag getting around the “image not found” error when I tried to bring OCMock into my iPhone dev work. (I’m using Google’s iPhone testing tools here.) Between various searches I found a few more people having the same trouble while one or two claimed success. So I didn’t give up hope. I finally tripped and fell into Mitch’s World and found my answer! Thanx Mitch! The solution is to add/copy the OCMock.framework folder into /Library/frameworks and reference it from there. It feels like such a hack and I know I’ll get into trouble this way but it got my tests running again!

Meant to add a link to this page. These Atomic guys seem like they can put a spin on the whole iPhone SDK experience.