- Swift strings use double quotes instead of single quote!
- Reference: How to print double quotes inside “”?
- use backslash to escape
- use
"""delimiter - enhanced delimiters (swift 5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class ViewController: UIViewController { | |
| var touchCountTimer: Timer? | |
| var touchBeginTime: Double = 0 | |
| let droneCollection = DroneCollectionController(fromJsonFile: "ring") // composition | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| // Point definition for json object | |
| class Point: Decodable { | |
| let x, y: Int | |
| let color: String | |
| // load all points from json file. | |
| // | |
| // ref: https://stackoverflow.com/a/50042872 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import AVFoundation | |
| import AVKit | |
| import UIKit | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var lyricsLabel: UILabel! | |
| @IBOutlet weak var videoView: UIView! | |
| var player: AVPlayer? | |
| var timer: Timer? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if age < 20 { | |
| print("hello world") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while num < 10 { | |
| num = number +1 | |
| } | |
| repeat { | |
| number = number +1 | |
| } while number < 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i in 1..10 { | |
| print("hello \(i)") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var number2 = 15 | |
| var number3 : Int | |
| number2 = number3 // <-- error! wihtout value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var age: Int = 18 | |
| var age = 18 // type inference | |
| var age // <-- error! neither type declaration nor initialized value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var name = "Jamie" | |
| var intro = "my name is \(name). hello world" |
NewerOlder