Skip to content

Instantly share code, notes, and snippets.

View pietrorea's full-sized avatar
✌️

Pietro Rea pietrorea

✌️
View GitHub Profile
@pietrorea
pietrorea / UIAlertController.swift
Last active November 27, 2016 19:04
UIAlertController example
var alert = UIAlertController(title: "Title", message: "Alert view message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Save", style: .Default, handler: { (action: UIAlertAction!) in
println("Saved")
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in
println("Cancel")
}))
presentViewController(alert, animated: true, completion: nil)
@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 / 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 / gist:4636954
Created January 25, 2013 19:08
How to move a UIView above the keyboard when the keyboard comes on screen. The method keyboardWillShow handles the notification UIKeyboardWillShowNotification.
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect convertedFrame = [self.view convertRect:keyboardFrame fromView:self.view.window];
CGFloat animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve animationCurve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
[UIView animateWithDuration:animationDuration delay:0 options:animationCurve animations:^{
self.viewToMove.bottom = self.view.height - convertedFrame.size.height - 15;