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

  • SEARCH
  • Home
  • 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 8205811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:24:39+00:00 2026-06-07T08:24:39+00:00

I am writing an iOS app for the iPhone in Xcode and I have

  • 0

I am writing an iOS app for the iPhone in Xcode and I have created some classes as well as their methods inside their respective .h and .m files (that’s two classes so basically I have two pairs of .h & .m files)

I now I want to start writing my main loop that will be executed whenever the user hits on the play button, but where exactly do I do that ?

Do I do that in ViewController.m ? e.g. inside this method :

- (IBAction)playPressed:(UIButton *)sender 
{
    // main loop executed in here ?
    // or simply message to the main loop to start executing is *sent* from here ?
}

I read about a similar question in here and someone was suggesting AppDelegate. Now would that be AppDelegate.m or AppDelegate.h ? And if that’s the case do I just start writing code or do I include everything inside something like :

int main(int argc, char **argv)
{
   ....
}

in the Appdelegate file?

I tried to simply start instantiating classes and declaring generic methods (not belonging to any particular class that is..) in a game.m file I created and I get a initializer element is not a compile-time constant warning as soon as I try instantiating anything

Any help? Coming from c++ it would really help me to clarify once and for all in which file exactly to write my main loop and whether I should wrap it in some kind of an int main() function..

thanks!

PS :

Just in case it makes any difference, my ViewController will only consist of a play button that would start the execution of my main loop whenever its pressed, and a stop button that would terminate the execution of the main loop

I have created their respective methods in ViewController.m :

- (IBAction)playPressed:(UIButton *)sender 
{
    // 
}

- (IBAction)stopPressed:(UIButton *)sender 
{
    //  ??
}

which are for the time being empty 🙂

  • 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-06-07T08:24:41+00:00Added an answer on June 7, 2026 at 8:24 am

    The programming methodoly on iOS is different from the C++ methodoly.
    In C++ , indeed , you would have to make an infinite loop and get the touches , draw everything , etc at each frame.
    Until the player presses “exit” and you break the loop.
    On iOS , things are done differently:
    You already have a main.m file in which you have a main function.
    That starts up the app delegate. That app delegate tells you when the app finished launching , goes to background , comes in foreground , etc.
    When the app finished launching , you go to your first actual screen.
    There , you ADD subviews. You don’t draw them at each frame. That is done automatically for you once you have added the view to a parent view.
    The programming on iOS is based on events. You don’t have to check for touches and see if the
    touch location is on a button and then call the method of that button.
    Instead , you set a callback method for the button and it’s called automatically for you once the button is pressed.
    Of course , you first need to alloc the button and add it to a parent view.

    Once you get used to this event based programming model , you will for sure like it.
    At the start it may seam very different and maybe it doesn’t make sense to you , but don’t worry.
    Comming from a C++ background is surely a good start.

    Cheers,

    George

    EDIT: In that case , I can give more specific info:
    So , you go from the AppDelegate in your first screen. Let’s call it MainAppScreen.
    Now , you need to add those 2 buttons and set selectors ( callback methods ) for them. I can see you already did that.

    Now :

    - (IBAction)playPressed:(UIButton *)sender
    {
        running = TRUE;
        [self performSelectorInBackground:@selector(myLoop) withObject:nil];
    }
    - (IBAction)stopPressed:(UIButton *)sender 
    {
        running = FALSE;
    }
    - (void) myLoop
    {
        while(running)
        {
           //this is your loop. You can code in here.
        }
    }
    

    Where running is an instance variable in the MainAppScreen class.

    Hope this helps.

    Cheers!

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

Sidebar

Related Questions

I have a iOS developer. He is writing he iPhone app. I am writing
My company is currently writing an iOS app whereby we will display some of
I'm writing an iOS 5 app (in Xcode 4.3, using Storyboards and ARC) that
I'm writing an app in XCode 3.2.3 for iOS 4. In my code, I
I'm currently writing an iOS app and I have many records that I'm writing
I am writing an iOS iPhone app and try to add the following functionality:
After reading: iphone: submit app with iOS 5 and XCode 4.2? I realize that
I'm writing an iPhone app (which will be my first ios app) that has
I am writing an iPhone app, that requires cloud back-end DB storage. I have
I'm writing an iOS app with a table view inside a tab view. In

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.