Skip to content

Instantly share code, notes, and snippets.

🚜
Working

StanislavK StanislavK

🚜
Working
Block or report user

Report or block StanislavK

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View UITableView+Extension.swift
public extension UITableView {
public func setAutomaticRowHeight() {
estimatedRowHeight = UITableViewAutomaticDimension
rowHeight = UITableViewAutomaticDimension
}
}
View String+Extension.swift
extension String {
var first: String {
return String(characters.prefix(1))
}
var last: String {
return String(characters.suffix(1))
}
var uppercaseFirst: String {
return first.uppercased() + String(characters.dropFirst())
}
View Ext+UITableView.swift
import UIKit
extension UITableView {
func register<T: UITableViewCell>(_: T.Type) {
let nib = UINib(nibName: T.nibName, bundle: nil)
register(nib, forCellReuseIdentifier: T.reuseIdentifier)
}
View NibLoadableView.swift
import UIKit
protocol NibLoadableView: class { }
extension NibLoadableView {
static var nibName: String {
return String(describing: self)
}
View ReusableView.swift
import UIKit
protocol ReusableView: class {}
extension ReusableView {
static var reuseIdentifier: String {
return String(describing: self)
}
}
View Bool+Extension.swift
extension Bool {
mutating func toggle() {
self = !self
}
}
View ComputesVersusStoredExplained.swift
//: 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
View FontNemes.swift
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)]")
}
}
View String+Extensions.swift
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"
View Search controller fix for ios11
let searchController = UISearchController(searchResultsController: nil)
if #available(iOS 11.0, *) {
self.navigationItem.searchController = searchController
searchController.isActive = true
}
else {
present(searchController, animated: true, completion: nil)
}
You can’t perform that action at this time.