Skip to content

Instantly share code, notes, and snippets.

View pietrorea's full-sized avatar
✌️

Pietro Rea pietrorea

✌️
View GitHub Profile
@pietrorea
pietrorea / TPSpringyModalTransition.h
Created May 15, 2014 12:46
TPSpringyModalTransition - modal transition that bounces off the top like a spring
// TPSpringyModalTransition.h
// iPeru
//
// Created by Pietro Rea on 5/4/14.
// Copyright (c) 2014 Pietro Rea. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface TPSpringyModalTransition : NSObject <UIViewControllerAnimatedTransitioning>
@pietrorea
pietrorea / CoreDataManager.swift
Created June 16, 2014 06:49
Simple Core Data stack
import CoreData
class CoreDataManager {
var context:NSManagedObjectContext
var psc:NSPersistentStoreCoordinator
var model:NSManagedObjectModel
var store:NSPersistentStore?
init() {
@pietrorea
pietrorea / gist:15a0697f2aaf6d682ac6
Created July 30, 2014 00:48
Convert RFC 3339 formatted date string to NSDate
//From https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html
- (NSDate *)dateFromRFC3339String:(NSString *)dateString {
static NSDateFormatter *sRFC3339DateFormatter = nil;
if (sRFC3339DateFormatter == nil) {
sRFC3339DateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[sRFC3339DateFormatter setLocale:enUSPOSIXLocale];
@pietrorea
pietrorea / gist:089e308b4e9b46ded3ae
Last active August 29, 2015 14:05
Auto Layout ambiguous constraints debugging tool
//In UIViewController subclass
@interface UIWindow (AutoLayoutDebug)
+ (UIWindow *)keyWindow;
- (NSString *)_autolayoutTrace;
@end
- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation
{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
@pietrorea
pietrorea / gist:fbd09d5496bd018f6354
Created August 31, 2014 14:07
debugLog preprocessor macro
//Add to Project-Prefix.pch
#ifdef DEBUG
#define debugLog(...) NSLog(__VA_ARGS__)
#else
#define debugLog(...) // Nothing
#endif
NSString *html = @"<bold>Wow!</bold> Now <em>iOS</em> can create <h3>NSAttributedString</h3> from HTMLs!";
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil];
@pietrorea
pietrorea / gist:9887ce31f1d09c87114b
Last active August 29, 2015 14:09
Weak reference to self within a Swift block
let dataTask = urlSession.dataTaskWithURL(url!, completionHandler: { [unowned self] (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
//add code here
})
@pietrorea
pietrorea / gist:8309d74336bd82c127ae
Created December 7, 2014 22:37
Cast Swift closure as Objective-C block (needed for JavaScriptCore)
var block : @objc_block (NSString!) -> Void = {
[unowned self] (string : NSString!) -> Void in
let jsText = "\(string)\n"
self.outputTextView.setText(jsText, concatenate: true)
}
context.setObject(unsafeBitCast(block, AnyObject.self),
forKeyedSubscript: "print")
@pietrorea
pietrorea / xcci.md
Created October 26, 2015 16:35 — forked from quellish/xcci.md
Xcode CI script variables

Variable

Type

@pietrorea
pietrorea / UIViewController+Containment.swift
Created November 12, 2015 18:56
UIViewController+Containment.swift
import UIKit
extension UIViewController {
func addChildVC(viewController: UIViewController) {
addChildViewController(viewController)
view.addSubview(viewController.view)
viewController.didMoveToParentViewController(self)
}
}