Skip to content

Instantly share code, notes, and snippets.

View gokselkoksal's full-sized avatar

Göksel Köksal gokselkoksal

View GitHub Profile
import XCTest
struct Scenario: ScenarioGivenContinuation, ScenarioWhenContinuation {
init(_ description: String) {
print("Scenario: \(description)")
}
struct Given: ScenarioWhenContinuation {
fileprivate init(description: String, setup: () throws -> Void) rethrows {
@gokselkoksal
gokselkoksal / Channel.swift
Last active September 16, 2022 03:53
Channel implementation
public class Channel<Value> {
private class Subscription {
weak var object: AnyObject?
private let notifyBlock: (Value) -> Void
private let queue: DispatchQueue
var isValid: Bool {
return object != nil
class Button: UIButton {
var outset: CGSize = CGSize.zero
var shouldFitContentVertically: Bool = false {
didSet {
if shouldFitContentVertically {
titleLabel?.lineBreakMode = .byWordWrapping
titleLabel?.numberOfLines = 0
}
@gokselkoksal
gokselkoksal / SwiftMigrationJustifications.md
Last active April 23, 2020 20:11
SwiftMigrationJustifications

Number of Lines in Swift Files

Might be handy when estimating work.

  1. Open Terminal
  2. cd to your Xcode project
  3. Execute the following when inside your target project:

Number of lines:

extension KeyedDecodingContainer {
func decodeIfPresent<T: Decodable>(key: K) throws -> T? {
return try decodeIfPresent(T.self, forKey: key)
}
func decode<T: Decodable>(key: K) throws -> T {
return try decode(T.self, forKey: key)
}
}
@gokselkoksal
gokselkoksal / AnyCodable.swift
Created February 12, 2019 10:45
A placeholder decodable type
// Reference: https://github.com/asensei/AnyCodable/blob/master/Sources/AnyCodable/AnyCodable.swift
import Foundation
public struct AnyCodable {
// MARK: Initialization
public init(_ value: Any?) {
self.value = value
}
enum Theme: String {
case light, dark
}
class UserSettings {
enum Message {
case didUpdateTheme(Theme)
}
extension Place: Unboxable {
static let dateAddedFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "YYYY-mm-dd"
return formatter
}()
init(unboxer: Unboxer) throws {
name = try unboxer.unbox(key: "placeName")
extension Place {
enum CodingKeys: String, CodingKey {
case name = "placeName"
case lat
case lon
case dateAdded
case info
}
protocol MovieListView: MovieListViewModelDelegate {
private var viewModel: MovieListViewModel
func updateWithMovies(_ movies: [Movie])
func didTapOnReload()
func didTapOnMovie(at index: Int)
func showDetailView(for movie: Movie)
}
protocol MovieListViewModelDelegate: class {
func viewModelDidUpdate(_ model: MovieListViewModel)