Post

Replies

Boosts

Views

Activity

Reply to SwiftUI view is in the middle instead of in the top - NavigationView
HomeScreen & SignInView will inherit the outer most NavigationView, no need to nest the NavigationView them. struct ContentView: View { @EnvironmentObject var viewModel: AppViewModel var body: some View { NavigationView { if viewModel.signedIn { HomeScreen() .navigationBarHidden(true) } else { SignInView() .navigationBarHidden(false) .navigationBarTitle("Sign In", displayMode: .inline) } } .onAppear { viewModel.signedIn = viewModel.isSignedIn } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to How do I use NotificationCenter in mac catalyst to detect and connect an external display?
https://developer.apple.com/documentation/uikit/uiscreen/1617812-screens UIScreen.screens Discussion The returned array includes the main screen plus any additional screens connected to the device. The main screen is always at index 0. Not all devices support external displays. Currently, external displays are supported by iPhone and iPod touch devices with Retina displays and iPad. Older devices, such as the iPhone 3GS do not support external displays. didConnectNotification This notification is posted when a new screen is connected to the device.  Discussion Connection notifications are not sent for screens that are already present when the application is launched. The application can instead use the screens method to get the current set of screens at launch time. The object of the notification is the UIScreen object representing the new screen. There is no userInfo dictionary.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to iOS voiceover for multiline input field
Still not relying on UIKit directly you can still make this a pure SwiftUI implementation by using a SwiftUI TextEditor and FocusValue & FocusBinding for iOS 14+ to do what FocusState is doing at iOS 15+. https://swiftwithmajid.com/2021/03/03/focusedvalue-and-focusedbinding-property-wrappers-in-swiftui/
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to When I try to pass parameter to @FetchRequest, how to solve?
Best to use: lazy var accountType = "Account" @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \.displayOrder, ascending: true)] , predicate: NSPredicate(format: "(hidden < %@) AND (type == %@)", argumentArray: [1, accountType]) , animation: .default ) private var items: FetchedResults<JMAccount> or @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \.displayOrder, ascending: true)] , predicate: NSPredicate(format: "(hidden < %@) AND (type == %@)", argumentArray: [1, "Account"]) , animation: .default ) private var items: FetchedResults<JMAccount>
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to iOS voiceover for multiline input field
You can do the something natively in swiftUI without using UIKit. See here:https://developer.apple.com/documentation/swiftui/textfield/focused(_:equals:) struct LoginForm { enum Field: Hashable { case usernameField case passwordField } @State private var username = "" @State private var password = "" @FocusState private var focusedField: Field? var body: some View { Form { TextField("Username", text: $username) .focused($focusedField, equals: .usernameField) SecureField("Password", text: $password) .focused($focusedField, equals: .passwordField) EmptyView()                   .emptyState(focusedField == .username) {                           Text("Please enter a user name.")                                 .foregroundColor(.red)                                 .font(.footnote)                         } Button("Sign In") { if username.isEmpty { focusedField = .usernameField } else if password.isEmpty { focusedField = .passwordField } else { handleLogin(username, password) } } } } } struct EmptyStateViewModifier<EmptyContent>: ViewModifier where EmptyContent: View {     var isEmpty: Bool     let emptyContent: () -> EmptyContent     func body(content: Content) -> some View {         if isEmpty {             emptyContent()         } else {             content         }     } } extension View {     func emptyState<EmptyContent>(_ isEmpty: Bool,                                     emptyContent: @escaping () -> EmptyContent) -> some View where EmptyContent: View {         modifier(EmptyStateViewModifier(isEmpty: isEmpty, emptyContent: emptyContent))     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22