Skip to content

Instantly share code, notes, and snippets.


StanislavK StanislavK

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 Data+ext.swift
extension Data {
func decoded<T: Decodable>(
as type: T.Type = T.self,
handledOn resultQueue: DispatchQueue = .main,
handler: @escaping (Result<T, Error>) -> Void
) {
let queue = DispatchQueue(label: "com.myapp.decoding")
let decoder = JSONDecoder()
queue.async {
View gist:9233c7f229f58fc10d03f9518dd5e3d4
#Use this when you need to have working playground and project: see more at
View UIFont+Extensions.swift
extension UIFont {
class func printAllFonts() {
UIFont.familyNames().forEach { family in
UIFont.fontNamesForFamilyName(family).forEach { font in
View IsConnected.swift
// Simple check if connected to internet
func isConnected() -> Bool {
// we need SCNetworkReachability object
guard let reachability = SCNetworkReachabilityCreateWithName(nil, "") else { return false }
// and flags
var flags = SCNetworkReachabilityFlags()
// read the "flags" into flags (via SCNetworkReachabilityGetFlags)
SCNetworkReachabilityGetFlags(reachability, &flags)
View Foo.swift
class SharePromptView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
func createSubviews() {
View UIViewController+Extensions.swift
// 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) {
if let frame = frame {
child.view.frame = frame
child.didMove(toParentViewController: self)
View Foo.swift
extension UIView {
func add(_ subviews: UIView...) {
// By dropping the "Subview" suffix from the method name, both
View Codable+Extensions.swift
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)
StanislavK / Foo.txt
Last active Feb 23, 2018
Make TODO: + FIXME: + WARNING: as warnings, ERROR: as error
View Foo.txt
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/"
View ImagePainter.swift
import UIKit
import CoreImage
class ImagePainter {
let context = CIContext(options:[kCIImageColorSpace: NSNull()])
let filter = CIFilter(name: "CIFalseColor",
withInputParameters: ["inputColor1" : CIColor(color: .black)])
You can’t perform that action at this time.