This file contains hidden or 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 Foundation | |
| extension Data { | |
| var hexString: String { | |
| return self.map({ return String(format: "%02hhx", $0) }).joined() | |
| } | |
| } |
This file contains hidden or 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 Foundation | |
| // Let's use a Command protocol... | |
| protocol Command { | |
| associatedtype Action | |
| static func modalAlert(title: String, accept: String) -> Self | |
| static func request(_ request: URLRequest, available: @escaping (Data?) -> Action) -> Self | |
| } |
This file contains hidden or 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 Foundation | |
| enum Either<A,B> { | |
| case left(A) | |
| case right(B) | |
| } | |
| // Works only using Swift 4.1 | |
| extension Either: Codable where A: Codable, B: Codable { | |
| enum CodingKeys: CodingKey { |
This file contains hidden or 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
| // | |
| // main.swift | |
| // ExtensibleEffects | |
| // | |
| // Created by Chris Eidhof on 02.01.18. | |
| // Copyright © 2018 objc.io. All rights reserved. | |
| // | |
| import Foundation |
This file contains hidden or 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
| // UICollectionView Objective-C example | |
| - (void)viewWillAppear:(BOOL)animated { | |
| [super viewWillAppear:animated]; | |
| NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject]; | |
| if (selectedIndexPath != nil) { | |
| id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator; | |
| if (coordinator != nil) { | |
| [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { |
This file contains hidden or 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
| protocol ControlEventBindable: class { } | |
| extension UIControl: ControlEventBindable { } | |
| extension UIBarButtonItem: ControlEventBindable { } | |
| private struct Keys { | |
| static var EventHandlers = "_EventHandlers" | |
| } | |
| // MARK: - Implementation |
This file contains hidden or 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
| /* | |
| Instead of using enum it's possible to use RawRepresentable struct that will give you support for "unsupported" values, | |
| but will cost you excastive switches (you'll alwyas have to handle default case, which will stand for those "unsupported" values) | |
| It's defenetely more code than if using optional, but might be better if it comes to unwrapping this value everywhere. | |
| */ | |
| //enum System: String, Decodable { | |
| // case ios, macos, tvos, watchos | |
| //} | |
| struct System: RawRepresentable, Decodable { |
This file contains hidden or 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
| protocol LayoutGuideProvider { | |
| var leadingAnchor: NSLayoutXAxisAnchor { get } | |
| var trailingAnchor: NSLayoutXAxisAnchor { get } | |
| var leftAnchor: NSLayoutXAxisAnchor { get } | |
| var rightAnchor: NSLayoutXAxisAnchor { get } | |
| var topAnchor: NSLayoutYAxisAnchor { get } | |
| var bottomAnchor: NSLayoutYAxisAnchor { get } | |
| var widthAnchor: NSLayoutDimension { get } | |
| var heightAnchor: NSLayoutDimension { get } | |
| var centerXAnchor: NSLayoutXAxisAnchor { get } |
This file contains hidden or 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 | |
| /// A UITableViewCell that loads a custom UIView into its .contentView | |
| /// the typed view can be accessed via the .customView property | |
| open class GenericTableViewCell<View: UIView>: UITableViewCell { | |
| // MARK: - Properties | |
| public let customView = View() | |
| // MARK: - Lifecycle | |
| public override init(style: UITableViewCellStyle, reuseIdentifier: String?) { |
This file contains hidden or 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
| // First make sure that you have granted access to Automator, Xcode and Paw in accessibility section in Security & Privacy settings. | |
| // Then create a new Service workflow in Automator with following actions: | |
| 1. Copy to clipboard | |
| 2. Launch Application: "Paw" | |
| 3. Run AppleScript: | |
| tell application "System Events" | |
| tell process "Paw" | |
| click menu item "Text" of menu 1 of menu item "Import" of menu 1 of menu bar item "File" of menu bar 1 |