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 Foundation | |
class ClassA { | |
private lazy var cellType = CellType.footer | |
init(_ x: Int) { | |
self.cellType = .footer | |
print("ClassA", self.cellType) | |
type(of: self.cellType) | |
} |
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
//: This is a companion Playground for the article "Swift Functors, Applicatives, and Monads in Pictures", available at http://www.mokacoding.com/blog/functor-applicative-monads-in-pictures/ | |
//: The article itself is a translation of the original "Functors, Applicatives, and Monads in Pictures" written for Haskell by Aditya Bhargava, available at http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html | |
//: | |
//: ## Optional | |
//: | |
//: Optional is just a type | |
enum MyOptional<T> { | |
case Some(T) | |
case None |
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
// | |
// Language.swift | |
// | |
// Created by Terry Chen on 2017/12/19. | |
// | |
import UIKit |
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 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 |
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
extension String { | |
static var txtLocoal: String { | |
return "txtLocoal".localized() | |
} | |
func localized() -> String { | |
return "localized String \(self)" | |
} | |
} |
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
protocol Presentable { | |
func presenting(with viewController: UIViewController) | |
} | |
extension Presentable where Self: UIViewController { | |
func presenting(with viewController: UIViewController) { | |
switch self { | |
case let pushableViewContorller as Pushable: |
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
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) |
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 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) |
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 Foundation | |
enum Status: Int { | |
case modified, create | |
} | |
struct Model { | |
var property: Int { | |
didSet{ self.status = .modified } | |
} | |
var modelName: String { |
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
class Person { | |
var age: Int | |
var residence: Residence? | |
init(age: Int, resdience: Residence?) { | |
self.age = age | |
self.residence = resdience | |
} | |
} | |
class Residence { var address: Address? } |