Skip to content

Instantly share code, notes, and snippets.

View endodoug's full-sized avatar
🎯
Not around

Doug Harper endodoug

🎯
Not around
View GitHub Profile
@endodoug
endodoug / randomNumbers.swift
Created November 4, 2016 02:37
Random Numbers - Swift 3
func randomFloat(from from:CGFloat, to:CGFloat) -> CGFloat {
let rand:CGFloat = CGFloat(Float(arc4random()) / 0xFFFFFFFF)
return (rand) * (to - from) + from
}
func randomInt(n: Int) -> Int {
return Int(arc4random_uniform(UInt32(n)))
}
@endodoug
endodoug / savePhotoToLibrary.swift
Last active November 4, 2016 02:35
Save Photo to Library - Swift 3
func savePhotoToLibrary(image: UIImage) {
let photoLibrary = PHPhotoLibrary.shared()
photoLibrary.performChanges({
PHAssetChangeRequest.creationRequestForAsset(from: image)
}) { (success: Bool, error: Error?) -> Void in
if success {
// Set thumbnail
self.setPhotoThumbnail(image: image)
} else {
print("Error writing to photo library: \(error!.localizedDescription)")
@endodoug
endodoug / arrayOfDictionaries.swift
Created September 16, 2015 23:04
Load plist arrary of dictionaries
var data = [String]()
var dataDescription = [String]()
override func viewDidLoad() {
super.viewDidLoad()
if let myPath = NSBundle.mainBundle().pathForResource("data", ofType: "plist") {
if let arrayOfDictionaries = NSArray(contentsOfFile: myPath) {
for dict in arrayOfDictionaries {
data.append(dict.objectForKey("title") as! String)
@endodoug
endodoug / plistDictionary.swift
Created September 16, 2015 23:01
Load plist dictionary in tableview
var tableData = [String]()
override func viewDidLoad() {
super.viewDidLoad()
var dict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("TableData", ofType: "plist") {
dict = NSDictionary(contentsOfFile: path)
}
@endodoug
endodoug / GameCenter
Created April 15, 2015 04:23
Game Center Integration
import GameKit
class GameScene: SKScene, GKGameCenterControllerDelegate {
var gcEnabled = Bool()
var gcDefaultLeaderboard = String()
var LeaderboardID = "com.endodoug.MagicalLeaderboard"
}
override func didMoveToView(view: SKView) {
AuthenticateLocalPlayer()
@endodoug
endodoug / Email
Created April 15, 2015 02:47
Swift Email - In app
import UIKit
import MessageUI
import Foundation
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@endodoug
endodoug / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console