Skip to content

Instantly share code, notes, and snippets.

View halilyuce's full-sized avatar
🏠
Working from home

Halil YÜCE halilyuce

🏠
Working from home
View GitHub Profile
@Amzd
Amzd / StateObject.swift
Last active March 27, 2024 20:14
StateObject that works in iOS 13
import Combine
import PublishedObject // https://github.com/Amzd/PublishedObject
import SwiftUI
/// A property wrapper type that instantiates an observable object.
@propertyWrapper
public struct StateObject<ObjectType: ObservableObject>: DynamicProperty
where ObjectType.ObjectWillChangePublisher == ObservableObjectPublisher {
/// Wrapper that helps with initialising without actually having an ObservableObject yet
@shial4
shial4 / DynamicList.swift
Last active June 7, 2024 09:25
SwiftUI Dynamic Horizontal or vertical List - loads only visible elements. Efficiency for large collections. Dynamic item size.
import SwiftUI
import Foundation
import PlaygroundSupport
public enum Orientation {
case horizontal
case vertical
}
public struct StackView<Content: View>: View {
@ren6
ren6 / app_store_receipt_example.json
Created October 15, 2019 12:57
Example of App Store receipt with 2 auto-renewable transactions (trial and renewal)
{
"status": 0,
"environment": "Sandbox",
"receipt": {
"receipt_type": "ProductionSandbox",
"adam_id": 0,
"app_item_id": 0,
"bundle_id": "com.apphud.subscriptionstest",
"application_version": "1",
"download_id": 0,
@Amzd
Amzd / UIKitTabView.swift
Last active March 16, 2024 10:40
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem