Swift (general) Flashcards

1
Q

What is a UIEelement?

A

It’s an object class in the view controller (eg a button)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an @IBAction?

A

@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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an @IBOutlet

A

@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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is UINavigation Controller?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does AVFoundation framework do?

A

It deals with audio and video

eg AVAudio class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an AVAudioSession?

A

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()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does NSSearchPathForDirectoriesInDomains

A

Creates a list of directory search paths

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is delegation?

A

When you get one object to do the job of anothers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a gesture recogniser?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the scene dock?

A

It’s the row of icons above the canvas (ie ViewController)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does ctrl + dragging from ViewController (yellow circle) to the UIElement (eg button) do?

A

It connects an @IBOutlet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does ctrl + dragging from a UIElement (eg button) to the ViewController (yellow circle)?

A

It connects an @IBAction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a tag?

A

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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a framework?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is UITabBarController?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a function?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Where are Global Functions?

A

Global Functions are functions that can be called from anyplace in an app (ie in a class) (eg print, min, and abs)

18
Q

What is a Method (function)?

A

When a function is defined in, and associated with a particular class, it is called a Method.

19
Q

When do you use dot syntax?

A

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

20
Q

What is a class?

A

A class is a unit we use to package together related data and functionality.

21
Q

What is an instance of a class?

A

One of its moving parts. (eg think of Mouse Trap. One of the wheels is an instance of a class)

22
Q

What makes up a class?

A

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()

23
Q

Breakdown:
class Movie {
let title: String
let releaseYear: Int

init(title: String, releaseYear: Int) {
self.title = title
self.releaseYear = release year
}

A

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.
}

24
Q

What are Type Properties? (aka Class Properties)

A

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”]

25
Q

What is a Computed Property?

A
A property that's based on computed data in the class
eg the average of a range of scores

(Nb they have getters and setters)

26
Q

What are Instance Methods?

A

Instance Methods are called on instances of the class

eg returning a list of movies that were produced in 1986

27
Q

What are Class Methods?

A

These belong to the entire class

eg
isSourceTypeAvailable belongs to the UIImagePickerController class

(nb source type will be a photo album or camera)

28
Q

What happens if you use ‘class’ instead of ‘static’ for Class Method?

eg
class func isSourceTypeAvaiable
A

If you use ‘class’ instead of ‘static’ subclasses will be able to override the method

29
Q

What are enums? What are structs?

A

Enums define a set of related values. Structs are a convenient way to bundle properties together. They can have their own methods and conform to protocols

enum PrimaryColour {
case red
case green
case blue
}

or enum PrimaryColour {
case red, green blue
}

30
Q

What is the difference between Structs/Enums and Classes?

A

Structs/Enums are value types, while Classes are reference types

31
Q

Between Classes, Enums, and Structs, which have inheritance?

A

Only classes have inheritance (ie subclasses inherit from the parent class)

32
Q

What are protocols and extensions?

A

Protocols and extensions are tools used to package models of functionality that expand on classes, enumerations and structs. Protocols can be shared across classes, and extensions are used to customise existing classes. The both allows you to reuse code and dry program (don’t repeat yourself).

33
Q

Describe protocols in more detail

A

A protocol is a list of related method signatures. Adopting a protocol is like signing a method to implement every method on the list (eg anything that conforms to Apple’s built in comparable protocol can be compared). Protocols are an essential component of the delegate pattern, the patter by which one type calls upon another type to perform some operation.

34
Q

What are extenstions?

A

Extensions offer a way to add computed properties and methods to an existing class, struct, or enum. They are often used to extend types for which you don’t have access to the code (eg apple frameworks, or third party libraries)

35
Q

What do closures include?

A

Closures include global functions, nested functions, and closure expressions

36
Q

What is a closure expression?

A

A closure expression is an unnamed, self contained block of code that can be passed as an argument to a function. Closure expressions are used to specify an action to be executed at some time in the future.

37
Q

Simplify a closure expression using shorthand arguments

A
var soups = ["tomato", "french onion"]
var sortedSoups = soups.sort({ (soup1: String, soup2: String) -> Bool in 
return soup2 > soup1
})
var sortedSoups = soups.sort({
      $1 > $0
})

The closure expression parameter and return types can be inferred…so no need for ‘String’ and ‘Bool’ and ‘->’. Since this is a single expression closure, it can be inferred that it returns the result of that single expression, so we can also leave out ‘return’. We can use the shorthand argument names, $0 and $1 for soup1 and soup2, so no need for these.

38
Q

Describe the ways of connecting the switches in ColorMaker

A
  1. For Red switch: in the ‘View Controller Scene’ ctrl click. Drag ‘Value Changed’ to the yellow View Controller on Storyboard. Select the desired method (ie changeColorComponent). This connects the switch to the method. Then drag from ‘New Referencing Outlet’ to the yellow ViewController icon to connect the switch to the redControl @IBOutlet redControl swich
  2. For Green switch; an easier method. Just drag the Green button to the method in ViewController.swift (ie the block of code). This will connect all the above.
39
Q

What are UIControl classes?

A

UIControl are the classes that turn user input (eg a touch) into events using the target/action pattern.

40
Q

Explain sliders and changing colours

A

Here’s a trick that will come in handy. The sliders will give you a Float value between 0 and 1, but the UIColor object must be constructed with CGFloat values.

If you have a Float and you need a CGFloat you can use the CGFloat constructor to convert between them

let f: Float = 0.5
let cgf: CGFloat = CGFloat(f)