Skip to content

Instantly share code, notes, and snippets.

View yoxisem544's full-sized avatar
πŸ₯‘

David Lin yoxisem544

πŸ₯‘
View GitHub Profile
@yesleon
yesleon / UITextView+placeholder.swift
Last active June 4, 2018 22:49
Add a placeholder property to UITextView.
//
// UITextView+placeholder.swift
//
// Created by Li-Heng Hsu on 02/06/2018.
// Copyright Β© 2018 narrativesaw. All rights reserved.
//
import UIKit
private let defaultPlaceholderColor = UIColor.gray
@yoxisem544
yoxisem544 / ArrayExtension.swift
Last active February 20, 2019 03:03
Swift extensions
import Foundation
extension Array {
/// You can get a random element in this array
///
/// - Returns: any element in this array, return nil if this array doesn't have anything in it.
func random() -> Element? {
guard count > 0 else { return nil }
let index = Int.random() % self.count
infix operator ?=: AssignmentPrecedence
infix operator ??=: AssignmentPrecedence
func ?= <T>(lhs: inout T, rhs: T?) {
print("-- ?= start")
defer { print("-- ?= end") }
guard let actualRhs = rhs else { return }
lhs = actualRhs
}
@pofat
pofat / Fastfile
Last active March 26, 2023 01:58
Shell script and Fastfile to build universal framework.
fastlane_version "2.50.1"
default_platform :ios
platform :ios do
before_all do
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
# cocoapods
end
@lattner
lattner / TaskConcurrencyManifesto.md
Last active August 19, 2025 19:22
Swift Concurrency Manifesto
let disposeBag = DisposeBag()
// 樑擬 indicator ι‘―η€Ί/ιš±θ—η‹€ζ…‹
let indicator = Variable(false)
// ζŒ‰ιˆ•
lazy var loginButton: UIButton = {
let button = UIButton(type: .system)
button.tintColor = UIColor.red
button.setTitle("η™»ε…₯", for: .normal)
@lattner
lattner / async_swift_proposal.md
Last active June 7, 2025 23:55 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@inamiy
inamiy / SwiftElmFrameworkList.md
Last active March 11, 2024 10:20
React & Elm inspired frameworks in Swift
@ivanbruel
ivanbruel / SnakeCase.swift
Last active March 19, 2023 16:42
Camel case to snake case in Swift
extension String {
func snakeCased() -> String? {
let pattern = "([a-z0-9])([A-Z])"
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: self.characters.count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased()
}
}
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
private var array = [Element]()
public init() { }