Skip to content

Instantly share code, notes, and snippets.

View marcocapano's full-sized avatar

Marco Capano marcocapano

View GitHub Profile
import Foundation
import Combine
struct MyObject {
var string: String
}
class MyClass {
var cancellable: AnyCancellable?
@marcocapano
marcocapano / EULoader.swift
Created March 22, 2019 17:05
A loader styled after the EU symbol
let vc = UIViewController()
vc.view.backgroundColor = .white
PlaygroundPage.current.liveView = vc
let replicatorLayer = CAReplicatorLayer()
vc.view.backgroundColor = UIColor.blue
vc.view.layer.addSublayer(replicatorLayer)
let size: CGFloat = 100
let viewFrame = vc.view.frame
@marcocapano
marcocapano / customLoader.swift
Created March 21, 2019 17:13
Custom loader spinner with CoreAnimation
let vc = UIViewController()
vc.view.backgroundColor = .white
PlaygroundPage.current.liveView = vc
//Creating the replicator layer
let replicatorLayer = CAReplicatorLayer()
vc.view.layer.addSublayer(replicatorLayer)
let size: CGFloat = 100
let viewFrame = vc.view.frame
/// Calls a function n times passing the result of each call into the next call.
///
/// - Parameters:
/// - function: A function that takes T and returns T. It will be called multiple times and produce the result.
/// - initialInput: The initial input to pass into the function.
/// - repetitions: The number of times the function has to be called.
/// - Returns: Returns the result of consecutive calls to the given functions.
func call<T>(_ function: @escaping (T) -> T?, initialInput: T, repetitions: Int) -> T? {
var seq = sequence(first: initialInput, next: function)
@marcocapano
marcocapano / presentingPopover
Last active November 17, 2018 16:20
Helper function to present a popover.
///
/// - Parameters:
/// - popoverContent: the view controller to add as a popover.
/// - sourcePoint: the point in which to anchor the popover.
/// - size: the size of the popover. Default uses the popover preferredContentSize.
/// - delegate: the popover's presentationController delegate. Default is nil.
/// - animated: Pass true to animate the presentation; otherwise, pass false.
/// - completion: The block to execute after the presentation finishes. Default is nil.
public func presentPopover(_ popoverContent: UIViewController, sourcePoint: CGPoint, size: CGSize? = nil, delegate: UIPopoverPresentationControllerDelegate? = nil, animated: Bool = true, completion: (() -> Void)? = nil) {
popoverContent.modalPresentationStyle = .popover