I often have need for multi-segment (hierarchical) pickers with dynamic data: in UIKit I achieve this by reloading a subsidiary component after the user picks a value from the higher level component, e.g. for Country then State.I've been trying to achieve the same sort of effect with a SwiftUI Form containing multiple (two to start with) Pickers, but without success. The ForEach(0 ..< elements.count) pattern doesn't work with second and subsequent levels in the hierarchy because the number of elements in these levels changes depending on the chosen top level, e.g. countries have different numbers of states. The compiler throws a warning that the ForEach(0 ..< ) pattern can only be used with constants and to use ForEach(array, id: ): the results are unpredictable anyway with the 0..< approach, with subscript out of range crashes.I can get correct display of second level choices based on the selected first level, but the Selection binding of the Picker doesn't work, i.e. no check marks and no
Search results for
swiftui
16,633 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I've found something of a workaround by replacing the standard back button with one of my own. A search turned up some useful information on StackOverflow describing how you can translate UIViewController.presentingViewController.dismissViewController(_:completion:) into SwiftUI. The sad thing here is that the animation behavior of the prior controller's title into the new controller's back button is gone, but at least the button is visible now.Here's how I did it in the end, within my detail view:struct DetailView: View { @Environment(.presentationMode) var presentationMode: Binding var backButton: some View { Button(action: { self.presentationMode.wrappedValue.dismiss() }) { HStack(spacing: 4) { Image(systemName: chevron.left) Text(Back) } .foregroundColor(.white) } } var body: some View { VStack { // ...content... } .edgesIgnoringSafeArea(.top) .navigationBarItems(leading: backButton) } }
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
No Public API in SwiftUI to response for the resizable modifier of View protocol. Only Image in SwiftUI could work with .resizable(). Custom UIView like UIView for GIF is not resizable now.Related issue: https://github.com/SDWebImage/SDWebImageSwiftUI/issues/3
Your ListRow view expects a Binding, but the closure for List(todoStore.todos, ...) gives you a value. You have to somehow get a binding out of the todoStore instead.Here's an example using the .indexed() extension on RandomAccessCollection (the extension was provided in the Xcode 11 Beta release notes, but has since been removed. In older Xcode 11 betas, you could just use ForEach()/List() to iterate and get Bindings out): https://github.com/rudedogg/swiftui-toggle-crash/blob/master/SwitchToggleCrash/ContentView.swiftI don't recommend doing it that way. It seems like you can get an index out of bounds error in some cases depending on how the View updates. If you look at https://developer.apple.com/tutorials/swiftui/handling-user-input#create-a-favorite-button-for-each-landmarkthere is a slightly different pattern used, which seems safer (it fixes the crash I created that Github repo to demonstrate).This still seems ugly to me, and I feel like there is a better way. Maybe someone can offer u
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I am following the SwiftUI Tutorial from developer.apple.com site and when I try to preview some files that I created in th project it shows me an error message Failed to build LandmarkList.swift followed by an info icon saying Compiling failed: no type named LandmarkList_Previews in module Landmarks. When I hit Try again button it keeps not showing and just giving the same error message.I have already:- deleted the Xcode 10 version that I had installed.-closed and openned Xcode 11 betaIm running on MacOS Catalina Beta version 10.15.Somebody please
I'm also getting this error with SwiftUI Pickers in a Form. The error occurs when the user selects a choice in the presented choices table. However, the error only occurs on my physical device (iPhone 8) running iOS 13.1 beta: it doesn't occur with iOS 13.0 in Simulators. It therefore looks to be an iOS bug. Have you submitted a report?Regards,Michaela
Topic:
UI Frameworks
SubTopic:
UIKit
Tags:
Where can I find and an example how how to implement using SwiftUI, a UIBarButtonItem navigation to new view From Master View of Master/Detail template. In the new view, I plan to create a new record for saving into core data.Any help would be greatly appreciated.Jim
I wanted to use Webkit with SwiftUI.However, it is not written in the tutorial.I am a beginner and do not know how to do it.So please tell me.
There's a dedicated topic area for SwiftUI in the dev forums and you should better post there.You can find some articles searching with Webkit with SwiftUI.An example in the dev forums:How do I implement a WebView (WebKit) in SwiftUI? But as far as I checked, all of the ariticles are so primitive rather than practical. I mean, there are not enough info about how to use WKWebView with SwiftUI in some practical scenario found in actual apps.SwiftUI is relatively a young framework and even experienced programmers are struggling on it.If you are ready to explore SwiftUI with them, the article above can be a good starting point.If you really are a beginner and wanting a c&p-ready code, I recommend you to work with Storyboard.There are many tutorials and guidances and code examples about WKWebView with Storyboard all over the web.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
Hello All,I'm trying to navigate to a new viewvia a SwiftUI Button, can it be done? or should i be using navigation views?HStack() { Button(action: { }) { Text(Staff) }.frame(width: 150, height: 75).background(Color.purple).cornerRadius(10).shadow(radius: 5).foregroundColor(Color.white) Button(action: {}) { Text(Visitor) }.frame(width: 150, height: 75).background(Color.purple).cornerRadius(10).shadow(radius: 5).foregroundColor(Color.white) }i would like to have each button navigate to its own view, if possible. I'm new to SwiftUI but i have done this same thing using segues and identifiers o im sure there is a way to accomplish this.
How do I set the tooltip for an AppKit SwiftUI view?
Same. It appears that XCode doesn't recognize that the .swift file is part of the Landmarks project. So for instance if you try to make a variable of type Landmark, and then right-click and Jump to Definition XCode just flashes a question mark. Whereas in LandmarkRow.swift, the same task will actually open the Landmark.swift file that defines a Landmark. Frustrating - how can we add a SwiftUI file to our project so that XCode recognizes the new file is part of an existing project?UPDATE: playing around more, it isn't adding the file, but rather its that Preview / Canvas system doesn't recognize any new Views as being part of the Landmarks module. For instance, I add a new SwiftUI file, edit nothing, and click Resume in the Canvas. It should display hello world, but it gives the error:Compiling failed: no type named 'Test_Previews' in module 'Landmarks'Whereas previously this worked.
Topic:
App & System Services
SubTopic:
Core OS
Tags:
Title says it all - Swift Playgrounds on iPad is a formidable tool to learn and write Swift-Code and prototypes on the go.Are there any plans to get it to the Swift 5.1 standard including SwiftUI?
While OOPer is largely correct, I've been working through this on my own. I'll throw my code down below, hopefully it helps you out.I'm assuming some basic knowledge of both SwiftUI and WebKit here. If you need to know how an individual part works you'll want to look up tutorials on each of these things. The example includes how to load a webpage from url (including an extension to WKWebView to make page loading easier) and how to get key-value observing working, which was a particular issue I had personally.This code represents a stand alone View, so you can call it from any other View just like you would anything in SwiftUI. For more detail on how to implement this View with your own UI elements I recommend you check out this video: https://youtu.be/5xvvfHNdB5c// // WebView.swift // // Created by Ryan Anderson on 9/23/19. // Copyright © 2019 Ryan Anderson. All rights reserved. // import SwiftUI import WebKit // Small class to hold variables that we'll use in the View body class ob
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I am not sure if this can work, but I have a Standalone watchOS 6 app written in SwiftUI using the same setup like the iOS app:enabled Associated Domain Capability in the Watch Extensionenabled Sign in with Apple Capability in the Watch Extensionadded the Domain with: webcredentials: xxxadded the bundle identifier of the watch extension to the webcredentials in the apple-app-site-association file on my websiteused TextField(...).textContentType(.username)and SecureField(...).textContentType(.password)to set the content typesIf I create an ASAuthorizationAppleIDProvider and ASAuthorizationPasswordProvider request it shows only the AppleId but never the saved passwords from my iOS App. On the iOS App I can choose between AppleId and other Accounts created with mail and password.So SiwA and Autofill works fine on the iPhone but only Siwa works on the watch but no Password Autofill.Does password autofill works for anyone in combination with Siwa on the watch?