Skip to content

Instantly share code, notes, and snippets.

View alexj70's full-sized avatar

Alexandr alexj70

  • IdeaSoft
  • Ukraine
View GitHub Profile
0x5063Ea9d67FB408faff44CA1dd8DDDd0FfDEd269
@alexj70
alexj70 / UITesting.md
Created April 28, 2017 13:02
UI Testing

UI Testing

★ Get Application

let app = XCUIApplication()

accessibilityIdentifier by code

@alexj70
alexj70 / DispatchOnce.md
Last active April 28, 2017 10:59
DispatchOne Swift 3

DispatchOnce

Swift3.0

public extension DispatchQueue {
    private static var _onceTracker = [String]()
    
    public class func once(file: String = #file, function: String = #function, line: Int = #line, block:(Void)->Void) {
        let token = file + ":" + function + ":" + String(line)
 once(token: token, block: block)
@alexj70
alexj70 / MethodSwizzling.md
Created April 28, 2017 08:26
Method Swizzling

Method Swizzling

★ Replacement of viewWillAppear method

private let swizzling: (UIViewController.Type) -> () = { viewController in
    
    let originalSelector = #selector(viewController.viewWillAppear(_:))
    let swizzledSelector = #selector(viewController.proj_viewWillAppear(animated:))
@alexj70
alexj70 / OptionalString.md
Last active April 28, 2017 11:01
Optional Extension

String Optional Extension

Swift3.1

extension Optional where Wrapped == String {
var isNilOrEmpty: Bool {
        return ((self as? String) ?? "").isEmpty
    }
}
@alexj70
alexj70 / Singleton.md
Created April 27, 2017 21:21
Singleton

Singleton

class Singleton {
    static let sharedInstance = Singleton()
    private override init() {}
}
@alexj70
alexj70 / Resourse.md
Last active April 27, 2017 21:22
Resource

Resource

import Foundation
struct Resource {
    enum HTML: String, ResourceConvertible, Iteratable {
        case rightOfWithdrawal = "RightOfWithdrawal"
        case privatePolicy = "PrivatePolicy"
        case termsAndConditions = "TermsAndConditions"
    }
}
@alexj70
alexj70 / Iteratable.md
Last active April 25, 2017 17:23
Iteratable

Enum iteration

protocol Iteratable {}
extension RawRepresentable where Self: RawRepresentable {
    static func iterateEnum<T: Hashable>(_: T.Type) -> AnyIterator<T> {
        var i = 0
        return AnyIterator {
            let next = withUnsafePointer(to: &i) {
                $0.withMemoryRebound(to: T.self, capacity: 1) { $0.pointee }
 }
print("Movies by C. Columbus only:")
for case let Media.movie(title, director, year) in mediaList where director == "Chris Columbus" {
print(" - \(title) (\(year))")
}
/* Output:
Movies by C. Columbus only:
- Harry Potter and the Philosopher's Stone (2001)
- Harry Potter and the Chamber of Secrets (2002)
*/
enum Media {
case book(title: String, author: String, year: Int)
case movie(title: String, director: String, year: Int)
case website(urlString: String)
}
let mediaList: [Media] = [
.book(title: "Harry Potter and the Philosopher's Stone", author: "J.K. Rowling", year: 1997),
.movie(title: "Harry Potter and the Philosopher's Stone", director: "Chris Columbus", year: 2001),
.book(title: "Harry Potter and the Chamber of Secrets", author: "J.K. Rowling", year: 1999),