This is a simple OptionSet Demo written in swift.
import UIKit
struct Weekday: OptionSet, CustomStringConvertible {
let rawValue: Int
/// Monday
static let Monday = Weekday(rawValue: 1 << 2)
import UIKit | |
extension UIView { | |
public func constrainEqual(attribute: NSLayoutAttribute, to: AnyObject, multiplier: CGFloat = 1, constant: CGFloat = 0) { | |
constrainEqual(attribute, to: to, attribute, multiplier: multiplier, constant: constant) | |
} | |
public func constrainEqual(attribute: NSLayoutAttribute, to: AnyObject, _ toAttribute: NSLayoutAttribute, multiplier: CGFloat = 1, constant: CGFloat = 0) { | |
NSLayoutConstraint.activateConstraints([ | |
NSLayoutConstraint(item: self, attribute: attribute, relatedBy: .Equal, toItem: to, attribute: toAttribute, multiplier: multiplier, constant: constant) |
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" { | |
//"Hello, playground" | |
willSet { | |
print("willSet \(str) : \(newValue)") | |
// "willSet Hello, playground : Hello, Antonio.\n" | |
str = "Hi" |
This is a simple OptionSet Demo written in swift.
import UIKit
struct Weekday: OptionSet, CustomStringConvertible {
let rawValue: Int
/// Monday
static let Monday = Weekday(rawValue: 1 << 2)
import Foundation | |
struct Country { | |
let name: String | |
let capital: String | |
var visited: Bool | |
} | |
extension Country: Equatable { | |
static func == (lhs: Country, rhs: Country) -> Bool { |
// | |
// ScrollViewController.swift | |
// | |
// Created by Antonio081014 on 3/6/18. | |
// Copyright © 2018 sample.com. All rights reserved. | |
// | |
import UIKit | |
import XCTest | |
extension XCTestCase { | |
func trackForMemoryLeaks(_ instance: AnyObject, file: StaticString = #file, line: UInt = #line) { | |
addTeardownBlock { [weak instance] in | |
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line) | |
} | |
} | |
} | |
// Here is how to call this function. |
func test_imageEntity_properties() throws { | |
// Assert non nil value, and unwrap it. | |
let entity = try XCTUnwrap( | |
CoreDataStore.model?.entitiesByName["Name of Entity"] | |
) | |
entity.verify(attribute: "id", hasType: .UUIDAttributeType, isOptional: false) | |
entity.verify(attribute: "description", hasType: .stringAttributeType, isOptional: true) | |
entity.verify(attribute: "url", hasType: .URIAttributeType, isOptional: false) | |
} |
import UIKit | |
extension UIView { | |
public var isShimmering: Bool { | |
get { | |
return layer.mask?.animation(forKey: shimmerAnimationKey) != nil | |
} | |
set { | |
if newValue { | |
startShimmering() |
import Foundation | |
import Combine | |
class FileSubscription<S: Subscriber>: Subscription | |
where S.Input == Data, S.Failure == Error { | |
// fileURL is the url of the file to read | |
private let fileURL: URL | |
private var subscriber: S? |
func load(from url: URL, completion: @escaping (Result<Data, Error>) -> Void) { | |
DispatchQueue.global().async { | |
do { | |
let data = try Data(contentsOf: url) | |
DispatchQueue.main.async { | |
completion(.success(data)) | |
} | |
} catch { | |
DispatchQueue.main.async { | |
completion(.failure(error)) |