Skip to content

Instantly share code, notes, and snippets.

@qoli
Created December 17, 2021 01:01
Show Gist options
  • Save qoli/3259275a28f060b71b6bae05a948afcf to your computer and use it in GitHub Desktop.
Save qoli/3259275a28f060b71b6bae05a948afcf to your computer and use it in GitHub Desktop.
modification.swift
//
// modification.swift
// Nomad
//
// Created by 黃佁媛 on 2021/12/17.
//
import Foundation
import SwiftUI
extension View {
@inlinable
func modify<T: View>(@ViewBuilder modifier: (Self) -> T) -> T {
return modifier(self)
}
}
extension View {
func iOS<Content: View>(_ modifier: (Self) -> Content) -> some View {
#if os(iOS)
return modifier(self)
#else
return self
#endif
}
}
extension View {
func macOS<Content: View>(_ modifier: (Self) -> Content) -> some View {
#if os(macOS)
return modifier(self)
#else
return self
#endif
}
}
extension View {
func tvOS<Content: View>(_ modifier: (Self) -> Content) -> some View {
#if os(tvOS)
return modifier(self)
#else
return self
#endif
}
}
extension View {
func watchOS<Content: View>(_ modifier: (Self) -> Content) -> some View {
#if os(watchOS)
return modifier(self)
#else
return self
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment