This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a new MKMapCamera object. | |
//Looking at, is where you want it to look at, in this example I keep it the same so use the map views current center coordinate | |
//I up the altitude (zoom out) by adding 1600 on to the current position | |
//Pitch and heading are the rotation and angle of the camera | |
let newCameraPosition = MKMapCamera(lookingAtCenterCoordinate: mapView.centerCoordinate, fromDistance: mapView.camera.altitude + 1600, pitch: 50, heading: -30) | |
//Animate the camera, here over 5 seconds with a 1.5 second delay, the options are fairly self explanitory. | |
UIView.animateWithDuration(5, delay: 1.5, options: [.AllowUserInteraction, .CurveEaseInOut], animations: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
func blurView(style: UIBlurEffect.Style) { | |
var blurEffectView = UIVisualEffectView() | |
let blurEffect = UIBlurEffect(style: style) | |
blurEffectView = UIVisualEffectView(effect: blurEffect) | |
blurEffectView.frame = bounds | |
addSubview(blurEffectView) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getSnapshotImage() -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0) | |
self.drawViewHierarchyInRect(self.bounds, afterScreenUpdates: false) | |
let snapshotImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return snapshotImage | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftyJSON | |
protocol DataLoader { } | |
extension DataLoader { | |
func loadJSON(fileName: String, type: String = "json") -> JSON? { | |
let filePath = NSBundle.mainBundle().pathForResource(fileName, ofType: type) | |
if let data = NSData(contentsOfFile: filePath!) { | |
let json = JSON(data: data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIImage { | |
func resizeWith(percentage: CGFloat) -> UIImage? { | |
let imageView = UIImageView(frame: CGRect(origin: .zero, size: CGSize(width: size.width * percentage, height: size.height * percentage))) | |
imageView.contentMode = .scaleAspectFit | |
imageView.image = self | |
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, scale) | |
guard let context = UIGraphicsGetCurrentContext() else { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getDuration(pointA: CGPoint, pointB: CGPoint, speed: CGFloat) -> TimeInterval { | |
let xDist = (pointB.x - pointA.x) | |
let yDist = (pointB.y - pointA.y) | |
let distance = sqrt((xDist * xDist) + (yDist * yDist)); | |
let duration = TimeInterval(distance/speed) | |
return duration | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImageView { | |
public func imageFromServerURL(urlString: String) { | |
URLSession.shared.dataTask(with: NSURL(string: urlString)! as URL, completionHandler: { (data, response, error) -> Void in | |
if error != nil { return } | |
DispatchQueue.main.async(execute: { () -> Void in | |
let image = UIImage(data: data!) | |
self.image = image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
static func randomString(length: Int) -> String { | |
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
let len = UInt32(letters.length) | |
var randomString = "" | |
for _ in 0 ..< length { | |
let rand = arc4random_uniform(len) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SKTileMapNode { | |
func loopThroughTiles(completionClosure: (_ col: Int, _ row: Int, _ tile: SKTileDefinition?) -> ()) { | |
for col in 0..<numberOfColumns { | |
for row in 0..<numberOfRows { | |
completionClosure(col, row, tileDefinition(atColumn: col, row: row)) | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Firebase | |
extension DataSnapshot { | |
func toObject<T:Codable>() throws -> T { | |
var newValue = value as! [String: Any] | |
newValue["uid"] = key | |
let data = try! JSONSerialization.data(withJSONObject: newValue, options: .sortedKeys) | |
return try JSONDecoder().decode(T.self, from: data) | |
} |
OlderNewer