iPhone Reference Errors

February 28, 2009

I’ve decided to give iPhone development a try.  I have a few ideas for cool mobile apps that I’d love to implement so that I can learn a new platform, a new language, and maybe make some money on the side…  However, I’ve remembered what I dislike most about programming – configuration.

I started out trying interface builder and got a basic interface to show up pretty quickly, but it was rather confusing and I didn’t really know what was going on.  Next, I thought I should probably just go through the tutorials in my book (iPhone SDK Application Development by O’Reilly) so that I could get an overview of what’s actually possible with the iPhone.  That way, when I restart building my own apps it will be much faster because I’ll know what I’m doing.

However, I’ve now been trying to get the TextView example in Chapter 3 (Hello World) to work for almost a week!  I typed in all the code correctly (twice, into two separate projects), and it compiles fine, but all I get on the iPhone simulator is a black screen!  After a while, I found the debugger console button in XCode and realized I was getting the following errors:

warning: Unable to read symbols for “/System/Library/Frameworks/UIKit.framework/UIKit” (file not found).
warning: Unable to read symbols from “UIKit” (not yet mapped into memory).
warning: Unable to read symbols for “/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics” (file not found).
warning: Unable to read symbols from “CoreGraphics” (not yet mapped into memory).

These frameworks are quite obviously linked in XCode (because the code completion works and the project compiles fine), but for some reason they don’t show up in the simulator.  After searching online, I’ve gotten to the point where I think it has to do with the way they’re referenced in XCode and that when running on the simulator, the application doesn’t actually compile all the references together; it just starts running without them, so you have to run it from within XCode.   Some people have also said that it had to do with breakpoints in code.  However, I’m running from within XCode and I don’t have any breakpoints, so I think it must be a file location configuration issue.  Now, I’ve had no luck finding any solutions online or by experimenting…

I’ll let you know how it works out; I’m not going to give up on this.

—- Update – March 1, 2009 —-

Well, the Hello World example started working… First thing to note is that the “file not found” type warnings I noted above don’t actually seem to be related to the problem; now that it works, they still show up.

I fixed the blank black screen by cleaning all targets (in the Build menu), then rewriting Hello World to directly use a TextView instead of manually subclassing UIView myself. Also, I didn’t allocate a window object; I just started using it and let the synthesize keyword work for me (before, I was trying to remove Interface Builder from the project, like it recommended in the book. Here’s the code that first worked (I called the project “Arg” because I was so frustrated):

ArgAppDelegate.h:

#import

@interface ArgAppDelegate : NSObject {
UIWindow *window;
UITextView *textView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

ArgAppDelegate.m:

#import
#import
#import
#import "ArgAppDelegate.h"

@implementation ArgAppDelegate

@synthesize window;

- (void) applicationDidFinishLaunching:(UIApplication *)application
{
CGRect screenBounds = [ [ UIScreen mainScreen ] applicationFrame ];

textView = [[MainView alloc] initWithFrame:screenBounds];
[window addSubview:textView];

[window makeKeyAndVisible];
}

- (void)dealloc {
[window release];
[super dealloc];
}
@end

This compiled fine and the text view showed up correctly, etc. Next, I slowly changed the code one line at a time back to the original code, compiling at each step, to see if I could find the line that was causing the problem. Unfortunately, I eventually came back to the original code and it worked…

ArgAppDelegate.h:

#import

@interface MainView : UIView
{
UITextView *textView;
}

@end

@interface ArgAppDelegate : NSObject {
UIWindow *window;
MainView *myMainView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

ArgAppDelegate.m:


#import
#import
#import
#import "ArgAppDelegate.h"

@implementation MainView

- (id)initWithFrame:(CGRect) rect {
self = [ super initWithFrame: rect ];

if (self != nil) {
textView = [ [ UITextView alloc] initWithFrame: rect ];
textView.text = @"Hello, World!";

[self addSubview:textView];
}

return self;
}

- (void)dealloc {
[ textView release ];
[ super dealloc ];
}

@end

@implementation ArgAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
CGRect screenBounds = [ [ UIScreen mainScreen ] applicationFrame ];
CGRect windowBounds = screenBounds;
windowBounds.origin.y = 0.0;

self.window = [ [ [ UIWindow alloc ] initWithFrame: screenBounds ]
autorelease
];

myMainView = [ [ MainView alloc ] initWithFrame: windowBounds ];
[window addSubview:myMainView];
// Override point for customization after application launch
[window makeKeyAndVisible];
}

- (void)dealloc {
[myMainView release];
[window release];
[super dealloc];
}

main.m:


#import

int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"ArgAppDelegate");
[pool release];
return retVal;
}

I hope this helps somewhat to anyone having the same problem. I found this incredibly frustrating and am not entirely happy about my solution here. I still don’t really know why it happened in the first place, so I’m worried it will come up again in the future. Let’s hope not!

Leave a Reply