I hereby claim:
- I am viccc on github.
- I am victoriagloba (https://keybase.io/victoriagloba) on keybase.
- I have a public key ASC6k96-hMUEEVa7YzhUaUTNvcs08zR8X218Ygkrzd8DSgo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| extension NSBundle { | |
| static func appDisplayName(context: NSFormattingContext) -> String { | |
| if let str = NSBundle.mainBundle().localizedInfoDictionary?["CFBundleDisplayName"] as? String { | |
| return str | |
| } | |
| if let str = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleDisplayName") as? String { | |
| return str | |
| } | |
| func size(_ imageSize: CGSize, constrainedToSize maxSize: CGSize) -> CGSize { | |
| if maxSize.width > 0 && maxSize.height > 0 && (maxSize.width < imageSize.width || maxSize.height < imageSize.height) | |
| { | |
| let constrainedSize: CGSize | |
| let constrainedHeight = min(imageSize.height, maxSize.height) | |
| let scaleProportionalToHeight = constrainedHeight / imageSize.height | |
| let sizeProportionalToHeight = CGSize(width: round(imageSize.width * scaleProportionalToHeight), height: constrainedHeight) | |
| let constrainedWidth = min(imageSize.width, maxSize.width) |
| extension NSFileManager { | |
| class func uniqueDocumentFileURLWithBaseName(baseName: String) throws -> NSURL { | |
| let directoryUrl = try NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true) | |
| return try directoryUrl.URLByAppendingUniqueFileNameWithBaseName(baseName) | |
| } | |
| class func uniqueAppSupportFileURL(inSubdirectory subdirectory: String, uniqueFileBaseName baseName: String) throws -> NSURL { | |
| let appSupportUrl = try NSFileManager.defaultManager().URLForDirectory(.ApplicationSupportDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true) | |
| let directoryUrl: NSURL | |
| if subdirectory.isEmpty { |
| override func viewDidAppear(animated: Bool) { | |
| super.viewDidAppear(animated) | |
| #if DEBUG | |
| // Shake to debug | |
| becomeFirstResponder() | |
| #endif | |
| // ... | |
| } |
| func randomInt(range: Range<Int>) -> Int { | |
| let base = range.endIndex - range.startIndex | |
| let r = arc4random_uniform(UInt32(base)) | |
| let n = Int(r) + range.startIndex | |
| return n | |
| } |
| func normalizeImageOrientationIfNeeded(image: UIImage) -> UIImage { | |
| if image.imageOrientation == .Up { | |
| return image | |
| } | |
| let size = image.size | |
| let scale = image.scale | |
| let rect = CGRectMake(0, 0, size.width, size.height) | |
| UIGraphicsBeginImageContextWithOptions(size, false, scale) |
| func imageWithPixelSize(size: CGSize, filledWithColor color: UIColor = UIColor.clearColor(), opaque: Bool = false) -> UIImage { | |
| return imageWithSize(size, filledWithColor: color, scale: 1.0, opaque: opaque) | |
| } | |
| func imageWithSize(size: CGSize, filledWithColor color: UIColor = UIColor.clearColor(), scale: CGFloat = 0.0, opaque: Bool = false) -> UIImage { | |
| let rect = CGRectMake(0, 0, size.width, size.height) | |
| UIGraphicsBeginImageContextWithOptions(size, opaque, scale) | |
| color.set() | |
| UIRectFill(rect) |
| func downscaleImage(image: UIImage, toPixelSize targetSize: CGSize) -> UIImage { | |
| return downscaleImage(image, toSize: targetSize, scale: 1.0) | |
| } | |
| func downscaleImage(image: UIImage, toSize targetSize: CGSize, scale: CGFloat = 0.0) -> UIImage { | |
| let actualScaleFactor = (scale == 0.0) ? UIScreen.mainScreen().scale : scale | |
| let size = image.size | |
| let imageScaleFactor = image.scale | |
| let imagePixelSize = CGSizeMake(size.width * imageScaleFactor, size.height * imageScaleFactor) | |
| // | |
| // RBResizer.swift | |
| // Locker | |
| // | |
| // Created by Hampton Catlin on 6/20/14. | |
| // Copyright (c) 2014 rarebit. All rights reserved. | |
| // | |
| import UIKit |