Skip to content

Instantly share code, notes, and snippets.

View totiz's full-sized avatar

Nattapon Nimakul totiz

View GitHub Profile
@totiz
totiz / Thing.swift
Last active May 23, 2016 10:10
Thing
struct Thing {
var name: String
// ตัวแปรระดับ Global สามารถเข้าถึงได้จากทุกที่
static var globalThings = [String]()
// บัณทึกชื่อไว้ใน globalThings แม้ว่าตัวแปร Thing จะถูกลบ ค่าที่เก็บไว้จะคงอยู่ต่อไป
func saveToGlobal() {
Thing.globalThings.append(name)
}
@totiz
totiz / AppController.swift
Last active September 12, 2018 09:45
AppController
class AppController {
static let NotifcationIdentifier = Notification.Name("Notify when something change")
func notify(message: String) {
NotificationCenter.default.post(name: AppController.NotifcationIdentifier, object: "User Did Open App")
}
}
@totiz
totiz / Lazy Controller.swift
Last active September 12, 2018 09:46
Lazy Controller
class Controller {
lazy var things = [String]()
lazy var lines: [Line] = {
return [Line(begin: CGPoint(x: 1, y: 1), end: CGPoint(x: 20, y: 20)),
Line(begin: CGPoint(x: 50, y: 50), end: CGPoint(x: 10, y: 10))]
}()
}
@totiz
totiz / Lazy Line 1.swift
Last active May 23, 2016 09:34
Lazy Line 1
//: Playground - noun: a place where people can play
import UIKit
struct Line {
let begin: CGPoint
let end: CGPoint
init(begin: CGPoint, end: CGPoint) {
self.begin = begin
var output = ""
for (index, league) in leagues.enumerate() {
output += "อันดับที่ \(index+1): \(league)\n"
}
output
leagues = leagues.map{ "สโมสร" + $0 }
leagues
for (index, league) in leagues.enumerate() {
leagues[index] = "สโมสร" + league
}
leagues
for index in 0..<leagues.count {
leagues[index] = "สโมสร" + leagues[index]
}
leagues
import UIKit
var leagues = ["เอสซีจี เมืองทองฯ ยูไนเต็ด", "บุรีรัมย์ ยูไนเต็ด", "บางกอกกล๊าส เอฟซี", "ราชบุรี มิตรผล"]
leagues += ["แบงค็อก ยูไนเต็ด", "ชลบุรี เอฟซี", "สุพรรณบุรี เอฟซี"]
leagues.append("เชียงราย ยูไนเต็ด")
leagues.append("อาร์มี่ ยูไนเต็ด")
leagues.append("นครราชสีมา มาสด้า เอฟซี")
leagues.count
leagues[4] // อันดับที่ 5
import UIKit
var str = "Hello, playground"
str.uppercaseString
str = "This is\n" +
"my first\n" +
"play ground"
str.uppercaseString