Skip to content

Instantly share code, notes, and snippets.

View MojtabaHs's full-sized avatar
🏆
Worldwide 2nd in SwiftUI - According to StackOverflow

Seyed Mojtaba Hosseini Zeidabadi MojtabaHs

🏆
Worldwide 2nd in SwiftUI - According to StackOverflow
View GitHub Profile
@MojtabaHs
MojtabaHs / UIViewForSwiftUI.swift
Last active April 18, 2023 10:33
This is a simple file you can use to bring any UIKit UIView in to the SwiftUI. Fully customizable.
import SwiftUI
protocol UIViewRepresentableHelper: UIViewRepresentable {
var configuration: (UIViewType) -> () { get set }
}
@available(iOS 13.0, *)
extension UIViewRepresentableHelper {
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIViewType {
let uiView = UIViewType()
@MojtabaHs
MojtabaHs / SomeKindOfBool.swift
Last active June 17, 2022 15:16
Decode logical `Bool` into a real `Bool` with this simple Property Wrapper.
// MARK: - Wrapper
@propertyWrapper
struct SomeKindOfBool: Decodable {
var wrappedValue: Bool
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let stringifiedValue = try? container.decode(String.self) {
switch stringifiedValue.lowercased() {
case "false", "no", "0", "n", "f": wrappedValue = false
@MojtabaHs
MojtabaHs / UserDefaultsStorage.swift
Last active March 1, 2024 09:55
A property. wrapper for store/restore variables backed by the given user defaults.
import Foundation
@propertyWrapper
public struct UserDefaultStorage<T: Codable> {
private let key: String
private let defaultValue: T
private let userDefaults: UserDefaults
public init(key: String, default: T, store: UserDefaults = .standard) {
@MojtabaHs
MojtabaHs / NumberAbbreviationFormatter.swift
Last active January 24, 2024 08:13
Converts between number and its abbreviation (1000 -> 1K -> 1000)
import Foundation
@dynamicMemberLookup
class NumberAbbreviationFormatter {
// MARK: - Internal properties
var formatter = NumberFormatter()
// MARK: - Static configurations