Skip to content

Instantly share code, notes, and snippets.

import UIKit
class InputToolbar: UIView {
private let separator = UIView()
private let button = UIButton(type: .system)
private let textField = UITextField()
private let sendButton = UIButton(type: .system)
func initialize() {
backgroundColor = .systemGreen
@Jimmy-Prime
Jimmy-Prime / ThreeColumnNavigation.swift
Last active June 29, 2020 08:43
SwiftUI three column navigation example - Xcode Version 12.0 beta (12A6159)
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
Sidebar()
Text("Select a mailbox")
Text("Select a mail")
}
}
@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
@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 {
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 / 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 SettingsViewController: UITableViewController {}
func showSettings() {
let vc = SettingsViewController()
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true)
}
@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) {
// designated init
init() {}
// designated init label
init(label: Type) {}
// convenience init
convenience init() {}
// convenience init label
// Model
typealias ChannelID = Int
struct ChannelGroup {
var name: String
var channels: [ChannelID]
}
// View's Model