Skip to content

Instantly share code, notes, and snippets.

@sebjvidal
sebjvidal / SceneDelegate.swift
Created June 27, 2023 18:14
Custom UINavigationBar Height
// MARK: - SceneDelegate
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let navigationController = UINavigationController(navigationBarClass: NavigationBar.self, toolbarClass: nil)
(navigationController.navigationBar as! NavigationBar).preferredHeight = 88
navigationController.setViewControllers([ViewController()], animated: false)
@dankamel
dankamel / BottomSheetDesign.swift
Last active April 15, 2024 15:57
Native iOS 15 Adjustable Bottom Sheet In SwiftUI (half bottom sheet)
import SwiftUI
struct BottomSheetDesign: View {
@State var showSheet: Bool? = nil
var body: some View {
Button(action: { showSheet = true }) {
//
// ContentView.swift
// CoordinateShapeVsViewFrameOffset
//
// Created by Matthew Young on 12/26/22.
//
import SwiftUI
// VVVVVv
import SwiftUI
struct ContentView: View {
@State private var spinRadians: CGFloat = .zero
@State private var tiltRadians: CGFloat = .zero
private var spin: Angle { .radians(spinRadians) }
private var tilt: Angle { .radians(tiltRadians) }
@swiftui-lab
swiftui-lab / grid-trainer.swift
Last active March 29, 2024 01:46
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/eager-grids
//
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
@IanKeen
IanKeen / Storage.swift
Last active April 8, 2024 12:24
PropertyWrapper: Storage to extend support for more types using `@AppStorage`
@propertyWrapper
struct Storage<T: AppStorageConvertible>: RawRepresentable {
var rawValue: String { wrappedValue.storedValue }
var wrappedValue: T
init?(rawValue: String) {
guard let value = T.init(rawValue) else { return nil }
self.wrappedValue = value
}
init(wrappedValue: T) {
import Foundation
import Combine
protocol Initializable: RawRepresentable {
init?(rawValue: RawValue)
}
enum Person: Int, Initializable {
case andrew
}
@YusukeHosonuma
YusukeHosonuma / The introduction to SwiftUI.md
Last active April 21, 2024 12:11
あなたが求めていた SwiftUI 入門(未完結)

昔に書いていた未完結の記事ですが、それでも宜しければどうぞです🙏

あなたが求めていた SwiftUI 入門(未完結)

あなたは今年こそ SwiftUI を学ぶ必要があると感じている。

それは今年の WWDC20 で発表された Widget と呼ばれる機能が SwiftUI でしか作成できないことを聞いたからかもしれないし、SwiftUI 100% でマルチプラットフォームのアプリを作成できるようになったからかもしれないし、あるいはいつまでも UIKit に依存しているのはリスクだと感じ取ったのかもしれない。

学習の上で一番難しい部分は、SwiftUI で考えるということだ。従来の命令的でステートフルなプログラミングから離れて、宣言的でステートレスに考えるように脳を強制しなくてはならない。すでに日本でも SwiftUI の書籍はいくつか発売されているが、その多くは使い方に関することが中心で、SwiftUI が**どのように動くのか(How it works)**についての解説は不足しているものが多いように感じる。

@IanKeen
IanKeen / UserDefaultsKey.swift
Last active July 9, 2022 17:31
Simple type safe wrapper around UserDefaults
struct UserDefaultsKey<T: Codable> {
var name: String
var `default`: T
}
extension UserDefaults {
func get<T>(_ key: UserDefaultsKey<T>) -> T {
guard
let data = data(forKey: key.name),
let box = try? JSONDecoder().decode(Box<T>.self, from: data)
//
// StreamLogoMarchingAnts.swift
// CustomShapeOutlines
//
// Created by from getstream.io on 12.2.2022.
//
import SwiftUI
struct StreamLogoMarchingAnts: View {