Skip to content

Instantly share code, notes, and snippets.

// 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 RxSwift
import RxCocoa
public class BehaviorDriver<Element>: NSObject {
var behavior: BehaviorRelay<Element>!
var driver: Driver<Element> {
return behavior.asDriver()
}
extension MoviesCollectionView{
func setupRx(){
setupRxCollectionView()
setupRxDrivers()
}
func setupRxCollectionView(){
let dataSubject = PublishSubject<[MoviesSection]>()
@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",
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?
class DisplayGenericCell< DISPLAY_VIEW :UIView> : UICollectionViewCell {
var displayView : DISPLAY_VIEW!
override init(frame: CGRect) {
super.init(frame: frame)
clipsToBounds = true
displayView = DISPLAY_VIEW()
@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
@hassanvfx
hassanvfx / largeTitleView.swift
Last active March 10, 2020 22:20
Access LargeTitleView in swift
var largeTitleView:UIView{
if let navBarSubviews = navigationController?.navigationBar.subviews {
for subView in navBarSubviews where NSStringFromClass(type(of: subView)).contains("LargeTitle"){
return subView
}
}
assert(false, "A large title view is expected on viewDidAppear")
return UIView()
}
import UIKit
public class FactoryCache {
public typealias MakerClosure<Item> = ()->Item
typealias CacheType = NSCache<NSString, InstanceWrapper>
struct CacheWrapper{
var storage: CacheType = NSCache()
}
@hassanvfx
hassanvfx / cameraView.swift
Created January 4, 2023 05:24
Basic Camera Display / Buffer Analysis in SwiftUI
import SwiftUI
import AVFoundation
struct CameraView: View {
// Set up the AVCaptureSession and AVCaptureVideoPreviewLayer
let captureSession = AVCaptureSession()
let previewLayer = AVCaptureVideoPreviewLayer()
let cameraDelegate = CameraDelegate()