Skip to content

Instantly share code, notes, and snippets.

Göksel Köksal gokselkoksal

Block or report user

Report or block gokselkoksal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View SelfSizingButton.swift
class Button: UIButton {
var outset: CGSize = CGSize.zero
var shouldFitContentVertically: Bool = false {
didSet {
if shouldFitContentVertically {
titleLabel?.lineBreakMode = .byWordWrapping
titleLabel?.numberOfLines = 0
}
@gokselkoksal
gokselkoksal / AnyCodable.swift
Created Feb 12, 2019
A placeholder decodable type
View AnyCodable.swift
// 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
}
View KeyedDecodingContainer+TypeInference.swift
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)
}
}
View JSONWars-UnboxWrap.swift
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")
View JSONWars-Codable.swift
extension Place {
enum CodingKeys: String, CodingKey {
case name = "placeName"
case lat
case lon
case dateAdded
case info
}
View BlurringTheLines-MVVM-3.swift
protocol MovieListView: MovieListPresenterDelegate {
private var presenter: MovieListPresenter
func didTapOnReload()
func didTapOnMovie(at index: Int)
}
protocol MovieListPresenterDelegate {
func updateWithMoviePresentations(_ movies: [MoviePresentation])
}
View BlurringTheLines-MVVM-2.swift
protocol MovieListView: MovieListPresenterDelegate {
private var presenter: MovieListPresenter
func didTapOnReload()
func didTapOnMovie(at index: Int)
func showDetailView(for movie: Movie)
}
protocol MovieListPresenterDelegate {
func updateWithMoviePresentations(_ movies: [MoviePresentation])
}
View BlurringTheLines-MVVM-1.swift
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)
View UsingChannels-Channel-Definition.swift
enum Theme: String {
case light, dark
}
class UserSettings {
enum Message {
case didUpdateTheme(Theme)
}
View UsingChannels-NotificationCenter-Definition.swift
enum Theme: String {
case light, dark
}
class UserSettings {
static let shared = UserSettings(notificationCenter: .default)
let notificationCenter: NotificationCenter
var theme: Theme = .light {
You can’t perform that action at this time.