Category: Xcode

Spooky xcode thread error

Upgraded to Xcode 3.1.3 pre-release and suddenly my iPhone app didn’t build!

I recieved this error:
bool _WebTryThreadLock(bool), 0xe755f0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now…

As you might know (or understand by this post) I am pretty new to Objective-C. Anyhow after some twists and turns I found out that if I pull the textMessage.text in sendMessage method it works. Why is this?

– (void) sendMessage {
// Override point for customization after application launch
[progressIndicator setHidden:NO];
[progressIndicator startAnimating];
[buttonSend setHidden:YES];
NSLog(@”Load message from UI: %@.”, textMessage.text);
textMessage.text = textMessage.text; // Spooky. If I remove this line I crash! Why?
[NSThread detachNewThreadSelector: @selector(popAway) toTarget:self withObject:nil];
– (void) popAway {
NSLog(@”Send started.”);
NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ];
NSLog(@”Load message from UI.”);
NSString *message = [ textMessage.text stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding ];
NSLog(@”Load mobile preference.”);
[pool release];