Skip to content

Instantly share code, notes, and snippets.

View ricardopereira's full-sized avatar
🏠
Working from home

Ricardo Pereira ricardopereira

🏠
Working from home
View GitHub Profile
let currentRunloop = CFRunLoopGetCurrent()
print("Before delay")
delay(3.0) {
print("Delay execution")
CFRunLoopPerformBlock(currentRunloop, NSRunLoopCommonModes) {
print("Perform block")
}
CFRunLoopWakeUp(currentRunloop)
}
print("After delay")
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let photoURL1 = URL(string: "https://i.imgur.com/Si2l3kd.png")!
//let photoURL2 = URL(string: "https://jxccsa.bn1.livefilestore.com/y2m5XyfjXFW78kXvn3-McCXl5926JSzKH-n7hysppnCZxn_hnMPjwWA2dT11K_pInOZYJArvCzlh0_Aozw2ZK_4sBMspJx23DN1kNX8IfRW4_cBuasM9pEUvOTup6p9KCCm/AE1.jpg?psid=1")!
@ricardopereira
ricardopereira / DataService.swift
Created January 4, 2017 16:26 — forked from marinbenc/DataService.swift
Automatically create simple mocks for protocols in Swift
import Foundation
/// Protocols confoming to this protocol will have a mock generated for them.
protocol AutoMockable {}
protocol DataServiceProtocol: AutoMockable {
func fetchResource(fromURL url: URL, onComplete: (Result)-> Void)
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// by calling [NSURLProtocol registerClass:[MyURLProtocol class]]; in -application:didFinishLoadingWithOptions:, your protocol will have priority over any of the built-in protocols.
URLProtocol.registerClass(ActivityURLProtocol.self)
//URLProtocol.unregisterClass(ActivityURLProtocol.self)
print(URLSession.shared.configuration.protocolClasses)
}
@ricardopereira
ricardopereira / StoryboardBackedViewController.h
Created January 20, 2017 14:07 — forked from JaviSoto/SampleViewController.swift
Init based Storyboard View Controller Instantiation
//
// StoryboardBackedViewController.h
// Fabric
//
// Created by Javier Soto on 9/6/15.
// Copyright © 2015 Fabric. All rights reserved.
//
#import <UIKit/UIKit.h>
//===--- Result.swift -----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
import Foundation
public typealias JSON = AnyObject
public protocol JSONDecodable {
associatedtype DecodedType = Self
static func decode(json: JSON) -> JSONDecoded<DecodedType>
}
public enum JSONDecoded<T> {
@ricardopereira
ricardopereira / UITableView_tableHeaderView+AutoLayout.m
Last active February 17, 2017 08:59
Variable-height UITableView tableHeaderView with autolayout
// in a UITableViewController (or any other view controller with a UITableView)
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, 0)];
header.translatesAutoresizingMaskIntoConstraints = NO;
// [add subviews and their constraints to header]
NSLayoutConstraint *headerWidthConstraint = [NSLayoutConstraint
class NotificationToken {
let token: NSObjectProtocol
let center: NSNotificationCenter
init(token: NSObjectProtocol, center: NSNotificationCenter) {
self.token = token
self.center = center
}
@ricardopereira
ricardopereira / .vimrc
Last active February 21, 2017 16:07 — forked from bendc/.vimrc
Vim config (`vim +PluginInstall +qall`)
set nocompatible
set encoding=utf-8 nobomb
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Vundle
Plugin 'VundleVim/Vundle.vim'