Splunk - Spelunk EnvironmentValues in SwiftUI

Related tags

SwiftUI App swiftui
Overview

Splunk

Go diving in SwiftUI's EnvironmentValues or use common values exposed for you.

Read First

This uses reflection under the hood. That means this is:

  • Probably incredibly unstable
  • Will almost definitely change
  • May behave incorrectly on different versions of iOS

Currently, this has been tested on iOS 15.0 -> iOS 15.2.

Examples

Splunk can be used to locate any values in Environment, there are a few ways to do that:

Basic Usage

import Splunk
import SwiftUI

struct ContentView: View {
  @Environment(\.self)
  private var env
  
  var body: some View {
    Text("Hello!")
      .foregroundColor(env.value(of: "ForegroundColorKey"))
  }
}

Colors Extension

import Splunk
import SwiftUI

struct ContentView: View {
  @Environment(\.colors.foregroundColor)
  private var foregroundColor
  
  var body: some View {
    Text("Hello!")
      .foregroundColor(foregroundColor)
  }
}

Advanced Usage

import Splunk
import SwiftUI

struct ContentView: View {
  var body: some View {
    InnerView()
      .buttonBorderShape(.capsule)
  }
}

struct InnerView: View {
  @Environment(\.buttonBorderShape)
  private var buttonBorderShape
  
  var body: some View {
    if let shape = buttonBorderShape, shape == .capsule {
      Text("Never Capsule!")
    } else {
      Button("Okay, capsule is cool.") {
        // do something amazing.
      }
    }
  }
}

extension EnvironmentValues {
  var buttonBorderShape: ButtonBorderShape? {
    get { value(of: "ButtonBorderShapeKey") }
  }
}

License

Splunk is released under the MIT license. See LICENSE for details.

You might also like...
Watchos-navlink-swiftui-bug - Example Project to demonstrate bug in SwiftUI when NavigationLink is activated inside a TabView SwiftUI-Card - Simple card ui designed using SwiftUI
SwiftUI-Card - Simple card ui designed using SwiftUI

SwiftUI - Card Simple card ui designed using SwiftUI Preview

Swiftui-pressed-states-example - Examples of Pressed States in SwiftUI

Examples of Pressed States in SwiftUI pressed-states.mp4

IOS15-SwiftUI-InAppPurchaseDemo - In-App Purchase Demo app written with SwiftUI
IOS15-SwiftUI-InAppPurchaseDemo - In-App Purchase Demo app written with SwiftUI

iOS15-SwiftUI-InAppPurchaseDemo In-App Purchase Demo app written with SwiftUI If

SwiftUI Backports - Introducing a collection of SwiftUI backports to make your iOS development easier

SwiftUI Backports Introducing a collection of SwiftUI backports to make your iOS development easier. Many backports support iOS 13+ but where UIKIt fe

This SwiftUI project is a result of the third 'milestone' in "Hacking With Swift's 100 Days of SwiftUI".

exercise-tracker This SwiftUI project is a result of the third 'milestone' in "Hacking With Swift's 100 Days of SwiftUI". In this exercise tracking ap

A cross-platform Reddit client built in SwiftUI
A cross-platform Reddit client built in SwiftUI

A cross-platform Reddit client created in SwiftUI. Get the Public Beta Note: This project is far from complete. It still lacks many features of your t

An example to-do list app using SwiftUI which is introduced in WWDC19
An example to-do list app using SwiftUI which is introduced in WWDC19

SwiftUITodo SwiftUITodo is an example to-do list application using SwiftUI which is first introduced in WWDC19 keynote. Requirements Xcode 11 Beta Swi

SwiftUI & Combine app using MovieDB API. With a custom Flux (Redux) implementation.
SwiftUI & Combine app using MovieDB API. With a custom Flux (Redux) implementation.

MovieSwiftUI MovieSwiftUI is an application that uses the MovieDB API and is built with SwiftUI. It demos some SwiftUI (& Combine) concepts. The goal

Releases(0.3.0)
Owner
Eric Lewis
Developer & Father. Feel free to reach out on twitter if I don't get back to you here.
Eric Lewis
A simple SwiftUI Application to demonstrate creation of UI using SwiftUI.

WatchShop_UI A simple SwiftUI Application to demonstrate creation of UI using SwiftUI. How to run the project ? Fork the project. Run the project usin

Shubham Kr. Singh 12 Apr 15, 2022
E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy.

Touchdown-SwiftUI E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy. Main components and concepts used: @EnvironmentOb

Jorge Martinez 5 Aug 18, 2022
A multiplatform SwiftUI project demonstrating various SwiftUI features.

WikiDemo A multiplatform SwiftUI project demonstrating various SwiftUI features, including creating a master-detail interface. It's a multiplatform ve

Swift Dev Journal 6 Oct 17, 2022
SwiftUI Projects from Udemy SwiftUI Masterclass

SwiftUI Masterclass Repos: AsyncImage (N/A) Fructus (finished): an app for getting information about different fruits. Data comes from json files. Afr

Patrick Spafford 1 Mar 3, 2022
Best architecture for SwiftUI + CombineBest architecture for SwiftUI + Combine

Best architecture for SwiftUI + Combine The content of the presentation: First of the proposed architectures - MVP + C Second of the proposed architec

Kyrylo Triskalo 3 Sep 1, 2022
Weather-swiftui - An example of using SwiftUI

weather-swiftui An example of using SwiftUI Installation Get openweather api key

null 0 Jan 1, 2022
Orbit-swiftui - Orbit design system implemented in SwiftUI for iOS

Orbit is a SwiftUI component library which provides developers the easiest possi

Kiwi.com 37 Jan 3, 2023
SwiftUI Resume - A simple resume writed by swiftUI + Combine

SwiftUI_Resume a simple "resume" writed by swiftUI + Combine

null 15 Apr 27, 2022
SwiftUI-MSALSample - Sample project to login with MSAL using SwiftUI

SwiftUI-MSALSample I could not find a good walkthrough on how to implement MSAL

Rob Evans 10 Nov 7, 2022
100-Days-of-SwiftUI - Studying through Paul Hudson's 100 Days of SwiftUI

Hacking with SwiftUI 100 Days of SwiftUI Studying through Paul Hudson's "100 Day

Dean Thompson 3 Aug 29, 2022