Skip to content

Instantly share code, notes, and snippets.

import Focus // https://github.com/typelift/Focus
struct Foo {
let bar: Int
let baz: Bool
static let bar = SimpleLens(get: {
$0.bar
}, set: { (oldFoo, newBar) in
Foo(bar: newBar, baz: oldFoo.baz)
import UIKit
private let UnknownNibName = ""
protocol NibLoadable: class {
typealias Object
static var nibName: String { get }
static func nib(name: String) throws -> UINib
static func firstObjectFromNib(nib: UINib) throws -> Object
@nikita-leonov
nikita-leonov / SafeExtension.swift
Created January 6, 2016 19:09
Safe Extensions with Namespaces
class ExternalClass {}
extension ExternalClass {
struct Namespace {
static func method() {
print("namespaced method call")
}
}
}
@nikita-leonov
nikita-leonov / insecure-registry alternative
Created November 6, 2015 21:06
insecure-registry alternative
$ docker pull host:5000/image #fails
$ ssh -N -L 5000:host:5000 user@host
$ docker pull localhost:5000/image #works
@nikita-leonov
nikita-leonov / generic-protocols.swift
Created October 31, 2015 05:54
`Generic` Protocols
class Container<T> {
private var containedValue: T
init(_ value: T) {
containedValue = value
}
}
protocol ContainerProtocol {
typealias ValueType
@nikita-leonov
nikita-leonov / sample.swift
Created June 25, 2015 00:34
Modification suggestion for interface of Quick itBehavesLike and sharedExamples functions
protocol Example { }
struct SharedExample<T>: Example {
let closure: ((T)) -> ()
init(_ closure: ((T)) -> ()) {
self.closure = closure
}
}
class World {
@nikita-leonov
nikita-leonov / AppDelegate.m
Created June 17, 2015 19:08
NLServiceLocator sample
#import "Service.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NLServiceLocator registerService:[[Service alloc] init]];
}
@end
@nikita-leonov
nikita-leonov / MyWebService.h
Last active August 29, 2015 13:56
ROADFramework web service method annotation sample
RF_ATTRIBUTE(RFWebService, serviceRoot = @"http://api.myproduct.com/")
@interface MyWebService : RFWebServiceClient //Service need to be inherited from RFWebServiceClient as it responsible for resolving web service call methods defined by attributes.
RF_ATTRIBUTE(RFWebServiceCall, method = @"GET", relativePath = @"resource/%%0%%" prototypeClass = [MyWebServiceResponse class]) //RelativePath used to map defined method relatively to serviceRoot provided earlier. Templating that defined by %% maps method parameters into call URL. Prototype class used for proper serialization of web service responses.
RF_ATTRIBUTE(RFWebServiceHeader, headerFields = @{@"Text" : %%1%%}) //The same templathing mechanism could be used for mapping header fields
- (id<RFWebServiceCancellable>)webCallURLParam:(NSString *)urlParam headerParam:(NSString *)headerParam (void(^)(MyWebServiceResponse result))successBlock failure:(void(^)(NSError *error))failureBlock; //Implementation of method not required as behavior defined by attributes,