0

I'm trying to make a very simple app in Xcode, basically each day that a user is using the app, a new message will appear in the center. The trouble is, I'm using an index to attempt to make a simple counter. However when it first starts, the app doesn't load until it reaches the final quote. When I attempt to create a function where it pauses for a certain amount of time, the app waits until that time has fully passed for each individual index so that when it loads it still only shows the last quote.

If anyone has any suggestions on how to create a pause that won't freeze the app, or for a better method for doing this, it would be greatly appreciated.

This is all that I pretty much have for the coding right now:

@IBOutlet var quoteLabel: UILabel!
var quotearray = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"]

override func viewDidLoad() {


for index in 0...9 {
quoteLabel.text = (quotearray[index])
    }

1 Answers1

0

Declare:

   func delay(delay:Double, closure:()->()) {
        dispatch_after(
            dispatch_time(
                DISPATCH_TIME_NOW,
                Int64(delay * Double(NSEC_PER_SEC))
            ),
            dispatch_get_main_queue(), closure)
    }

Use this function for pause as:

delay(3.0) {
 // your code here
}

Store the index in UserDefaults and increment everytime you show your quote.

Sahil Kapoor
  • 10,322
  • 10
  • 57
  • 82