Search code examples
swiftstoryboarduikit

Is there any type of functionality i can add to a movie app project? Swift, UIKit


I have created this personal project that is a movie mock up called Movly, I have mainly worked within storyboard and have yet to write any code to the app. There is multiple screens to the app accessible by the push of a button, but i am new to what kind of functions i can add in order to make my app an app, rather than just UI


Solution

  • In order to be able to programatically control the view controllers you will need to first create a custom view controller. You can do this by going to File > New > File > Cocoa Touch Class, you can name it whatever you want. Then go to the view controller in storyboard. Press the button 'Show the Identity Inspector' (the rextangle) and then you will see a section labelled custom class. By changing the drop down box next to Class and selecting the view controller you just made you now have access to the view controller programatically.

    If you want to control things on the screen I recommend researching @IBOutlet and @IBAction (sounds complicated but it is quite simple really) and then you can write functions when textFields are changed/ buttons are pressed.

    In order to write a function you need to use the following layout

    func functionName() {
    
    }
    

    If you want to take in some kind of data you can put what it is in the bracket, e.g.

    func functionName(name: String) {
    
    }
    

    and if you want to return something from the function you can use

    func functionName() -> String {
    
    }
    

    When you want to call the function you just do functionName()