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
@mattt
mattt / UIViewControllerPreview.swift
Last active Jan 15, 2020
Generic structures to host previews of UIView and UIViewController subclasses.
View UIViewControllerPreview.swift
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
View with.swift
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
@raven
raven / ViewController.swift
Last active May 11, 2017
rdar://30739102
View ViewController.swift
//
// ViewController.swift
// AttributedString
//
// Created by Peter Goldsmith on 27/02/2017.
//
import UIKit
class ViewController: UIViewController {
@JohnSundell
JohnSundell / Perform.swift
Last active Dec 21, 2019
A function that enables you to easily wrap throwing APIs, to provide a custom error
View Perform.swift
/**
* Perform a throwing expression, and throw a custom error in case the expression threw
*
* - parameter expression: The expression to execute
* - parameter error: The custom error to throw instead of the expression's error
* - throws: The given error
* - returns: The return value of the given expression
*/
func perform<T>(_ expression: @autoclosure () throws -> T, orThrow errorExpression: @autoclosure () -> Error) throws -> T {
do {
@simme
simme / debounce-throttle.swift
Created Dec 20, 2016
Swift 3 debounce & throttle
View debounce-throttle.swift
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
@YusukeHosonuma
YusukeHosonuma / UIViewController.swift
Last active Oct 12, 2017
Capture UITableView full content.
View UIViewController.swift
//
// ViewController.swift
// UIViewCapture
//
// Created by Yusuke on 11/7/16.
// Copyright © 2016 Yusuke. All rights reserved.
//
import UIKit
View UserDefaultable.swift
//:
//: UserDefaultable.swift
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import Foundation
// MARK: - Key Namespaceable
@Gurdeep0602
Gurdeep0602 / AppStoryboard.swift
Last active Jan 10, 2020
AppStoryboard enumeration
View AppStoryboard.swift
//
// AppStoryboards.swift
// AppStoryboards
//
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
//
import Foundation
import UIKit
@steipete
steipete / gist:d9b44d8e9f341e81414e86d7ff8fb62d
Last active Jan 14, 2020
Using iOS 13.2 devices with Xcode 11.1 (instead of Xcode 11.2) (also, Xcode 10.3)
View gist:d9b44d8e9f341e81414e86d7ff8fb62d
// The trick is to link the DeviceSupport folder from the beta to the stable version.
// sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
// Support iOS 13.2 devices (Xcode 11.2) with Xcode 11.1:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.2 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Xcode 10.3 to Xcode 11
sudo ln -s /Applications/Xcode-11.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.0 /Applications/Xcode-10.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active Jan 13, 2020
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics
View ios-cell-registration-swift.md

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
You can’t perform that action at this time.