Skip to content

Instantly share code, notes, and snippets.

View 複數PublushersCombine.swift
//
// ViewController.swift
// CombineCombine
//
// Created by Woody Liu on 2021/8/16.
//
import UIKit
import Combine
@woodycatliu
woodycatliu / OptionalNotified.swift
Last active Jul 24, 2021
Observing optional value change allow NoticationCenter post
View OptionalNotified.swift
//
// OptionalNotified.swift
// iOS_MomDad
//
// Created by Woody Liu on 2021/7/24.
//
import Foundation
@propertyWrapper
View Notified.swift
import Foundation
@propertyWrapper
public class Notified<Value: Equatable> {
public let notificationName: Notification.Name
public var wrappedValue: Value {
didSet {
if oldValue != wrappedValue {
View Persisted.swift
import Foundation
/// Store any `Codable` value in `UserDefaults`, and post a notification when value changed.
///
/// To add handler for value changed notification, use
///
/// let observation = foo.$bar.addObserver { ... }
///
/// or just
View Observed 屬性包裝器.swift
import Foundation
@propertyWrapper
public class Observed<T> {
private var _value: T {
didSet {
execute()
}
}
View Observed 屬性包裝器.swift
import Foundation
@propertyWrapper
public class Observed<T> {
private var _value: T {
didSet {
execute()
}
}
View LabelTextGradientColor.swift
/* 設定Label 文字漸層色
有兩三種做法,這個作法是我最喜歡的,不需要考慮到 view 的生命週期。
原理: 在label 繪製text之前。建立一個漸層色image,再將它轉成顏色給textColor
*/
extension UIImage {
View UIColor_hex.swift
extension UIColor {
class var mainXXX: UIColor {
let color = UIColor(XXX)
return color
}
static let main: UIColor = {
View img壓縮.swift
/*
compressImgMid: 二分壓縮法,指定預期的 MB
imgWithNewSize: 更改 img 尺寸,可依照預期 imgView 的尺寸去縮放(一般縮到跟 imgView 預期最大即可)
*/
extension UIImage {