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 NSError { | |
var serializedErrorData: [String : AnyObject]? { | |
get { | |
if let responseData = userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] as? NSData { | |
if let data = try? NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.AllowFragments) as? [String : AnyObject] { | |
return data | |
} | |
} | |
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
extension String { | |
func fontSizeThatFitsWidth(size: CGSize, font: UIFont) -> CGFloat { | |
let testString = self as NSString | |
var fontSize: CGFloat = 100 | |
let minFontSize: CGFloat = 5 | |
while fontSize > minFontSize { | |
let testFont = font.fontWithSize(fontSize) | |
let textSize = testString.sizeWithAttributes([NSFontAttributeName : testFont]) |
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 | |
@IBDesignable class RoundedView: UIView { | |
@IBInspectable var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set(newRadius) { | |
layer.cornerRadius = newRadius ?? 0 |
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
#!/usr/bin/env xcrun --sdk macosx swift | |
// Use this gist in order to write values in your Info.plist as a run phase | |
// Remember to add a custom Build Phase in your targets running this file as a first step | |
import Foundation | |
let relativePlistFilesFolder = "/YOUR_INFO_LIST_FOLDER/" | |
let currentDirectoryPath = FileManager.default.currentDirectoryPath |
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
struct RuntimeClass { | |
private static var appName: String { | |
return Bundle.main.infoDictionary![kCFBundleNameKey as String] as! String | |
} | |
enum Class { | |
case Example | |
fileprivate var name: String { | |
switch self { |
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 | |
typealias ArrayOrderedUpdates<T: Equatable> = (added: [T], removed: [T]) | |
typealias ArrayNonOrderedUpdates<T: Hashable> = (added: [T], removed: [T]) | |
extension Array where Element: Hashable { | |
/// Returns values added and removed from arrays. Faster solution that returns a non-ordered array | |
static func diffArrays(lhs: [Element], rhs: [Element]) -> ArrayNonOrderedUpdates<Element> { | |
let leftSet = Set(lhs) | |
let rightSet = Set(rhs) |
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
// | |
// CellNib.swift | |
// miitiOS | |
// | |
// Created by Luis Fernando Mata on 8/31/19. | |
// Copyright © 2019 Miit. All rights reserved. | |
// | |
import UIKit |