Skip to content

Instantly share code, notes, and snippets.

Note about Swift Book

👍 感謝學員免費獲得的電子書:彼得潘的 Swift 程式設計入門

Ch2. Playground

  • Swift strings use double quotes instead of single quote!
var name = "Jamie"
var intro = "my name is \(name). hello world"
var age: Int = 18
var age = 18 // type inference
var age // <-- error! neither type declaration nor initialized value.
var number2 = 15
var number3 : Int
number2 = number3 // <-- error! wihtout value
for i in 1..10 {
print("hello \(i)")
}
while num < 10 {
num = number +1
}
repeat {
number = number +1
} while number < 10
if age < 20 {
print("hello world")
}
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?
@takawang
takawang / points.swift
Last active March 19, 2022 12:26
Load local json to class
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