Skip to content

Instantly share code, notes, and snippets.

View dkulundzic's full-sized avatar

Domagoj Kulundžić dkulundzic

  • The World
View GitHub Profile
@dkulundzic
dkulundzic / ActivitiesListContentView.swift
Last active February 2, 2023 12:47
A UIKit UIView with programmatic Auto Layout based layout
class ActivitiesListContentView: UIView {
var flowLayout: ActivitiesListFlowLayout? {
collectionView.collectionViewLayout as? ActivitiesListFlowLayout
}
private(set) lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: ActivitiesListFlowLayout())
private(set) var categorySelectorView: UIView?
private lazy var categorySelectorContainerView = UIView.autolayoutView()
override init(frame: CGRect) {
@dkulundzic
dkulundzic / FilteringList.swift
Last active February 2, 2023 12:47
An example "smart" Collection with embedded filtering abilities
public struct FilteringList<Element, Filter>: Collection {
public typealias Filtering = (Element, Filter?) -> Bool
public typealias Index = Int
public typealias Element = Element
public var filtering: Filtering? {
didSet { filter(using: selectedFilter) }
}
public var selectedFilter: Filter? {
@dkulundzic
dkulundzic / ChatNetworkService.swift
Last active February 2, 2023 12:49
A testable, Promise based example network service
public protocol ChatNetworkService {
func loadMessages(bookingId: String) -> Promise<[ChatMessage]>
func sendMessage(_ message: String, bookingId: String) -> Promise<ChatMessage>
}
public final class DefaultChatNetworkService {
public init() { }
}
extension ChatNetworkService: ChatNetworkService {
@dkulundzic
dkulundzic / MessageViewPresentable.swift
Created February 2, 2023 12:39
Protocol based mechanism for easily and uniformly displaying a custom messaging UI element
protocol MessageViewPresentable: AnyObject {
var messageView: MessageView? { get set }
var hostView: UIView { get }
func showMessageView(using context: MessageView.Context, action: Action?)
func hideMessageView(animated: Bool)
}
extension MessageViewPresentable where Self: UIViewController {
var hostView: UIView {
view
@dkulundzic
dkulundzic / AppDelegate.swift
Created February 2, 2023 12:46
An abstraction for a predefined set of functionality, aimed to be ran once, at app startup
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
StartupProcessService()
.execute(process: AppearanceCustomisationStartupProcess())
.execute(process: AppsFlyerStartupProcess(delegate: self))
.execute(process: FacebookStartupProcess(application: application, launchOptions: launchOptions))
.execute(process: GoogleServicesStartupProcess(messagingDelegate: self))
.execute(process: MixpanelStartupProcess(launchOptions: launchOptions))