let val = (Double)6
let x = 5
guard x == 5 { return }
enum Direction {
case north, south, east, west
}
let val = 5
print("value is: \(val)")
vals
after this code is executed?var vals = [10, 2]
vals.sort { (s1, s2) -> Bool in
s1 > s2
}
typealias Thing = [String:Any]
var stuff: Thing
print(type(of: stuff))
let x = ["1", "2"].dropFirst()
let y = x[0]
var test = 1 == 1
var x: Int?
let y = x ?? 5
func add(a: Int, b: Int) -> Int { return a+b }
func myFunc(_ a: Int, b: Int) -> Int {
return a + b
}
let value1 = "\("test".count)"
class Person {
var name: String
var address: String
}
let names = ["Bear", "Joe", "Clark"]
names.map { (s) -> String in
return s.uppercased()
}
let val = 5
extension String {
var firstLetter: Character = "c" {
didSet {
print("new value")
}
}
}
self.callback = {
self.attempts += 1
self.downloadFailed()
}
var vals = Set<String> = ["4", "5", "6"]
vals.insert("5")
if let s = String.init("some string") {
print(s)
}
var strings = [1, 2, 3]
for i in 0...100 {
print(i)
}
let names = ["Larry", "Sven", "Bear"]
let t = names.enumerated().first().offset
let vt = (name: "ABC", val: 5)
let test = vt.0
class LSN : MMM {
}
var userLocation: String = "Home" {
willSet(newValue) {
print("About to set userLocation to \(newValue)...")
}
didSet {
if userLocation != oldValue {
print("userLocation updated with new value!")
} else {
print("userLocation already set to that value...")
}
}
}
userLocation = "Work"
throws
.let x = ["a", "b", "c"]
String[]
Array<String>
Set<String>
Array<Character>
oThings
after this code is executed?let nThings: [Any] = [1, "2", "three"]
let oThings = nThings.reduce("") { "\($0)\($1)" }
!try
try?
try!
?try
protocol TUI {
func add(x1 : Int, x2 : Int) -> Int {
return x1 + x2
}
}
add
is a reserved keyword.wheels
and doors
examples of?class Car {
var wheels: Int = 4
let doors = 4
}
init?
let dbl = Double.init("5a")
print(dbl ?? ".asString()")
.asString()
this
and toThat
examples of?func add(this x: Int, toThat y: Int)->{}
for (key, value) in [1: "one", 2: "two"]{
print(key, value)
}
class Square{
var height: Int = 0
var width : Int {
return height
}
}
let vals = ("val", 1)
var x = 5
x = 10.0
var items = ["a":1, "b":2, "c":"test"] as [String: Any]
items["c"] = nil
print(items["c"] as Any)
let val = 5.0 + 10
struct Test{
var score: Int
var date: Date
}
let x = try? String.init("test")
print(x)
var vals = [1,2,3]
vals.sort { $0 < $1 }
vals.sort { (s1, s2) in s1 < s2 }
vals.sort(by: <)
for i in ["0", "1"]{
print(i)
}
let names = ["Bear", "Tony", "Svante"]
print(names[1]+"Bear")
let name: String?
let
constants.val
after this code is executed?let i = 5
let val = i * 6.0
enum Positions : Int {
case first, second, third, other
}
print (Positions.other.rawValue)
"t".forEach { (char) in
print(char)
}
let s1 = ["1", "2", "3"]
.filter { $0 > "0" }
.sorted { $0 > $1 }
print(s1)
(Question does not make that much sense though. )
class AmP : MMM, AOM {
}
let numbers = [1,2,3,4,5,6].filter{ $0 % 2 == 0}
vals
in this code?let vals = ["a", 1, "Hi"]
x
in tuple vt
let vt = (name: "ABC", val: 5)
_
, x) = vt