Skip to content

Instantly share code, notes, and snippets.

View biloshkurskyi-ss's full-sized avatar

Serhii Biloshkurskyi biloshkurskyi-ss

View GitHub Profile

Videos

@biloshkurskyi-ss
biloshkurskyi-ss / Mark.Object.Example
Last active November 9, 2017 17:04
Marks example in the class
class User: Object {
// MARK: - Init
convenience init(param first: String, second: String) {
self.init()
}
// MARK: - Instance / Persisted Properties
@objc dynamic var id = UUID().uuidString
@biloshkurskyi-ss
biloshkurskyi-ss / Mark.Full.Example
Last active November 6, 2017 19:37
Marks examples
//------------- e.g Realm Object
class User: Object {
// MARK: - Init
convenience init(param first: String, second: String) {
self.init()
}
// MARK: - Instance / Persisted Properties
@objc dynamic var id = UUID().uuidString
@biloshkurskyi-ss
biloshkurskyi-ss / Marks.ViewController.Example
Last active November 9, 2017 17:08
Marks example in the ViewController
import UIKit
// MARK: - ThirtPartyDelegate
protocol ThirtPartyDelegate {
//Delegate methods
}
// MARK: - NetworkClientType
protocol NetworkClientType {
//Protocoll variables + methods
@biloshkurskyi-ss
biloshkurskyi-ss / Marks.Other.Example
Created November 9, 2017 17:06
Other Marks examples
import UIKit
protocol NetworkClientType {
//Protocoll variables + methods
}
class NetworkClient: NetworkClientType {
// MARK: - Class Constructors
static let shared: NetworkClient = {
//customize instance
@biloshkurskyi-ss
biloshkurskyi-ss / gist:93fec5d46be1615d1d252ecc4c1c7a8c
Last active December 25, 2017 15:20
Stackoverflow answer 47969339 gist
//: Playground - noun: a place where people can play
import UIKit
var str = "12,3,5,75,584,364,57,88,94,4,79,333,7465,867,56,6,748,546,573,466"
let numbers = str.components(separatedBy: ",")
extension Array {
func chunked(by chunkSize: Int) -> [[Element]] {
return stride(from: 0, to: self.count, by: chunkSize).map {
Array(self[$0..<Swift.min($0 + chunkSize, self.count)])
@biloshkurskyi-ss
biloshkurskyi-ss / gist:7432279b01dc07c8c9df58b4e19315ba
Last active January 27, 2018 16:50
SWIFT.Solid.SingleResponsobility.Bad
protocol OrderBadType {
func printOrder() //could change text representation style
//methods below may change DB processing from Core Data to Realm
func load()
func save()
}
@biloshkurskyi-ss
biloshkurskyi-ss / gist:b43f68c2583f80c1610748da23b85175
Last active January 30, 2018 16:25
SWIFT.Solid.SingleResponsobility.Good
protocol OrderType {
var products: [ProductType] { get }
func calculateTotalSum()
func getItems()
func add(_ product: ProductType)
func remove(_ product: ProductType)
}
class OrderStorage {
func load() {
let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
let ordersFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "Order")
do {
let fetchedEmployees = try moc.fetch(orderFetch) as! [Order]
} catch {
fatalError("Failed to fetch orders: \(error)")
}
@biloshkurskyi-ss
biloshkurskyi-ss / gist:7104f28f382d7701cc45f6c972537375
Created January 27, 2018 18:58
SWIFT.Solid.OpenСlosed.Good
protocol OrderStorageType {
func load()
func save()
}
class ReamlOrderStorage: OrderStorageType {
var order: Order
func load() {
do {
let realm = try Realm()