Swift
Date 和 DateComponents 转换
1 | let calendar = Calendar.current |
判断键盘是否支持Emoji输入
1 | var isEmojiKeyboardSupoprted: Bool { |
UITextField 隐藏光标
1 | override func caretRect(for position: UITextPosition) -> CGRect { |
时间格式化、FormatStyle
子线程执行异步任务,回调主线程
1 | DispatchQueue.global().async { |
延迟执行异步任务
1 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { |
获取对象地址
1 | // 获取对象地址: |
获取当前是否为暗色模式
1 | if #available(iOS 13.0, *) { |
getOrDefault in Swift
从 Dictionary 中取值,如果不存在则返回默认值
1 | let list = dic["keyOfList", default: []] |
SwiftUI
Menu
1 | struct ContentView: View { |
TabView 中使用 SFSymbol 默认会被替换成“fill”变体
使用 selection 来判断是否选中从而切换icon。注入 environment
。
1 | TabView(selection: $selectedItem) { |
HStack 中的 Button 会同时响应事件
1 | Button() |
让 View 撑满屏幕
1 | Text("SwiftUI Tutorials") |
在 ForEach 循环中获取 index
1 | ForEach(Array(array.enumerated()), id: \.element) { index, element in |
其他
Python
1 | # 获取参数 |
macOS 唤起 Emoji 输入面板
快捷键
1 | Command + Control + Space |