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
public struct DeviceModel { | |
/// Returns true, if iPhoneX is detected | |
/// Detection is based on the portrait height, see https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/ | |
public static var isiPhoneX: Bool = { | |
let iPhoneXPortaitHeight: CGFloat = 812 | |
let currentDevicePortraitHeight: CGFloat = UIScreen.main.fixedCoordinateSpace.bounds.size.height | |
return currentDevicePortraitHeight == iPhoneXPortaitHeight ? true : false | |
}() | |
} |
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
let searchController = UISearchController(searchResultsController: nil) | |
if #available(iOS 11.0, *) { | |
self.navigationItem.searchController = searchController | |
searchController.isActive = true | |
} | |
else { | |
present(searchController, animated: true, completion: 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 { | |
/** Get email addresses in a string, discard any other content. */ | |
func emailAddresses() -> [String] { | |
var addresses = [String]() | |
if let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) { | |
let matches = detector.matches(in: self, options: [], range: NSMakeRange(0, self.count)) | |
for match in matches { | |
if let matchURL = match.url, | |
let matchURLComponents = URLComponents(url: matchURL, resolvingAgainstBaseURL: false), | |
matchURLComponents.scheme == "mailto" |
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 printAllFontNames() { | |
let fontFamilyNames = UIFont.familyNames | |
for familyName in fontFamilyNames { | |
print("------------------------------") | |
print("Font Family Name = [\(familyName)]") | |
let names = UIFont.fontNames(forFamilyName: familyName) | |
print("Font Names = [\(names)]") | |
} | |
} |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
// Computed property | |
// NOTE: Since a computed property gets reassigned upon every access!, it can only be declared as a var and not a let. | |
var urlSession: URLSession { | |
let urlSessionConfiguration: URLSessionConfiguration = URLSessionConfiguration.default.copy() as! URLSessionConfiguration | |
urlSessionConfiguration.requestCachePolicy = NSURLRequest.CachePolicy.returnCacheDataElseLoad | |
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 Bool { | |
mutating func toggle() { | |
self = !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 UIKit | |
protocol ReusableView: class {} | |
extension ReusableView { | |
static var reuseIdentifier: String { | |
return String(describing: 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 UIKit | |
protocol NibLoadableView: class { } | |
extension NibLoadableView { | |
static var nibName: String { | |
return String(describing: 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 UIKit | |
extension UITableView { | |
func register<T: UITableViewCell>(_: T.Type) { | |
let nib = UINib(nibName: T.nibName, bundle: nil) | |
register(nib, forCellReuseIdentifier: T.reuseIdentifier) | |
} | |