This file contains 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
class CustomAnnotation: MKPointAnnotation, Codable { | |
var imageName: String? | |
enum CodingKeys: String, CodingKey { | |
case latitude, longitude, title, subtitle, imageName | |
} | |
override init() { | |
super.init() | |
} |
This file contains 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
class CustomAnnotationView: MKAnnotationView { | |
override var annotation: MKAnnotation? { didSet { update(for: annotation) } } | |
override init(annotation: MKAnnotation?, reuseIdentifier: String?) { | |
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier) | |
canShowCallout = true | |
update(for: annotation) | |
} | |
override func prepareForReuse() { |
This file contains 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
/// Suspendable Task | |
/// | |
/// This provides an interface by which one can write code that can periodically call | |
/// `waitIfSuspended`, to achieve a block of code that can be suspended. | |
/// | |
/// Usage: | |
/// | |
/// ``` | |
/// let item = SuspendableTask { task in | |
/// for i in 0 ..< 1_000_000 { |
This file contains 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
extension Sequence where Element: FloatingPoint { | |
func mean() -> Element { | |
var count = 0 | |
var sum: Element = 0 | |
for element in self { | |
sum += element | |
count += 1 | |
} | |
return sum / Element(count) |
This file contains 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 SwiftUI | |
import Combine | |
struct TimerTest: View { | |
@State var date = Date() | |
@State var showSubView = false | |
@State var timer: AnyCancellable? = nil | |
var body: some View { | |
ZStack { |
This file contains 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
private func loadImagesConCurrent() { | |
let concurrentQueue = DispatchQueue(label: "myConcurrentQueue", qos: .background, attributes: .concurrent) | |
activity.startAnimating() | |
let group = DispatchGroup() | |
for (i, item) in myArray.enumerated() { | |
group.enter() | |
concurrentQueue.async { [weak self] in | |
let fileURL = try! FileManager.default | |
.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) | |
.appendingPathComponent(item as! String) |
This file contains 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
func generateRandomColors() -> [UIColor] { | |
var randomColors: [UIColor] = Array(repeating: .blue, count: .random(in: 0...10)) | |
randomColors += Array(repeating: .red, count: .random(in: 0...15)) | |
randomColors += Array(repeating: .yellow, count: .random(in: 0...25)) | |
randomColors += Array(repeating: .orange, count: 100 - randomColors.count) | |
return randomColors.shuffled() | |
} |
This file contains 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
extension String { | |
func matches(of regex: String, options: NSRegularExpression.Options = []) throws -> [String] { | |
try NSRegularExpression(pattern: regex, options: options) | |
.matches(in: self, range: NSRange(startIndex..., in: self)) | |
.compactMap { Range($0.range, in: self) } | |
.map { String(self[$0]) } | |
} | |
} |
This file contains 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
class DriverAnnotation: NSObject, MKAnnotation { | |
var coordinate: CLLocationCoordinate2D // if this can change, I'd suggest making it `dynamic var`; if it can't change, I'd make it constant with `let` | |
var uid: String | |
init(uid: String, coordinate: CLLocationCoordinate2D) { | |
self.uid = uid | |
self.coordinate = coordinate | |
} | |
} |
This file contains 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
// | |
// CGPoint+Centroid.swift | |
// | |
// Created by Robert Ryan on 5/19/20. | |
// Copyright © 2020 Robert Ryan. All rights reserved. | |
// | |
// See https://stackoverflow.com/a/61884774/1271826 | |
import Foundation |