A swift playground experiment in making a Swift struct to JSON serialization.
The approach currently fails for arrays, but those can be handled much like dictionaries and optionals.
| // | |
| // AVAsset+Catalog.swift | |
| // Micro Album | |
| // | |
| // Created by Fabian Canas on 5/28/19. | |
| // Copyright © 2019 Fabian Canas. All rights reserved. | |
| // | |
| import AVFoundation | |
| import MobileCoreServices |
| import Foundation | |
| class C { | |
| @NSCopying var copiedName: NSString? | |
| var noCopyName: NSString? | |
| } | |
| let f = NSMutableString(string: "First") | |
| let obj = C() |
| class C<T> { | |
| enum E { | |
| case c(T) | |
| } | |
| var e: E? | |
| } | |
| let o = C<Int>() // Crash : cyclic metadata dependency detected, aborting |
| import UIKit | |
| /*: | |
| # Ordering Matters in UIFontDescriptor | |
| Oct 21, 2017, iOS 11 | |
| When creating a derived font descriptor with a font family, existing traits | |
| such as italic or bold are overwritten or ignored. | |
| */ |
| extension Sequence where Element: BinaryFloatingPoint { | |
| func average() -> Element { | |
| return abstractAverage(sequence: self, sum: +, div: /) | |
| } | |
| } | |
| extension Sequence where Element: SignedInteger { | |
| func average() -> Element { | |
| return abstractAverage(sequence: self, sum: +, div: /) | |
| } | |
| } |
A swift playground experiment in making a Swift struct to JSON serialization.
The approach currently fails for arrays, but those can be handled much like dictionaries and optionals.
| @implementation NSData (HexString) | |
| - (NSString *)hex_hexString { | |
| NSMutableString *out = [NSMutableString stringWithCapacity:self.length * 2]; | |
| [self enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) { | |
| for (NSUInteger i = 0; i < byteRange.length; i++) { | |
| [out appendFormat:@"%02x", ((unsigned char *)bytes)[i]]; | |
| } | |
| }]; | |
| return out; |
| import Cocoa | |
| import MapKit | |
| import CompassOSX | |
| import CoreGraphics | |
| /* | |
| // Elsewhere in the code, to initiate the trace action: | |
| @IBAction func makeTrace(sender: AnyObject) { | |
| let traceView = MapTraceView() |
| func squaredSame(a: [Int], b: [Int]) -> Bool { | |
| if a.count == 0 || b.count == 0 { | |
| return false | |
| } | |
| return Set(map(a, { $0 * $0 })) == Set(b) | |
| } | |
| let testResult = test(squaredSame) |
| func encode(name :String) -> Int { | |
| return reduce(map(name.unicodeScalars) { Int($0.value) - 64 }, 1, *) % 47 | |
| } | |
| func ride(group: String, comet: String) -> String { | |
| return encode(group) == encode(comet) ? "GO" : "STAY" | |
| } | |
| let testData = [ | |
| ("COMETQ","HVNGAT","GO"), |