Having a process sleep for some time

walden systems, objective c, geolocation, ios, CLLocationManager, desiredAccuracy, distanceFilter, startUpdatingLocation, stopUpdatingLocation, delegate, iphone, picture, screen, swipe, iphone, thread, nsthread, uitableviewcell, uitableview, initwithFName, infocellcontroller, nsdate, nsdateformatter nsstring, uuid, time, sleep
Objective-C defines a small but powerful set of extensions to the ANSI C programming language that enables sophisticated object-oriented programming. Objective-C is the native language for Cocoa programming—it’s the language that the frameworks are written in, and the language that most applications are written in. You can also use some other languages—such as Python and Ruby—to develop programs using the Cocoa frameworks. It’s useful, though, to have at least a basic understanding of Objective-C because Apple’s documentation and code samples are typically written in terms of this language.

Sometimes you might need to have your process sleep for some time before or after executing or have it run repeatedly at a set interval. There are many ways to accomplish this task and I would like to discuss one of the ways we are using here at Walden Systems, because we believe this is the most straightforward method to have a process sleep.

Strategy to resize a picture is fairly simple: First, we need to determine what interval we want to sleep for. Second, we need determine if we want the process to sleep before or after executing it's tasks. Third, we need to determine if we want to run repeatedly. Finally, we must change the method header of the method we want to call.

Change the method header by adding a parameter ( in bold below ) :

- ( void ) someMethod : ( NSTimer * ) timer

Here are actual code samples:

To have a process sleep for some time, we will be using the NSTimer object. The NSTimer object will take certain parameters. We will be dealing with three parameters: scheduledTimerWithTimeInterval ( the sleep time in seconds ), @selector ( the method name to execute ), and repeats ( if you want it to repeat). In this example, we will be running a method called "newMethod" every 5 seconds.

    [NSTimer scheduledTimerWithTimeInterval : 5.0f target : self selector : @selector( newMethod : ) userInfo : nil repeats : YES ] ;