SwiftUI - am I an iOS widget or watchOS app? - swiftui

I have a SwiftUI view which was originally only used for an iOS widget. I would like to re-use this view now for a watchOS app.
#Environment(.widgetFamily) var widgetFamily
The widgetFamily surprisingly was set to ".accessoryCircular". Is this some kind of strange default? This happens within the context of the main watchOS app - no widgets and no complications involved at this stage.
I would like to distinguish between the "accessoryCircular" iOS widget and the main watchOS app. How can I achieve this?

Related

how to make swiftUI buttons exclusive?

using swiftUI i have a lot of Buttons which i need to make only one can be clicked at the same time.
By default in swiftUI you have two or more buttons on a view you can click them all at once
I tried adding the following:
UIButton.appearance().isMultipleTouchEnabled = false
UIButton.appearance().isExclusiveTouch = true
With UIKit we had exclusiveTouch and MultiTouchEnabled but how do we do this with swiftUI?
What is the correct way to solve this application wide?
Update: The use case is simple there is a view with a login button and a register button and now the user can tap both at the same time which i don't want

SwiftUI - Adding Toolbar to Keyboard not working with XCode 13.2

I'm a newbie developer. Based on what I've read, in the latest version of Xcode it is possible to add a toolbar item to the keyboard in a straightforward manner:
TextField("Today's weight", text: $weight)
.textFieldStyle(.roundedBorder)
.keyboardType(.decimalPad)
.toolbar {
ToolbarItem(placement: .keyboard) {
Button("Click") {
isKeyBoardActive = false
}
}
}
The app is designed with TabView for navigation rather than a navigation view.
Based on this link I assumed that Xcode 13.1 would require a navigation view for this to work, but Xcode 13.2 would not. I've confirmed that my Xcode version is 13.2.1.
I've also tried the code with 'ToolbarItem' and 'ToolbarItemGroup'. When my app is run, no toolbar appears with either variation.
Any help would be greatly appreciated.
Edit: Upon further troubleshooting, I've realised that embedding the TextField in the TabView causes it not to work. If its a standalone view (i.e. not in a TabView) the toolbar item is added as expected. Extracting the TextField to its own subview while within TabView doesn't seem to work either.

How to avoid app crash with TabView inside NavigationView when navigate backwards ios 13 SwiftUI

I'm using a TabView inside NavigationView but my app crashes when I try to navigate backwards, it shows this error message "Thread 1: EXC_BAD_ACCESS (code=2, address=0x16ad5bff0)" at AppDelegate class. In ios 14 device it works fine but it crashes on ios 13. I think this is navigationView issue in ios 13. I'm looking for an alternative in iOS 13 and avoid the crash.
PS: I'm using xcode 12.
Nesting TabView's inside of NavigationView's has been an issue since SwiftUI started. The cleanest workaround to this is to create view "View layers". Take a look this answer to give you an idea about how they work.
Pure SwiftUI login, signup, register flow, is it possible?
There is a lot that you can do with layering in SwiftUI that feels natural. Check it out and let me know if you have any questions!

Is it possible to add an AppDelegate to an independent watchOS SwiftUI app?

I am trying to add an AppDelegate to a standalone watchOS SwiftUI app (no companion iOS app) as indicated in here, but I can't seem to resolve the issue Cannot find type 'UIApplicationDelegate' in scope
Explicitly adding an import UIKit does not help.
Any clues?
https://developer.apple.com/documentation/uikit/uiapplicationdelegate
UIApplicationDelegate seems to only work with Catalyst, iOS and TvOS. Per WatchKit documentation it using the WKExtensionDelegate that has all the same methods.
https://developer.apple.com/documentation/watchkit/working_with_the_watchos_app_life_cycle
https://developer.apple.com/documentation/watchkit/wkextensiondelegate

How to change the stylemask of NSWindow using Xcode12

On the subject of MacApp, is there a way to change it with the SwiftUI App on Xcode12?
I know how to change it with AppKit App Delegate.