concept good time in category ios

appears as: good time, good time
iOS Development with Swift

This is an excerpt from Manning's book iOS Development with Swift.

We’ve looked at constants in brief, but now’s a good time to look at them a little closer.

  • Add a handleTap() action method that will be triggered when the user taps the image. The method increments the image number by 1 and returns it to 0 if it reaches the upper limit of elements in the images array. It then replaces the image in the image view with the next image in the array, as shown in the following code. (You could add a fancy transition here, but let’s not complicate things too soon—all in good time!)
    @objc func handleTap(_ sender: UITapGestureRecognizer) {
        imageNo += 1
        if imageNo == images.count {imageNo = 0}
        imageView.image = UIImage(named: images[imageNo])
    }
    Now, to create the gesture recognizer itself. Every gesture recognizer is instantiated with two parameters, as shown in table 5.6.
    Table 5.6. Gesture recognizer parameters

    Parameter

    Description

    target Specifies the object to receive any gesture events, which in this case will be self—the view controller.
    action Specifies the method to receive notification of the gesture event. You set up the handleTap() method to receive these notifications. The action is specified using a special expression called #selector. Use #selector to pass in the name of the method. Because the #selector expression uses the Objective-C runtime to connect to the associated method, the method will need to be exposed with the @objc keyword.