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)
class AsyncFileReading { | |
func asyncReadFile(_ url: URL) async throws -> Data { | |
let (data, _) = try await URLSession.shared.data(from: url) | |
return data | |
} | |
static func testout() { | |
let instance = AsyncFileReading() | |
let filename = "file_to_be_read.txt" | |
let url = Bundle.main.bundleURL.appending(component: filename) |
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)) |
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? |
import UIKit | |
extension UIView { | |
public var isShimmering: Bool { | |
get { | |
return layer.mask?.animation(forKey: shimmerAnimationKey) != nil | |
} | |
set { | |
if newValue { | |
startShimmering() |
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 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. |
// | |
// ScrollViewController.swift | |
// | |
// Created by Antonio081014 on 3/6/18. | |
// Copyright © 2018 sample.com. All rights reserved. | |
// | |
import UIKit | |
import Foundation | |
struct Country { | |
let name: String | |
let capital: String | |
var visited: Bool | |
} | |
extension Country: Equatable { | |
static func == (lhs: Country, rhs: Country) -> Bool { |
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)
//: 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" |