Skip to content

Instantly share code, notes, and snippets.

View makthrow's full-sized avatar

Alan Jaw makthrow

View GitHub Profile
@makthrow
makthrow / PreviewViewController(cancel not working).swift
Last active December 1, 2016 01:27
preview cam - dismiss view not working
CamViewController
// self.performSegue(withIdentifier: "preview", sender: self)
// leads to PreviewViewController
// PreviewViewController.swift
import UIKit
import AVKit
import AVFoundation
class PreviewViewController: UIViewController {
import UIKit
import AVFoundation
import AssetsLibrary
import Photos
import MobileCoreServices
import FirebaseAuth
import CoreLocation
import RecordButton
// TODO: iOS9.0 - rewrite using Photos framework
PHPhotoLibrary.shared().performChanges({
let request = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: outputFileURL)
}, completionHandler: { (success, error) in
if !success { NSLog("error creating asset: \(error)") }
})
// ALAssetsLibrary().writeVideoAtPath(toSavedPhotosAlbum: outputFileURL, completionBlock: {
@makthrow
makthrow / fixed number of cells per row UICollectionViewController
Created March 10, 2016 01:58
set fixed number of cells per row in UICollectionViewController
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
let totalSpace = flowLayout.sectionInset.left
+ flowLayout.sectionInset.right
+ (flowLayout.minimumInteritemSpacing * CGFloat(numberOfItemsPerRow - 1))
let size = Int((collectionView.bounds.width - totalSpace) / CGFloat(numberOfItemsPerRow))
@makthrow
makthrow / newPostVC 430pm
Created March 9, 2016 00:30
saveiconPost() methods
//
// NewPostViewController.swift
// didyoulift
//
// Created by Alan Jaw on 3/2/16.
// Copyright © 2016 Alan Jaw. All rights reserved.
//
import UIKit
import Firebase
@makthrow
makthrow / SaveImagetoFirebase.swift
Last active November 28, 2016 05:33
saving and getting images in base64 string to Firebase
var data: NSData = NSData()
if let image = photoImageView.image {
data = UIImageJPEGRepresentation(image,0.1)!
}
let base64String = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
let user: NSDictionary = ["name":name!,"dob":dateOfBirthTimeInterval, "photoBase64":base64String]
@makthrow
makthrow / Extension for UIViewController for easy NavCon handling
Last active March 3, 2016 23:22
Extension to UIViewController for easy handling of navigationControllers that are destinationViewControllers
// as described in CS193P
// If i'm a navigationController, then return my visible View Controller. otherwise, return myself
// now i can send to any viewcontroller, give me the content view controller. if you are the content view controller,
// you give me yourself. if you are a nav controller, you give me the visible view controller
extension UIViewController {
var contentViewController: UIViewController {
if let navcon = self as? UINavigationController {
return navcon.visibleViewController
}
@makthrow
makthrow / FBSDK getFacebookInfo example Swift
Created March 1, 2016 22:44
FBSDK get facebook usr info function in swift
func getFBUserInfo() {
let facebookRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "name, gender, picture, birthday, first_name, last_name"])
facebookRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result, error) -> Void in
if error == nil {
print ("result: \(result)")
var r = result as! NSDictionary
//
// ViewController.swift
//
// Created by Alan Jaw on 2/29/16.
// Copyright © 2016 Alan Jaw. All rights reserved.
//
import UIKit
import FBSDKLoginKit
import Firebase
// FBSDKLoginButtonDelegate has two required methods
// loginButtonDidLogOut and loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult
//
// ViewController.swift
//
// Created by Alan Jaw on 2/29/16.
// Copyright © 2016 Alan Jaw. All rights reserved.
//