Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 611965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:50:30+00:00 2026-05-13T17:50:30+00:00

It just sits there… How do I run code independently of UI actions (as

  • 0

It just sits there… How do I run code independently of UI actions (as in, not only in response to a button push)? I’m trying to initialize some objects and run some scripts BEFORE i awakeFromNib. How do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:50:31+00:00Added an answer on May 13, 2026 at 5:50 pm

    In Cocoa, what is the purpose of the main.m class?

    None, because there isn’t one.

    For one thing, the .m file is not the class. Neither is the .h. The practice of putting a class’s @interface in a .h (header) file and its @implementation in a .m (implementation) file is a convention, nothing more. It’s a good convention, but it’s not enforced by the language.

    So, a .m file contains zero or more class implementations. Usually, it’s exactly one. Sometimes it’s two, where the other is a small private class whose @interface is also in the same file.

    main.m contains no classes. It usually only contains one function, which is named main.

    main comes from C (of which Objective-C is a superset), and is the entry point of the program: It’s where the program starts running. Everything happens here, or in a function called from here. A command-line tool will usually exit here as well, by main returning.

    Most main functions in Cocoa apps are the default one that comes with the project template; this implementation simply tail-calls NSApplicationMain, which sets up the shared NSApplication object and starts it running. That function never returns; when the user quits a Cocoa app, the process simply exits.

    You may want to read this list of important facts about Cocoa and Objective-C that I wrote. It sounds like you have some misconceptions (probably brought over from another framework you’re more familiar with) that that list can clear up for you.

    How do I run code independently of UI actions (as in, not only in response to a button push)?

    That depends on when you are trying to do it. A periodic action, for example, would be a job for a timer.

    I’m trying to initialize some objects and run some scripts BEFORE i awakeFromNib. How do I do this?

    You could do it in initWithCoder:, which is sent to every non-view-layer object instantiated from an archive, including yours. Nibs are archives, too.

    You might also consider being the application delegate and implementing a applicationWillFinishLaunching: method.

    A third way would be to stuff the code in main. Note that practically any Cocoa code here is likely to log “no autorelease pool” warnings unless you wrap it in an @autoreleasepool statement; other solutions don’t have this problem because NSApplication has already created an autorelease pool for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 models: ParentModel: 'just' sits there ChildModel: has a foreign key to
just a quick question: I am a CS undergrad and have only had experience
Trying to make this simple applet - the first part just creates a simple
I'm trying to get a Rails (version 2.3.5) app set up to run RSpec
Just what the title says, I need to change the password for an existing
Just looking for the first step basic solution here that keeps the honest people
Just bought a 2.4GHz Intel Core 2 Duo iMac with 2GB of memory and
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.
Just how much slower are events? I have written a streaming XML parser (that
just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.