2048-swiftui | 2048 game using SwiftUI and Combine | Frontend Framework library
kandi X-RAY | 2048-swiftui Summary
kandi X-RAY | 2048-swiftui Summary
2048 game using SwiftUI and Combine
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of 2048-swiftui
2048-swiftui Key Features
2048-swiftui Examples and Code Snippets
Community Discussions
Trending Discussions on 2048-swiftui
QUESTION
When using AppStorage for a global variable, navigationlinks are exited with simple swipe/tap gestures if AppStorage is used 2 times.
When I press one of two buttons to go into one of the two navigationlinks, once inside the NavigationLink, any single tap/swipe immediately exits the NavigationLink.
All I am trying to do is make sure that I can access the global variable "quarters" everywhere in my app - the main screen, the first NavigationLink that gives me quarters, and the second NavigationLink where I use my quarters.
This issue only began when I started using the below two lines of code for the global variable "quarters".
I am also open to any other ways to have a global variable "quarters". This one was suggested in a different question I asked and seems to work really well and easily and simply ... except for this issue.
The code causing the behavior:
...ANSWER
Answered 2021-May-16 at 14:52The issue comes from the fact that you call @AppStorage
in the ContentView
, and by using them in Menu1
and Menu2
, a pop navigation to the root view is triggered when the value is updated. I don't know if it is a bug from Apple or if it is an expected behavior, but I suggest you to fill a bug report in the FeedbackAssistant.app to let Apple engineers know about it.
To fix your issue, I have created a view model that you will pass between your views and read a new value result
at startup to retrieve the saved @AppStorage
value. I added a method to upgrade result
on the button tap, and then save the new value to @AppStorage
. By doing so, the NavigationLink behavior you expect is fixed.
This is the new view model that will handle the logic between views and keep track of the quarters
result:
QUESTION
I am trying to create a navigation screen with two buttons for two view controllers.
I found a game online which has similar navigation implemented. But when I run it, it takes me straight to the first navigation item without showing the options screen.
I want to get the navigation working properly, but it does not.
Note: I'm getting an error on the second part (GameViewController.swift) on line 9 saying Argument passed to call that takes no arguments
. It seems I need to move viewModel
or something similar into ContentView
but the different ways I've tried just pop up more errors that I don't understand.
ANSWER
Answered 2021-May-15 at 14:50Basically, that error
is saying that you are trying to pass something to the ContentView
(in this case you are passing an instance of GameViewModel
while the ContentView
does not expect that thing (in this case that instance), So to fix that we have to make the ContentView
to take an instance of GameViewModel
.
According to the code and explanation you provided, you need to do few things to fix correctly the error:
1. Create an instance variable of GameViewModel
in your ContentView
:
Add this in your ContentView
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install 2048-swiftui
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page