A1. What is a Mark Line in Xcode?
A2. What are Instance Variables, Computed Properties, init()
A3. Using Xcode’s Quick Help + Building CalFinance’s Documentation
A5. Enum Fundamentals in Swift
A Mark Line in CardManager.swift
.
A Mark Line is a special comment that greatly aids in navigation. First, it helps you create sections to separate different areas of code from each other.
If you have the Minimap enabled, you can see all of the Mark Lines visibly which can be really useful in navigating to places via the Minimap.
(If you don’t have the Minimap visible, you can enable it by the context menu as shown to the right →)
How to enable Xcode’s Minimap.
At the top of the code editor, right below all the file tabs, is Xcode’s Method Navigator. All your Mark Lines adds both a chapter title and line break here. It is especially helpful when navigating in or even exploring a large file for the first time.
init()
To represent an real-life or abstract objects (for example like a car or perhaps a player in a game), we can use structs
and classes
to model them in code. Let’s for example, take a look of how we can do so for a car:
struct Car {
var make: String
var model: String
var color: Color
var year: Int
func goStraight() -> String {
return "Going Straight"
}
}
Here, we have declared a struct
called Car
with 4 properties (which are also called instance variables) and 1 method (goStraight
). Now, Car
is just a model representing what a car really is, we haven’t created the actual car just yet.
To create a car, we do something called “instantiation” (in this case “instantiating the Car
struct”). This means we will create a car object from our Car
struct with the appropriate properties initialized to their respective values like this:
//Instantiating a new Car struct
var myCar1 = Car("Toyota", "Camry", Color.red, 2015)
print(myCar.model) // "Camry"
make
, model
, color
, and year
are called properties (variables that belong to a struct
or class
). In addition, they are also instance variables. What does that mean? Well to simply put it: they are variables that belong to each instance.
Let’s take a look at this example now.