This file contains 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
struct Thing { | |
var name: String | |
// ตัวแปรระดับ Global สามารถเข้าถึงได้จากทุกที่ | |
static var globalThings = [String]() | |
// บัณทึกชื่อไว้ใน globalThings แม้ว่าตัวแปร Thing จะถูกลบ ค่าที่เก็บไว้จะคงอยู่ต่อไป | |
func saveToGlobal() { | |
Thing.globalThings.append(name) | |
} |
This file contains 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
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") | |
} | |
} |
This file contains 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
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))] | |
}() | |
} |
This file contains 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
//: 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 |
This file contains 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 output = "" | |
for (index, league) in leagues.enumerate() { | |
output += "อันดับที่ \(index+1): \(league)\n" | |
} | |
output |
This file contains 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
leagues = leagues.map{ "สโมสร" + $0 } | |
leagues |
This file contains 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 (index, league) in leagues.enumerate() { | |
leagues[index] = "สโมสร" + league | |
} | |
leagues |
This file contains 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 index in 0..<leagues.count { | |
leagues[index] = "สโมสร" + leagues[index] | |
} | |
leagues |
This file contains 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 | |
var leagues = ["เอสซีจี เมืองทองฯ ยูไนเต็ด", "บุรีรัมย์ ยูไนเต็ด", "บางกอกกล๊าส เอฟซี", "ราชบุรี มิตรผล"] | |
leagues += ["แบงค็อก ยูไนเต็ด", "ชลบุรี เอฟซี", "สุพรรณบุรี เอฟซี"] | |
leagues.append("เชียงราย ยูไนเต็ด") | |
leagues.append("อาร์มี่ ยูไนเต็ด") | |
leagues.append("นครราชสีมา มาสด้า เอฟซี") | |
leagues.count | |
leagues[4] // อันดับที่ 5 |
This file contains 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 | |
var str = "Hello, playground" | |
str.uppercaseString | |
str = "This is\n" + | |
"my first\n" + | |
"play ground" | |
str.uppercaseString |
NewerOlder