Skip to content

dipiro/DPKit-Swift-Components

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Extensions

Array

public extension Array {
    subscript(save index: Int) -> Element? {
        guard index >= 0, index < self.count else { return nil }
        return self[index]
    }
}

Bundle

public extension Bundle {
    var appName: String {
        object(forInfoDictionaryKey: "CFBundleName") as? String ?? "Unknown"
    }
    
    var appVersion: String {
        object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "Unknown"
    }
}

ViewModifiers

struct OnLoadModifier: ViewModifier {
    @State private var didLoad = false
    
    private let action: (() -> Void)?
    
    // MARK: - Init
    init(perform action: (() -> Void)? = nil) {
        self.action = action
    }
    
    // MARK: - Body
    func body(content: Content) -> some View {
        content.onAppear {
            if didLoad == false {
                didLoad = true
                action?()
            }
        }
    }
}

// MARK: - Extension
extension View {
    public func onLoad(perform action: (() -> Void)? = nil) -> some View {
        modifier(OnLoadModifier(perform: action))
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published