Go Down

Topic: Equivilant of loop() in Objective-C? (Read 1 time) previous topic - next topic

Valalvax

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 :(

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.
http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

Graynomad

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

main () {

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

}

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

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.
http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

James C4S

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.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com


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!
http://ilektron-x.blogspot.com - Hacking and General Electronics Goodness

liudr

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.

Valalvax

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 :P

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

Go Up