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
// That’s marked @nonobjc so it won’t conflict with any of Apple’s own code, now or in the future. | |
@nonobjc extension UIViewController { | |
func add(_ child: UIViewController, frame: CGRect? = nil) { | |
addChildViewController(child) | |
if let frame = frame { | |
child.view.frame = frame | |
} | |
view.addSubview(child.view) | |
child.didMove(toParentViewController: 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
extension UIView { | |
func add(_ subviews: UIView...) { | |
subviews.forEach(addSubview) | |
} | |
} | |
view.add(button) | |
view.add(label) | |
// By dropping the "Subview" suffix from the method name, both |
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 Encodable { | |
func encode(with encoder: JSONEncoder = JSONEncoder()) throws -> Data { | |
return try encoder.encode(self) | |
} | |
} | |
extension Decodable { | |
static func decode(with decoder: JSONDecoder = JSONDecoder(), from data: Data) throws -> Self { | |
return try decoder.decode(Self.self, from: 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
TAGS="TODO:|FIXME:|WARNING:" | |
ERRORTAG="ERROR:" | |
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"| perl -p -e "s/($ERRORTAG)/ error: \$1/" |
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 | |
import CoreImage | |
class ImagePainter { | |
let context = CIContext(options:[kCIImageColorSpace: NSNull()]) | |
let filter = CIFilter(name: "CIFalseColor", | |
withInputParameters: ["inputColor1" : CIColor(color: .black)]) | |
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 pinEdgesToSafeArea(of view: UIView) { | |
self.translatesAutoresizingMaskIntoConstraints = false | |
self.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true | |
self.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true | |
self.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true | |
self.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true | |
} |
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 extension UITableView { | |
public func setAutomaticRowHeight() { | |
estimatedRowHeight = UITableViewAutomaticDimension | |
rowHeight = UITableViewAutomaticDimension | |
} | |
} |
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 { | |
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()) | |
} |
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) | |
} | |
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) | |
} | |