Skip to content

Instantly share code, notes, and snippets.

/**-------- swift 集合类型解读 之 Collection - 1213/17
通过定一个 队列 来熟悉 Collection协议
其区别于 栈 ,栈的实现可以通过数组Array实现,但其会在练习内存中持有元素,这对 pop & push 来说很简单,但一旦有 remove(at: ) 这样的操作,时间复杂就会是 O(n)
*/
protocol YRQueen {
associatedtype Element
// 入队
mutating func enQueen(_ newElement: Element)
@13hoop
13hoop / libdispatch-efficiency-tips.md
Created February 26, 2020 07:37 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

@13hoop
13hoop / Server.swift
Created September 24, 2021 07:00
this is a mock API server demo
class Server {
private init() {}
static let shared = Server.init()
private static let serverQueue = DispatchQueue.global(qos: .background)
func getCountries(completion: @escaping (Array<String>) -> Void) {
let countries = ["France", "Germany", "Spain", "Portugal"]
let delay = Int.random(in: 1..<4)
Self.serverQueue.asyncAfter(deadline: .now() + .seconds(delay)) {
completion(countries)
}
//
// HyperlinkLabel.swift
// SLHome
//
// Created by yongren on 2022/1/6.
//
import Foundation
/// A UILabel subclass that responds to links tap.