Skip to content

Instantly share code, notes, and snippets.

@vedon
vedon / NBResponderChainUtilities.h
Last active August 29, 2015 14:28 — forked from n-b/NBResponderChainUtilities.h
Chain Responder Debugging Methods
//
// NBResponderChainUtilities.h
//
// Created by Nicolas @ bou.io on 19/04/13.
//
#import <UIKit/UIKit.h>
@interface UIView (NBResponderChainUtilities)
- (UIView*) nb_firstResponder; // Recurse into subviews to find one that responds YES to -isFirstResponder
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
ALWAYS_SEARCH_USER_PATHS = NO
ALWAYS_USE_SEPARATE_HEADERMAPS = YES
APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer
APPLE_INTERNAL_DIR = /AppleInternal
APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation
//
// MetalVideoRenderer.swift
// RTEVideoEditor
//
// Created by weidong fu on 2020/1/1.
// Copyright © 2020 Free. All rights reserved.
//
import UIKit
import AVFoundation
class LoginViewController {
private let userSession: UserSession
init(_ userSession: UserSession) {
self.userSession = userSession
}
func login(_ userName: String, password: String) {
userSession.login(userName, password)
}
class LoginViewController {
var userSession: UserSession?
func login(_ userName: String, password: String) {
userSesson?.login(userName, password)
}
}
typealias Login = (_ name: String, _ password: String) -> Void
class LoginViewController {
func login(_ login: Login, name: String, password: String) {
...
login(name, password)
...
}
}
Class UserSession {
static let shared: UserSession
}
Class LoginViewController {
func login(_ name: String, password: String) {
...
UserSession.shared.login(name, password)
...
protocol Service {}
Class ServiceLocator {
func register(_ service: Service, for type: ServiceType)
func resolve(_ type: ServiceType)
}
ServiceLocator.shared.register(UserSession(), type: UserService.self)
Struct UserService: Service {}
class LoginViewController {
private let userSession: UserSession
init(_ userSession: UserSession = UserSession()) {
self.userSession = userSession
}
}
let vc = LoginViewController()
let vc = LoginViewController(userSession)
import Foundation
import Swinject
public typealias DIContainer = Container
public final class AnyInitializer {
private let resolve:(_ container: DIContainer) -> Any
public init<D1, D2, T>(_ function: @escaping (D1, D2) -> T) {
resolve = { container in
let d1: D1 = container.resolve(D1.self)!