Skip to content

Instantly share code, notes, and snippets.

@hassanvfx
hassanvfx / gist:02feb9f75d451810e1e3ec4a20131e9d
Created February 11, 2020 21:34
Check if the current application state is dark mode.
UIApplication.shared.windows.first?.traitCollection.userInterfaceStyle
class DisplayGenericCell< DISPLAY_VIEW :UIView> : UICollectionViewCell {
var displayView : DISPLAY_VIEW!
override init(frame: CGRect) {
super.init(frame: frame)
clipsToBounds = true
displayView = DISPLAY_VIEW()
import Dispatch
private let coroutineQueue = DispatchQueue(label: "com.swift5.yield", attributes: .concurrent)
public class Coroutine<Element>: IteratorProtocol {
private let callerReady = DispatchSemaphore(value: 0)
private let coroutineReady = DispatchSemaphore(value: 0)
private var done: Bool = false
private var transportStorage: Element?
@hassanvfx
hassanvfx / Package.swift
Created October 10, 2019 23:40
Package swift base
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyLibrary",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "MyLibrary",
extension MoviesCollectionView{
func setupRx(){
setupRxCollectionView()
setupRxDrivers()
}
func setupRxCollectionView(){
let dataSubject = PublishSubject<[MoviesSection]>()
import UIKit
import RxSwift
import RxCocoa
public class BehaviorDriver<Element>: NSObject {
var behavior: BehaviorRelay<Element>!
var driver: Driver<Element> {
return behavior.asDriver()
}
// Getting a single object
Services.api.rx.call(.getMovie(mid))
.subscribe(onSuccess: { completion($0) })
.disposed(by: diposeBag)
// Getting a list
Services.api.rx.call(.getMovieRelated(mid))
.subscribe(onSuccess: { [weak self] (response:APIResponseMovieList) in
self?.movies = response.items()
import UIKit
import Alamofire
import AlamofireObjectMapper
import ObjectMapper
typealias APIClosure<K> = (K?)->Void
class APIService: NSObject {
static let API_KEY_V3 = "SECRET_KEY"
import UIKit
import ObjectMapper
protocol APIResponse {
func items<K>(_ type:K.Type? )->[K]
}
extension APIResponse{
func items<K>(_ type:K.Type? = nil)->[K]{
return ([self] as? [K]) ?? []
import UIKit
import RxSwift
import Alamofire
import AlamofireObjectMapper
extension Reactive where Base:APIService{
func call<K:APIResponse>(_ endpoint : APIEndpoints) -> Single<K> {
return Single<K>.create { single in