Skip to content

Instantly share code, notes, and snippets.

protocol P {
func test()
}
private struct Object {
let index: Int
}
extension Object: P {
fileprivate func test() {
class OAO {
let concurrent = DispatchQueue(label: "OAO", attributes: .concurrent)
let arrayQueue = DispatchQueue(label: "OAO.array", attributes: .concurrent)
// Thread-Safe
private var _array: [Int] = []
private var array: [Int] {
get {
// Model
typealias ChannelID = Int
struct ChannelGroup {
var name: String
var channels: [ChannelID]
}
// View's Model
// designated init
init() {}
// designated init label
init(label: Type) {}
// convenience init
convenience init() {}
// convenience init label
@objc class SettingsViewController: UITableViewController {
@objc convenience init() {
self.init(categories: SettingCategory.allCases)
}
init(categories: [SettingCategory]) {
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
class SettingsViewController: UITableViewController {}
func showSettings() {
let vc = SettingsViewController()
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true)
}
@Jimmy-Prime
Jimmy-Prime / NavigationDropdownMenu.swift
Last active September 7, 2021 09:54
POC implementation, using UIListContentConfiguration with UICollectionView to define UI
import UIKit
protocol DropdownMenuItem {
var appearance: UIListContentConfiguration { get }
}
protocol DropdownMenuSection {
associatedtype Item: DropdownMenuItem
var appearance: UIListContentConfiguration? { get }
class Channel {
final int id;
bool isStarred;
bool isJoined;
bool isEncrypted;
Channel.fromJson(Map<String, dynamic> json)
: id = json['channel_id'],
isStarred = json['is_star'],
@Jimmy-Prime
Jimmy-Prime / serialization.swift
Last active March 25, 2021 08:41
serialize json from scratch
import Foundation
// valid JSON format
// 1. null
// 2. String
// 3. Number
// 4. { "key": JSON, "key": JSON, ... }
// 5. [JSON, JSON, ...]
enum Status {
@Jimmy-Prime
Jimmy-Prime / FloatingLabelTextField.swift
Created November 2, 2020 09:40
SwiftUI floating label textfield
// Because Label's size don't match, transition looks weird.
import SwiftUI
struct FloatingLabelTextField: View {
@Namespace private var namespace
let placeholder: String
@Binding var text: String
@State private var isTextFieldFirstResponder: Bool = false