Skip to content

Instantly share code, notes, and snippets.

View ytyubox's full-sized avatar
😎
TooFastToSlow

Tsungyu Yu ytyubox

😎
TooFastToSlow
View GitHub Profile
//
/*
* Created by 游宗諭 in 2021/5/26
*
* Using Swift 5.0
*
* Running on macOS 11.4
*/
import Combine
// MARK: - UserRecord
struct UserRecord: Codable {
let name: String
@PolymorphicValue
var pet: Animal
}
import XCTest

From

var fib_6 = {
  v: Int -> Int  in
  if v <= 1  { return v }
  return ???(v - 1) + ???(v - 2)
}(6)

to

let containerCellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, OutlineItem> { cell, _, menuItem in
var contentConfiguration = cell.defaultContentConfiguration()
contentConfiguration.text = menuItem.title
if menuItem.imageName != nil {
contentConfiguration.image = UIImage(systemName: menuItem.imageName!)
}
contentConfiguration.textProperties.font = .preferredFont(forTextStyle: .headline)
@ytyubox
ytyubox / CollectionViewCell.swift
Created April 5, 2021 10:51
Tap To Squeeze On Cell and Control
/* Also working with UIControl, UITableViewCell */
class Cell: UICollectionViewCell {
override var isHighlighted: Bool {
didSet {
let duration = isHighlighted
? 0.45
: 0.4
let transform = isHighlighted
? CGAffineTransform(scaleX: 0.96, y: 0.96)
: CGAffineTransform.identity
//
/*
* Created by 游宗諭 in 2021/2/26
*
* Using Swift 5.0
*
* Running on macOS 10.15
*/
import UIKit
# Protocol, ["TopLevel", "ClassImplementation"]
snippet protocol
protocol <#name#> {
<#requirements#>
}
# Struct, ["TopLevel", "ClassImplementation"]
snippet struct
struct <#name#> {
<#fields#>
}
@propertyWrapper struct Lock<Value> {
private var inner: LockInner
init(wrappedValue: Value) {
inner = LockInner(wrappedValue)
}
var wrappedValue: Value {
get { return inner.value }
nonmutating _modify {
extension Result {
func tryMap<T>(_ transform:(Success) throws -> T) -> Result<T, Swift.Error> {
switch self {
case let .success(success):
do {
return .success(try transform(success))
} catch {
return .failure(error)
}
case let .failure(failure):