Skip to content

Instantly share code, notes, and snippets.

View brunomunizaf's full-sized avatar

Bruno Muniz brunomunizaf

View GitHub Profile
class TransitionDelegate: NSObject {
private let duration = 0.5
func configureViews(for state: State,
containerView: UIView,
backgroundViewController: UIViewController,
viewInBackground: UIImageView,
viewInForeground: UIImageView,
snapshotView: UIImageView) {
switch state {
extension TransitionDelegate: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationController.Operation,
from fromVC: UIViewController,
to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if toVC is AnimatedTransition {
return self
}
return nil
extension TransitionDelegate: UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let fromViewController = transitionContext.viewController(forKey: .from)!
let toViewController = transitionContext.viewController(forKey: .to)!
let containerView = transitionContext.containerView
@brunomunizaf
brunomunizaf / AppDelegate.swift
Created June 7, 2019 01:38
Rich media push notifications
// MARK: - UNUserNotificationCenterDelegate
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "open.action" {
// OPEN DOOR
}
var sound: SystemSoundID = 0
if let soundURL = Bundle.main.url(forAuxiliaryExecutable: "doorbellRing.caf") {
AudioServicesCreateSystemSoundID(soundURL as CFURL, &sound)
AudioServicesPlaySystemSound(sound)
}
@propertyWrapper
struct Dependency<T> {
var wrappedValue: T
init() {
self.wrappedValue = DependencyContainer.resolve()
}
}
final class DependencyContainer {
protocol Pushing {
func push(_ target: UIViewController, from parent: UIViewController)
}
struct Pusher: Pushing {
func push(_ target: UIViewController, from parent: UIViewController) {
parent.navigationController?.pushViewController(target, animated: true)
}
}
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions...) -> Bool {
DependencyContainer.register(DashboardCoordinator() as DashboardCoordinating)
// ...
}
}
final class SomeScreen: UIViewController {
import Quick
import Nimble
@testable import myapp
final class PusherDouble: Pushing {
private(set) var didPresentTarget: UIViewController?
private(set) var didPresentFrom: UIViewController?
}
import UIKit
let appDelegate: String? = NSClassFromString("XCTestCase") == nil ? NSStringFromClass(AppDelegate.self) : nil
UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, appDelegate)