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 Strategy { | |
func attack() -> String | |
} | |
struct Adventure { | |
private let name: String | |
init(name: String) { | |
self.name = name | |
} |
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 Strategy { | |
func attack() -> String | |
} | |
struct Adventure { | |
private let name: String | |
init(name: String) { | |
self.name = name | |
} |
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
//: [Overview](@previous) | |
/*: | |
## Protocol Oriented Programming Exercise | |
### Exercises | |
0. Warm up Counter of even and odd | |
1. Squaring integers | |
2. Clamping integers |
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? } |
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
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
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
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 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
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 |