Pages: [1]   Go Down
Author Topic: Equivilant of loop() in Objective-C?  (Read 945 times)
0 Members and 1 Guest are viewing this topic.
Georgia, US
Offline Offline
Sr. Member
****
Karma: 5
Posts: 371
Arduino makes my head hurt :(
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I'm trying to make a little Objective-C program real quick (lol been working on this for like six hours now :/), with little to no knowledge of Objective-C

I get that viewDidLoad (iPhone) and awakeFromNib (OS X) are the equivalent of Setup(), but no amount of Googling will reveal what the equivalent of Loop() is...

While it's fun to make apps that do their thing once, and then take their toys and go home, it's not exactly... useful.... to make a notification system that the user has to close and reopen the app for to get the notification telling them something's gone wrong... when opening the app would require them to be AT the computer something went wrong... thus knowing there was a problem anyway... lol smiley-sad
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There isn't such a thing as 'Loop()' outside of Arduino.  There is main() in any type of C.  I don't know specifically about iphone stuff, but If you want a continuous loop, you need to create it yourself.
Logged

http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not familiar with Objective C but with "normal" C

main () {

  while (1) {
    // do stuff here forever
  }

}

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Objective C is to C as C++ is to C, and a quick scan shows that there should be a main() function in the iphone app.
Logged

http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6134
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

loop() is used by the Arduino IDE to help people understand, "this will always be running."

Programming the Arduino and programming an iOS application have very little in common.  Objective-C / CocoaTouch / iOS is fully object oriented system.  While Arduino is more of a procedural system.

You won't find an equivalent of a loop() in Obj-C because it doesn't really exist.  Cocoa applications run in a constant "waiting" state, waiting for events to occur.  This is different from Arduino (or microprocessors in general) because you tend to specify what to be doing at any given time. 

Setting up a while(1) loop in an Objective-C application, to simulate Arduino's loop() would result in a very broken program.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

loop() is used by the Arduino IDE to help people understand, "this will always be running."

Programming the Arduino and programming an iOS application have very little in common.  Objective-C / CocoaTouch / iOS is fully object oriented system.  While Arduino is more of a procedural system.

You won't find an equivalent of a loop() in Obj-C because it doesn't really exist.  Cocoa applications run in a constant "waiting" state, waiting for events to occur.  This is different from Arduino (or microprocessors in general) because you tend to specify what to be doing at any given time. 

Setting up a while(1) loop in an Objective-C application, to simulate Arduino's loop() would result in a very broken program.

Good answer!
Logged

http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are going from a dedicated processor on arduino to a multitasking processor on an iphone. Even if you can program like on arduino, your real time tasks should become much worse. From what I know with limited knowledge, a dedicated system works with other machines, ICs, sensors in real time applications but a multitasking processor works with slow human responses. When a multitasking processor is trying to run a dedicated routine, such as doing something stupid for MS word or Adobe reader, its human operator usually gets upset since the machine loses attention to keyboard pushes and mouse movements and ends up walking away for a coffee break.
Logged


Georgia, US
Offline Offline
Sr. Member
****
Karma: 5
Posts: 371
Arduino makes my head hurt :(
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help, sorry for the delay in answering, the forums did that weird thing where it appends ?token=<string> to the end of the URL and after that I'd come by and refresh the page every now and then but never took the time to troubleshoot why it wasn't loading...

Yea, I already knew I didn't want to do an infinite loop, I figured out what I needed to do, and no, loop() was not it smiley-razz

It's rough jumping from something as easy as Arduino into a mid-level complex project on something that works extremely differently
Logged

Pages: [1]   Go Up
Jump to: