concept method in category swift

appears as: method, method, methods, methods, A method, The method, The methods
Swift in Depth

This is an excerpt from Manning's book Swift in Depth.

Sometimes you need some flexibility in the shape of polymorphism. Polymorphism means that a single function, method, array, dictionary—you name it—can work with different types.

You use iterators, sequences, and collections all the time when programming Swift. Whenever you use an Array, String, stride, Dictionary, and other types, you’re working with something you can iterate over. Iterators enable the use of for loops. They also enable a large number of methods, including, but not limited to, filter, map, sorted, and reduce.

  • Sequence is the backbone for methods such as filter, reduce, map, zip, repeat, and many others.
  • iOS Development with Swift

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

  • Modify the method to return a blank array:
    func sampleBooks()->[Book] {
        return []
    }
  • Find the sampleBooks method. This method returns the sample data. (Methods start with the keyword func.) When the app is published to the App Store and a new user opens the app for the first time, this method should no longer return sample data.
  • Modify the method to return a blank array:
    func sampleBooks()->[Book] {
        return []
    }
  • Nothing happens yet when you tap the buttons. You’re going to connect the convert buttons with methods in the view controller code that will perform the conversion and display the result.

    To connect a method to a control event in Interface Builder, you’ll need to define the method as an action. An action in simple terms is a method that will be triggered when something happens. In this case, you’ll create an action method in your view controller code that will be triggered when a convert button is touched using the following steps: