Skip to content

Instantly share code, notes, and snippets.

View srstanic's full-sized avatar

Srđan Stanić srstanic

View GitHub Profile
// Presenter
typealias SomeViewModel = String // this is just a placeholder for your view model type
protocol SomeView {
func showSomething(viewModel: SomeViewModel)
}
protocol SomeViewOutput {
func onUserAction()
@srstanic
srstanic / MyCollectionViewController3.swift
Created February 28, 2023 12:53
MyCollectionViewController #3
import UIKit
protocol CellController {
func getCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell
}
struct TextItemModel {
let title: String
}
@srstanic
srstanic / MyCollectionViewController2.swift
Created February 28, 2023 12:49
MyCollectionViewController #2
import UIKit
struct CollectionItemModel {
let title: String?
let image: UIImage?
}
struct CellController {
var model: CollectionItemModel
func getCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
@srstanic
srstanic / MyCollectionViewController1.swift
Created February 28, 2023 12:47
MyCollectionViewController #1
import UIKit
struct CollectionItemModel {
let title: String?
let image: UIImage?
}
/// First set `model` and then present on screen.
final class MyCollectionViewController: UICollectionViewController {
var models: [CollectionItemModel]?
@srstanic
srstanic / RealmMultiThreadingStaleDataTests.swift
Created March 15, 2022 14:55
RealmMultiThreadingStaleDataTests.swift
import XCTest
import Combine
import RealmSwift
class RealmMultiThreadingStaleDataTests: XCTestCase {
private var cancellables: Set<AnyCancellable>!
override func setUpWithError() throws {
super.setUp()
cancellables = []
@srstanic
srstanic / .zshrc
Created March 15, 2022 10:19
.zshrc
autoload -U colors && colors
## rbenv
eval "$(rbenv init - zsh)"
## git
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn
zstyle ':vcs_info:git*' formats "%r/%S%{$fg[grey]%} %{$fg[blue]%}%b%{$reset_color%} (%a) %m%u%c%{$reset_color%} "
precmd() {
extension UIView {
static func withoutConstraints() -> Self {
let instance = self.init()
instance.translatesAutoresizingMaskIntoConstraints = false
return instance
}
func addSubviews(_ views: UIView...) {
for view in views {
addSubview(view)
/// Inspired by
/// http://blog.benjamin-encz.de/post/main-queue-vs-main-thread/
/// and https://stackoverflow.com/a/60348601
/// Associates a predefined key/value pair with the main queue and later uses the presence of it
/// to determine whether the current queue is the main queue.
extension DispatchQueue {
private static let mainQueueCheckKey: DispatchSpecificKey<String> = {
let mainQueueCheckKey = DispatchSpecificKey<String>()
DispatchQueue.main.setSpecific(key: mainQueueCheckKey, value: mainQueueCheckValue)
return mainQueueCheckKey
extension FileManager {
func isDirectory(at url: URL) -> Bool {
var isDirectory: ObjCBool = false
guard FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory) else {
return false
}
return isDirectory.boolValue
}
}
typealias AlertActionStyle = UIAlertAction.Style
extension UIAlertController {
static func create(
style: UIAlertController.Style,
title: String?,
message: String?,
actions: [AlertAction] = [],
onDismiss: VoidHandler? = nil
) -> UIAlertController {