Swift (general) Flashcards
What is a UIEelement?
It’s an object class in the view controller (eg a button)
What is an @IBAction?
@IBActions are connected to UIElements (eg a button). They call code when the button is tapped. Connects ViewController (eg with button) to the code - eg button is controlling the code execution.
What is an @IBOutlet
@IBOutlets are connected to UIElements (eg button). They change the look of the UIElement (button) in the ViewController. Connects code to ViewController - eg the code changes the look of the button.
What is UINavigation Controller?
UINavigation Controller is a class that lets you navigate between different UIViewControllers (ie screens). It can handle a stack of different UIViewControllers (ie the screens). The first stack is called the rootViewController
What does AVFoundation framework do?
It deals with audio and video
eg AVAudio class
What is an AVAudioSession?
Need to record and playback audio. There’s just one that exists for the entire time the app is running. You grab it with the .sharedInstance() method - ie AVAudioSession.sharedInstance()
What does NSSearchPathForDirectoriesInDomains
Creates a list of directory search paths
What is delegation?
When you get one object to do the job of anothers
What is a gesture recogniser?
A subclass of UIGestureRecogniser that detects a specific touch sequence and calls an action on its target when the sequence is detected. eg pinch, swipe, tap
What is the scene dock?
It’s the row of icons above the canvas (ie ViewController)
What does ctrl + dragging from ViewController (yellow circle) to the UIElement (eg button) do?
It connects an @IBOutlet
What does ctrl + dragging from a UIElement (eg button) to the ViewController (yellow circle)?
It connects an @IBAction
What is a tag?
Found in the Attributes Inspector, a tag is an integer that you can use to identify View objects in your app
(Related method is -[UIView tag]
What is a framework?
A framework a shared library of of code that includes associated resources such as interface files and images (eg MKMapView) (can be added in xcode using imports UK for eg)
What is UITabBarController?
UITabBarController is an array of view controllers. It also has a tab bar at the bottom of the screen with a tab for each view controller in its array.
What is a function?
A function is a self contained piece of code that performs a specific task. The three types in swift are Global Functions, Nested Functions, and Methods
Where are Global Functions?
Global Functions are functions that can be called from anyplace in an app (ie in a class) (eg print, min, and abs)
What is a Method (function)?
When a function is defined in, and associated with a particular class, it is called a Method.
When do you use dot syntax?
eg append is a method. A function that’s part of the String class. So we call the append Method on an instance of the string class using dot syntax
What is a class?
A class is a unit we use to package together related data and functionality.
What is an instance of a class?
One of its moving parts. (eg think of Mouse Trap. One of the wheels is an instance of a class)
What makes up a class?
A class is made up of properties and methods
eg properties
let title: String
let releaseYear: Int
eg methods (every class needs an init method)
init()
Breakdown:
class Movie {
let title: String
let releaseYear: Int
init(title: String, releaseYear: Int) {
self.title = title
self.releaseYear = release year
}
class Movie {
let title: String
let releaseYear: Int
^*PROPERTIES
*INITALISE BELOW
init(title: String, releaseYear: Int) {
self. title = title
self. releaseYear = release year
^*USING self. BECAUSE THE PARAMETERS IN THE init() HAVE THE SAME NAMES AS THE PROPERTIES. USE self. TO REPRESENT THE OBJECT BEING INITIALISED.
}
What are Type Properties? (aka Class Properties)
There belong more to the class, and not objects within the class. They don’t vary across classes, so their value stays the same.
ie it has the same value for every instance of a class
eg
static let permittedRatings = [“G”, “PG”]
OR
class let permittedRatings = [“G”, “PG”]