Skip to content

Instantly share code, notes, and snippets.

View vittoriom's full-sized avatar

Vittorio Monaco vittoriom

View GitHub Profile
@vittoriom
vittoriom / keybase.md
Created October 13, 2016 15:32
keybase.md
View keybase.md

Keybase proof

I hereby claim:

  • I am vittoriom on github.
  • I am vittoriom (https://keybase.io/vittoriom) on keybase.
  • I have a public key ASBUDFp_pxp2lM5ComDGpVgo-ZcnQCsgYwx0n6yDOk32CQo

To claim this, I am signing this object:

@vittoriom
vittoriom / Reproduce.swift
Created April 27, 2016 07:06
Protocol extension dynamic dispatch
View Reproduce.swift
protocol Test {
func doStuff()
}
extension Test {
// default protocol implementation
func doStuff() {
print("Stuff!")
}
}
@vittoriom
vittoriom / reports.swift
Last active April 23, 2016 13:17 — forked from sferrini/reports.swift
reports func must be more Swifty.
View reports.swift
enum State {
case Happy
case Sad
}
struct Day {
let name: String
let state: State
}
@vittoriom
vittoriom / ArticleInteractor.swift
Last active March 11, 2017 13:11
A wrap-up of the Swifty Service Locator implementation as described in http://vittoriomonaco.it/blog/swifty-service-locator
View ArticleInteractor.swift
// Since in this class we'll use other objects, we define a typealias at the beginning of the file that will have 2 functions:
// 1) It will provide an interface for service locators that want to locate dependencies for this object, type-safe, not more and not less
// 2) It will show in a readable way what dependencies this object needs
typealias ArticleInteractorServiceLocatorInterface = protocol<ArticleRepositoryLocator, ReachabilityLocator>
// Then we define a class implementing this protocol, that will get all the default implementations of the protocols it inherits from, for free
class ArticleInteractorServiceLocator: ArticleInteractorServiceLocatorInterface {
// We can just override the default implementation in this specific service locator!
func reachability() -> ReachabilityInterface {
return OfflineSimulator()
View MessageProducer.swift
import Foundation
// Define here your domain-specific events
public enum MessageEvent {
case YourEvent
}
public protocol MessageProducer {
func addSubscriber(subscriber: MessageConsumer)
@vittoriom
vittoriom / resetAllSimulators.sh
Last active August 29, 2015 14:27 — forked from ZevEisenberg/resetAllSimulators.sh
Reset all iOS simulators with this one weird trick
View resetAllSimulators.sh
osascript -e 'tell application "iOS Simulator" to quit'
xcrun simctl list devices | grep -v '^[-=]' | grep -v 'unavailable' | cut -d "(" -f2 | cut -d ")" -f1 | xargs -I {} xcrun simctl erase "{}"
@vittoriom
vittoriom / Playground.swift
Last active August 29, 2015 14:14
Talking protocols
View Playground.swift
// Playground - noun: a place where people can play
// Please see http://ashfurrow.com/blog/protocols-and-swift/ to know what this is all about
protocol FoodConsumer {
var calorieCount: Double { get set }
var hydrationLevel: Double { get set }
}
protocol Food {
//By having a simple generic function we don't have to cast the returned value when we call the method on the food
@vittoriom
vittoriom / gist:9789960
Created March 26, 2014 18:26
using VMDInstrumenter to track screen views with Google Analytics in a clean way (for example in a category of the UIViewController)
View gist:9789960
- (void)setupAnalytics
{
VMDInstrumenter *shared = [VMDInstrumenter sharedInstance];
[shared instrumentSelector:@selector(viewDidAppear:)
forInstancesOfClass:[VMBaseViewController class]
passingTest:^BOOL(VMBaseViewController *instance) {
//You can put whatever test you want here
return [instance conformsToProtocol:@protocol(VMTrackableScreen)];
} withBeforeBlock:nil
afterBlock:^(VMBaseViewController *instance) {