I want to know my project use swiftUI 3 or swiftUI 4 .
env
xcode 13.2.1
i hav try to google for answer , and read the apple documentation, and look setting of project and settings of Xcode's preference.
The SwiftUI version relates to the iOS version. You could verify the version using the available API
if #available(iOS 13, *) {
// SwiftUI 1.0
} else if #available(iOS 14, *) {
// SwiftUI 2.0
} else if #available(iOS 15, *) {
// SwiftUI 3.0
} else if #available(iOS 16, *) {
// SwiftUI 4.0
}
Here you can find some solutions here
Related
From ios 15 SWiftUI provides an action parameter for adding multiple options in alert, but for lesser OS versions how can we achieve that?
from iOS 15
view.alert("Choose a package", isPresented: $showAlert) {
Button("Standard") { package = "Standard" }
Button("Pro") { package = "Pro" }
Button("Premium") { package = "Premium" }
}
Any native option for iOS 14 or below?
i'm trying to add hardware keyboard support for an iOS 14.0 app written in SwiftUI 2.0.
I saw some examples working with UIHostingController, so i'd like to try this way on iOS14/SWiftui 2.0 using WindowGroup.
I'm gettin gerror when compiling in XCODe 12.3
"Generic struct 'WindowGroup' requires that 'KeyTestController' conform to 'View'"
ContentView() conforms to View and everything is working fine when not using the "KeyTestController" class.
Any way to solve this ?
Thank you very much.
import SwiftUI
import StoreKit
import UIKit
#main
struct myApp: App
{
var body: some Scene
{
WindowGroup
{
KeyTestController(rootView:ContentView())
}
}
}
class KeyTestController<Content>: UIHostingController<Content> where Content: View
{
/* CODE …… */
}
I updated my SwiftUI Watch App from Xcode 11 to Xcode 12, using the new Xcode 12 / SwiftUI LifeCycle methodology. Unfortunately in doing that the "tint color" (which defines the color of NavigationBar back button & test) is lost & reverts to the defaults (which is not what I want or had set before in Xcode 11).
Does anyone know how to change the color of the ‘back’ button & text on NavigationBar - using the new lifecycle SwiftUI with Xcode 12 & WatchOS7?
In xcode 11 one could change the ‘tint’ color using inspector on the StoryBoard to do that (for the whole App). But with the new SwiftUI lifecycle in xcode 12, I can’t figure out how this is now set (probably some parameter in ‘init()’ of App?)
I have tried the the below code but it gives the below syntax error (remember this is for WatchOS7):
"Cannot find 'UINavigationBarAppearance' in scope"
#main
struct myApp: App {
init() {
print("App Initializing....")
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
}
#SceneBuilder var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Also tried:
#SceneBuilder var body: some Scene {
WindowGroup {
ContentView().accentColor(.white)
}
But that has no effect (no matter where the .accentColor modifier is placed).
Any help / suggestions?
Thanks!
Gerard
SwiftUI NavigationBar WatchOS7
OK - figured it out from Apple Documentation!
See: https://developer.apple.com/documentation/watchos-apps/setting-the-app-s-accent-color/
and follow instructions for "Update Existing Projects"
NOTE:
The new "AccentColor" color set must be added to the assets in the Frameworks->AppName WatchKit App->Assets.xcassets file. This is the same file where the App's Icon is placed.
One of the new features of SwiftUI 2 are LazyVStacks. Is it possible to implement its functionality in the current SwiftUI framework? I have the following code sample where I want to use it:
var body : some View {
VStack(alignment: .leading){
ScrollView {
Text("sample")
VStack{ // I want to have a LazyVStack here
ForEach(1..<10000, id: \.self) {_ in
Text("test")
}
}
}
}
}
Normally i would use a List which is by default lazy. But due to other constraints it's not possible.
Thanks in advance.
You have to install Xcode 12 beta in order to use LazyStacks. If you are coding for an iOS app, the simulator will run correctly, but if you are coding for a macOS app you will have to update to Big Sur also in order to run the SwiftUI 2 code.
The PresentationButton presents the view properly, but upon hitting "Cancel" to return to parent view, the button refuses to present the child view again.
Here is my PresentationButton code:
struct ContentView : View {
var body: some View {
ZStack {
PresentationButton(Text("Click to show"), destination: SomeOtherView())
.transition(.slide)
}
}
}
This bug has existed in various forms until Xcode 11 beta 4, but note that the API has changed.
PresentationButton became PresentationLink and then was deprecated in Xcode 11 beta 4 in favor of .sheet.
See here for an example of how to use the new functionality: https://stackoverflow.com/a/57087399/3179416