Skip to content

Instantly share code, notes, and snippets.

@pedromancheno
pedromancheno / reduce.txt
Created January 16, 2019 13:06
Using Swift's reduce method to construct a URL path with parameters
let params = [ "userID" : 1, "balance" : 1000 ]
let string: String = params.reduce("") {
if $0.isEmpty {
return $1.key + "=" + String($1.value)
} else {
return $0 + "&" + $1.key + "=" + String($1.value)
}
}
@pedromancheno
pedromancheno / ViewModel.swift
Last active March 22, 2017 21:11
Xcode snippet for quickly adding the structure of a ViewModel
protocol <#Name#>ViewModelInputs {
}
protocol <#Name#>ViewModelOutputs {
}
protocol <#Name#>ViewModelType {
var inputs: <#Name#>ViewModelInputs{ get }
var outputs: <#Name#>ViewModelOutputs { get }
}
@pedromancheno
pedromancheno / HTTP.swift
Created February 21, 2017 11:44
Wrapper for URLSession for making HTTP Requests.
import Foundation
enum Result<T> {
case success(T?)
case failure(Error)
}
enum HTTPError: Error {
case noResponse
case unsuccesfulStatusCode(Int)
git mergetool --tool=mergepbx <# ProjectName #>.xcodeproj/project.pbxproj
@pedromancheno
pedromancheno / CustomPresentationController.h
Last active May 11, 2017 13:57
Presenting a UIViewController modally, with a custom animations. Sample code for [http://bit.ly/2q5DeLM]
/**
* Presents a view controller modally by superposing it's view on top of the
* presenting's view, but retaining it's context.
*
* Useful for creating a modal presentation with a dimmed background.
*/
typedef enum {
@pedromancheno
pedromancheno / Swaping (key-value)
Last active December 25, 2015 15:29
Categories for NSDictionary and NSArray for swapping the keys of a dictionary for it's value.
@interface NSDictionary (Swapping)
- (NSDictionary *)dictionaryBySwappingKeyWithValue;
@end
@interface NSDictionary (Swapping)
- (NSDictionary *)dictionaryBySwappingKeyWithValue
{
@pedromancheno
pedromancheno / Swapping (key-newKey)
Last active December 25, 2015 15:09
Categories for NSDictionary and NSArray for swapping the keys of a dictionary.
@interface NSDictionary (Swapping)
- (NSDictionary *)dictionaryBySwappingKey:(id)oldKey withKey:(id)newKey;
@end
@implementation NSDictionary (Swapping)
- (NSDictionary *)dictionaryBySwappingKey:(id)oldKey withKey:(id)newKey
{