Questions tagged [swiftui-environment]

141 questions
1
vote
2 answers

(Working) String interpolation having localised string Swiftui

I am trying to return an interpolated String from a business logic thats return only string type. I have tried few way but are not useful let value = LocalizedStringKey.init(stringLiteral: "stringKey") return ("\(value)…
NormalGuy
  • 97
  • 14
1
vote
0 answers

SwiftUI ButtonStyle ignores isEnabled environment variable on iOS 14.4, works on iOS 14.5+

I have the following SwiftUI ButtonStyle: public struct PrimaryButton: ButtonStyle { private let type: ButtonType @Environment(\.isEnabled) private var isEnabled public init() { } public func makeBody(configuration:…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
1
vote
1 answer

Change Font to whole SwiftUI project from one Place

is there any way to change the font of whole swiftUI project from one place. for example in swift we override UIFontDescriptor, CTFontRegularUsage in these similar way, is any possible to override font to whole swiftUI app. please provide any…
Maharajan S
  • 93
  • 10
1
vote
1 answer

Accessing State's value outside of being installed on a View. This will result in a constant Binding of the initial value and will not update

I tried to encapsulate the gesture in a class and then call it in another view. My project can run well, and it can be built well. but Xcode12 give me a pink error. This is my code class GestureClass: ObservableObject { private var…
ikunhub
  • 73
  • 1
  • 7
1
vote
1 answer

Cannot assign through subscript / environment key

While working on an iOS app using SwiftUI, I am facing the following situation. I have set a custom environment key following what I found in some tutorial on the net. Here is the relevant code inside the SceneDelegate.swift file. ..... …
Michel
  • 10,303
  • 17
  • 82
  • 179
1
vote
1 answer

In a SwiftUI AppLifecycle Document App, how can I get a menu command in active ContentView?

I'm writing a MacOS document app using the SwiftUI App lifecycle, and all the tricks I see here and elsewhere for sending a menu action to the active window depend on using platform specific implementation, which is (mostly) unavailable in a SwiftUI…
dang
  • 587
  • 1
  • 5
  • 10
1
vote
1 answer

How to display AM/PM on text in swiftUI?

I've inserted an timer, so the time changes according to the system clock. the problem is, its displaying in numbers without am/pm like(12:33). please guide me to solve this problem. This is the code I used to display the text. @State var endTime =…
davede3103
  • 67
  • 1
  • 9
1
vote
1 answer

SwiftUI- App does not conform to protocol 'App'

I'm a beginner to programming and have just added a custom tab bar to allow navigation throughout the app. However, since I have added the property wrappers to let this happen I get the error: 'app does not conform to protocol 'App' '. It forces…
mstv2020
  • 143
  • 2
  • 6
1
vote
2 answers

SwiftUI remove array entries within ForEach subviews

I'm quite new to IOS development so please bear with me if I have used the code in a completely improper way. I use swiftui 2 and my problem is that I have in my data structure an array which contains information I would like to present in another…
FriendlyGuy
  • 331
  • 5
  • 14
1
vote
1 answer

Accessing and manipulating array item in an EnvironmentObject

I have an EnvironmentObject that I'm using to generate a list class ActivityViewModel: ObservableObject { @Published var Activities = [Activity]() init() { self.Activities = ActivityService.fetchActivities() } } struct…
Matt Ward
  • 1,095
  • 1
  • 14
  • 28
1
vote
2 answers

SwiftUI : Thread error when accessing EnvironmentObject access at runtime

I have this scene with this several environmentObject: func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Get the managed object context from the shared persistent…
Kevin ABRIOUX
  • 16,507
  • 12
  • 93
  • 99
1
vote
1 answer

NavigationLink is not clickable after returning to the view from it's child view

My app has a multilevel layout AView -> BView -> CView -> DView. I change window.rootViewController to BView in order to "pop" 2 top views but for some reason when i come back to BView it's NavigationLink is not clickable. Any ideas on how to fix…
eugene_prg
  • 948
  • 2
  • 12
  • 25
1
vote
1 answer

Manipulating EnvironmentObject inside ObservedObject without getting entire view updated

Using a wrapper allows us to pass EnvironmentObject down into ObservedObject. Nice approach.. But what if you want to manipulate the userData inside ViewObject without an entirely new ViewObject being created every time? In my app entire view is…
eugene_prg
  • 948
  • 2
  • 12
  • 25
1
vote
1 answer

SwiftUI List content gets reset with selection

Here is my issue: MainView displays ChildView and gives it an EnvironmentObject containing a set of selected items. ChildView displays a list of selectable items(2 items in the example), and load the list when appearing. The problem is that the…
lorenzo
  • 1,487
  • 1
  • 17
  • 25
1
vote
1 answer

ObservableObject with ObservableObject property is not triggering SwiftUI Update

// NavigationState.swift class NavigationState: ObservableObject { @Published var contentViewNavigation = ContentViewNavigationState() //@Published var selectedTab = 0 } // App.swift @main struct SwiftUIDeepLinkApp: App { @StateObject…