Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
24 Cards in this Set
- Front
- Back
- 3rd side (hint)
Create a Type Inference variable |
var string = "abc" var number = 123 |
Providing a value when creating a variable or constant lets the compiler infer its type. |
|
var number = 123 Print above using String Interpolation |
print("\(number)") |
Write Int values in \() and the value be converted into a string |
|
Declare name as an Optional |
var name: string? |
A value that contains either an underlying value or nil to indicate that the value is missing Swift disallow assigning nil to prevent null pointer exceptions. |
|
var optionalValue: Int? User Optional Binding to check if optionalValue has a value. |
if let value = optionalValue{ value = optionalValue*2 } else { print("Optional has a nil value.") } |
The safest way to unwrap an optional. Use a If let... else... statement to check if a optional has a value or a nil. |
|
var imageView = UIImageView() imageView.image = UIImage(named:"puppy_in_box")
Use Optional Chaining to check if size has a value and print the value. |
if let imageSize = imageView.image?.size{
print("\(imageSize)") } else { print("Image has not been set.") } Jnj |
A process of querying and calling properties, methods, and subscript on an optioned that might currently be nil. |
|
Create an Implicitly Unwrapped Optional |
var x: int! |
Optionals that is clear that it will always have a value after that value is first set. |
|
Var DogName: String? Force unwrap DogName |
DogName! |
Once you’re sure that the optional does contain a value, you can access its underlying value by adding an exclamation mark (!) to the end of the optional’s name. |
|
Create a class called Vehicle with a stored property called currentSpeed set to 0.0 |
class Vehicle{ var currentSpeed = 0.0 } |
Classes are general-purpose, flexible constructs that become the building blocks of your program’s code. |
|
Create a sub-class of the class Vehicle called Bicycle with a stored property called hasBasket set to false |
class Bicycle: Vehicle { var hasBasket = false } |
Subclassing is the act of basing a new class on an existing class. The subclass inherits characteristics from the existing class, which you can then refine. You can also add new characteristics to the subclass. |
|
var numericalString = "3" var number = Declare number by converting it using a built-in function |
var number = int(numericalString) |
This is new to Swift 2. |
|
Initialize an array called cuteAnimals with the type CuddlyCreature. |
var cuteAnimals =[CuddlyCreature]() |
|
|
Initialize a string array of 5 US states using array literal syntax. |
let states = ["Florida", "Idaho", "Maine", "Kansas", "Virginia"] |
|
|
var colors = ["red", "orange", "yellow", "green", "blue", "violet"] Insert indigo after blue |
colors.insert("indigo", atIndex: 5) |
|
|
Initialize an empty dictionary which holds Strings as keys and Bools as values |
var emptyDict = [String:Bool]() |
|
|
Initialize a dictionary using array literal syntax |
var goodfood = ["apple":true, "Torula Yeast":false] |
|
|
Why does this code return an optional? CityStateDict["New York"] |
There is a possibility this code is looking for something that is not in the dictionary, resulting in nil, thus requiring a return of an optional. |
|
|
Write the syntax for creating a range. |
1...10 |
|
|
Create a for-in loop for this array. var numarray = [2, 4, 6, 8] |
For number in numarray{ print(number) } |
|
|
Create a for-in loop for this dictionary array. var treetype = ["cedar":true, "birch": true, "licorice":false] |
for (tree, tfval) in treetype{ if tfval{ print(tree + "is a tree.") } else{ print(tree + "is not a tree.") } } |
|
|
Replace "123" in below string with "911" var string = "12345" |
string.stringByReplacingOccurencesOfString("123", withString: "911") |
|
|
Create an enumeration called tree for the following: leaves, branches, roots. |
enum tree{ case leaves, branches, roots } |
|
|
Create switch statement for each case. enum tree{ case leaves, branches, roots } var gathering = tree.leaves |
switch gathering{ case .leaves: print("I'm gathering leaves.") case .branches: print("I'm gathering branches.") case .roots: print("I'm gathering roots.") } |
|
|
Create a switch-case control flow to change grade to "Pass", "Fail" or "Incomplete" var score = 75 var grade = "" |
switch score{ case 65...100: grade = "Pass" case 0...64: grade = "Fail" default: grade = "Incomplete" } |
|
|
What are the 3 different functions in Swift? |
Global Functions (ex: Print), Nested Functions (function within a function), Methods (functions in a class). |
|