Skip to content

Instantly share code, notes, and snippets.

View imthath-m's full-sized avatar
💭
developmentMode

Mohammed Imthathullah imthath-m

💭
developmentMode
View GitHub Profile
import Foundation
class Vehicle: Codable {
var seats: Int = 0
init() { }
func move() { }
}
import UIKit
public extension UIView {
@discardableResult func align(_ type1: NSLayoutConstraint.Attribute,
with view: UIView? = nil, on type2: NSLayoutConstraint.Attribute? = nil,
offset constant: CGFloat = 0,
priority: Float? = nil) -> NSLayoutConstraint? {
guard let view = view ?? superview else {
return nil
import UniformTypeIdentifiers
import PhotosUI
@available(iOS 14, *)
extension PHPickerResult {
var fileName: String? {
guard let name = itemProvider.suggestedName else { return nil }
if let extn = itemProvider.itemType?.preferredFilenameExtension {
return name + ".\(extn)"
@available (iOS 14.0, *)
public struct MenuPicker<T, V: View>: View {
@Binding var selected: Int
var array: [T]
var title: String?
let mapping: (T) -> V
public init(selected: Binding<Int>, array: [T], title: String? = nil,
mapping: @escaping (T) -> V) {
@available(iOS 14.0, *)
public struct EnumMenuPicker<T: Hashable & CaseIterable, V: View>: View {
@Binding var selected: T
var title: String? = nil
let mapping: (T) -> V
public var body: some View {
if let existingTitle = title {
class UserSettings: ObservableObject {
private init() { }
static let shared = UserSettings()
@Published var score = 0
}
class UserSettings: ObservableObject {
@Published var score = 0
}
struct ContentView: View {
@EnvironmentObject var settings: UserSettings
var body: some View {
NavigationView {
VStack {
@imthath-m
imthath-m / 0_UIKitTabView.swift
Created April 8, 2020 02:02 — forked from Amzd/UIKitTabView.swift
SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
import SwiftUI
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
struct UIKitTabView: View {
var viewControllers: [UIHostingController<AnyView>]
@State var selectedIndex: Int = 0
init(_ views: [Tab]) {
self.viewControllers = views.map {
let host = UIHostingController(rootView: $0.view)
@objc class SuperClassA: NSObject {
public required override init() { }
public static var shared: SuperClassA {
if let instance = _shared {
return instance
}
return instance
import SwiftUI
// import Introspect
public struct PasscodeField: View {
var maxDigits: Int = 4
var label = "Enter One Time Password"
@State var pin: String = ""
@State var showPin = false