Skip to content

Instantly share code, notes, and snippets.

View TerryCK's full-sized avatar

Guan-Jhen (Terry) TerryCK

  • Taipei, Taiwan
View GitHub Profile
protocol Strategy {
func attack() -> String
}
struct Adventure {
private let name: String
init(name: String) {
self.name = name
}
protocol Strategy {
func attack() -> String
}
struct Adventure {
private let name: String
init(name: String) {
self.name = name
}
@TerryCK
TerryCK / FP&POP.swift
Created October 9, 2017 14:23
FP&POP.swift
//: [Overview](@previous)
/*:
## Protocol Oriented Programming Exercise
### Exercises
0. Warm up Counter of even and odd
1. Squaring integers
2. Clamping integers
@TerryCK
TerryCK / iBook.swift
Created November 12, 2017 06:53
iBook.swift
class Person {
var age: Int
var residence: Residence?
init(age: Int, resdience: Residence?) {
self.age = age
self.residence = resdience
}
}
class Residence { var address: Address? }
import Foundation
enum Status: Int {
case modified, create
}
struct Model {
var property: Int {
didSet{ self.status = .modified }
}
var modelName: String {
@TerryCK
TerryCK / threadSafety.swift
Created December 11, 2017 15:41
Discuss about Swift threadSafety with struct and memory address
import Foundation
var array = [1,2,3,4]
// read the `array` to property `getArray`, to properties in the same heap momery address, not copy data form `array` to `getArray` right now.
let getArray = array
array
getArray
address(of: array)
@TerryCK
TerryCK / ChristmasTree.swift
Last active December 25, 2017 01:57
ChristmasTree.swift
extension BinaryInteger {
func printPyramid() {
guard self > 0 else { return }
for i in 0...up {
// let offset = i <= 9 ? "0" : ""
let spaceStr = Array(repeating: " ", count: up - i).joined()
let numsStr = Array(0...i).toString
// let numsStr = Array(repeating: "\(offset)\(i.specStringInternal)", count: i).joined()
print(spaceStr + numsStr)
@TerryCK
TerryCK / strategy.swift
Last active December 26, 2017 10:41
strategy runtime error
protocol Presentable {
func presenting(with viewController: UIViewController)
}
extension Presentable where Self: UIViewController {
func presenting(with viewController: UIViewController) {
switch self {
case let pushableViewContorller as Pushable:
@TerryCK
TerryCK / String+Extension.swift
Created December 26, 2017 15:03
String+Extension in playground
extension String {
static var txtLocoal: String {
return "txtLocoal".localized()
}
func localized() -> String {
return "localized String \(self)"
}
}
@TerryCK
TerryCK / BatteryStatus.swift
Last active December 27, 2017 06:00
iOSTaipei
import Foundation
protocol BatteryStatusProtocol {
static var allStatus: [BatteryStatus] { get }
mutating func setStatus<T: BinaryInteger>(input: T)
}
enum BatteryStatus: String, BatteryStatusProtocol {
case full, medium, less, charging, notOffcial
}
// Implement