Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
struct Payment {
var amount: Float
var comission: Float
var totalAmount: Float {
return amount + comission
}
}
struct Pin {
var value: String {
willSet {
print("new pin value: \(newValue)")
}
didSet {
print("old pint value: \(oldValue)")
}
}
struct PropertyStruct {
static var storedTypeProperty = "1"
static var computedTypeProperty: Double {
return 10.0
}
}
print("struct type property: \(PropertyStruct.storedTypeProperty)")
class Player {
var playing: Bool = false
func play() {
playing = true
}
func stop() {
playing = false
struct NameComponents {
var firstName: String
var lastName: String
mutating func change(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
}
struct PropertyStructM {
static func typeMethod() {
// Code
}
}
PropertyStructM.typeMethod()
// PUT code into playground
var globalVariable = "globalString"
func fly() {
var localVariable = "localString"
}
struct Airplane {
// Local Variable
var number: String
class VideoPlayer: Player {
var file: String
var width: Int
var height: Int
}
class AudioPlayer: Player {
// Overriding Property Observers
override var playing: Bool {
didSet {
print("\(self) did set playing")
}
}
// Overriding Methods
@vialyx
vialyx / init.swift
Last active October 11, 2018 03:05
class Setting: NSObject {
enum State {
case off, on
}
enum Action {
case setup, open
}