views:

59

answers:

1

Hello!

It will be a noob question, but i'm getting crazy with this. I've read a tons of topics but i think i am missing something main.

I`ve created new cocoa app project, did not change anything, just add next code to main.m

int main(int argc, char *argv[])
{
    NSView *superview = [window contentView]; 
    NSRect frame = NSMakeRect(10, 10, 200, 100); 
    NSButton *button = [[NSButton alloc] initWithFrame:frame]; 
    [button setTitle:@"Click me!"]; 
    [superview addSubview:button]; 
    [button release];
    return NSApplicationMain(argc,  (const char **) argv);
} 

During compiling xcode tells me that window undeclared. I understand that instead of window should be name of my NSWindow object, but i don`t understand which name has NSWindow which automatically created in MainMenu.xib file.

Please help, i`m almost ready to broke the wall with my head.

+1  A: 

At that point no window has even been created yet. The code generated by Xcode gives you window in your projects application delegate, so add your code to -applicationDidFinishLaunching: in YourProjectAppDelegate.m instead.
I recommend to start with some introductory material like Hillegass where such things should be covered in detail.

Georg Fritzsche
Thank you. I`m not a developer, its just a hobby, besides my english skills not so perfect and sometimes it is difficult to understand some special developer things and there are only two books about objective-c in russian.
Alex Molskiy
@Alex: I guess that sounded harsher than it was intended. As your english sounds fine i somehow assumed lazyness; sorry if i misinterpreted.
Georg Fritzsche
May be you are right :)
Alex Molskiy