Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

SwiftUI Documentation

Post

Replies

Boosts

Views

Activity

Xcode Preview error: "A coordinated install for ... is already pending."
Hi,When testing my SwiftUI code, I sometimes get the new Xcode preview system having this error:Error Domain=IXErrorDomain Code=29 "A coordinated install for xxxx is already pending." UserInfo={NSLocalizedDescription=A coordinated install for xxxx is already pending., SourceFileLine=143, FunctionName=+[IXAppInstallCoordinator(IXSimpleInstaller) _beginInstallForURL:consumeSource:options:completion:]_block_invoke, NSLocalizedFailureReason=Unhandled reason for code: 29 in domain IXErrorDomain}The workaround I have found is to reboot my Mac (I will edit this post if I find a less radical workaround).Note: Version 11.0 beta 2 (11M337n)
3
1
4.6k
Jun ’19
MetalKit in SwiftUI
Hi,Are there any plans for integrating Metal/MetalKit with SwiftUI?Is that correct that current recommended way of the integration is to use UIViewControllerRepresentable like in the tutorial?Thank you!
18
1
12k
Jul ’19
Navigation Link Issue with SwiftUI
I have been using ScrollView with SwiftUI to develop a Custom Table Structure due to certain Customisation limitations with ListView. As soon I as I add NavigationLink for each item in scrollView. The icons or Images in the items are highlighted to blue color. Is this an already reported bug or is it something which I should avoid doing?
12
1
12k
Jul ’19
popToRootViewController in SwiftUI
What is the best practice to achieve popToRootViewController like functionality in SwiftUI? There are couple of ways to do it and one of them is described nicely here (https://stackoverflow.com/questions/57334455/swiftui-how-to-pop-to-root-view) via publish event but it losses the animation while popping to root. Please suggest.
3
0
5.6k
Sep ’19
How to remove SwiftUI TextField focus border?
How does one remove the focus border for a TextField in SwiftUI?In Cocoa, setting the border to "None" in interface builder would remove the border.I've tried using .border with a width of zero, but that does not work. The .border adds another border on top of the focus border.Setting the style also does not do the trick.
2
0
4.2k
Oct ’19
how to remove delete button in SwiftUI List rows when in Edit Mode?
How would remove the delete button in SwiftUI List rows when in Edit Mode? Note the hamburger button on the right of the row that allows rows to be re-ordered needs to continue to function.Background - Want a list that has the "re-order" rows functions always enabled. Edit mode seems to enable this (i.e. leave List in edit mode) however do not want the red delete button on each row.
2
1
2.4k
Nov ’19
SwiftUI - Determining Current Device and Orientation
So currently what I have been doing for determining what device type and orientation I am in for SwiftUI is using sizeClasses, usually something like the following:struct SizeClassView: View { @Environment(\.verticalSizeClass) var verticalSizeClass: UserInterfaceSizeClass? @Environment(\.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass? var body: some View { if horizontalSizeClass == .compact && verticalSizeClass == .regular { Text("iPhone Portrait") } else if horizontalSizeClass == .regular && verticalSizeClass == .compact { Text("iPhone Landscape") } else if horizontalSizeClass == .regular && verticalSizeClass == .regular { Text("iPad Portrait/Landscape") } } }What I'd like to know is: Is there any better way to do this in SwiftUI? The main problem I'm having with this method is that I can't differentiate between iPad Portrait and Landscape, but at least I can use it to differentiate between iPhone Portrait and iPhone Landscape and iPad... Any help and insight is greatly appreciated!
7
2
21k
Dec ’19
AttributeGraph: cycle detected
Hi all!When presenting a specific modal sheet in a SwiftUI project, I consistently get a ton of console output like:=== AttributeGraph: cycle detected through attribute 290 ===Like, a couple hundred of these logs. It appears to be accompanied by a stutter/slowdown in the UI, but there's no crash and everything looks to be in the right place.Is the "cycle" here some sort of ARC retain cycle? Is it SwiftUI-specific? (I'm asking here because I've never seen this warning in a classic UIKit project.) Where can I go to learn more about this?Thanks!
11
2
15k
Dec ’19
Possible MacOS SwiftUI onFocusChange bug
I think I've found a bug with focusable(_: onFocusChange:) on MacOS with SwiftUI and wanted to sanity check it here before using feedback assistant. This is with Xcode 11.3.1When I create the window, the VStack inside thinks it is in focus. But the onFocusChange closure never gets called to say it loses focus. As a result, both my VStacks in both my windows think they are infocus.Demonstration project at https://github.com/darrellroot/focusBug/Here's my ContentView which displays whether it thinks it is in focus:struct ContentView: View { @State var inFocus = false let windowCount: Int var body: some View { VStack { Text("Focus Window \(windowCount)") inFocus ? Text("This window thinks it is in focus") : Text("This window does not think it is in focus") }.padding(50).focusable() { newFocus in debugPrint("onFocusChange: \(newFocus)") self.inFocus = newFocus } } }Here's my appDelegate code which spawns 1 window on launch and 1 more every time a particular menu is selected: var windows: [Int:NSWindow] = [:] var windowCount = 0 func applicationDidFinishLaunching(_ aNotification: Notification) { newWindow() } @IBAction func newFocusWindow(_ sender: NSMenuItem) { newWindow() } func newWindow() { windowCount = windowCount + 1 let contentView = ContentView(windowCount: windowCount) let window = NSWindow( contentRect: NSRect(x: 100, y: 100, width: 1000, height: 1000), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false) window.isReleasedWhenClosed = false windows[windowCount] = window window.title = "Focus Window \(self.windowCount)" window.tabbingMode = .disallowed window.center() //window.setFrameAutosaveName("Window \(self.windowCount)") window.contentView = NSHostingView(rootView: contentView) window.makeKeyAndOrderFront(nil) }DebugPrint output shows that onFocusChange got called once per window:2020-03-09 10:24:22.363001-0700 focusBug[2555:258395] Metal API Validation Enabled"onFocusChange: true""onFocusChange: true"
3
1
1.4k
Mar ’20
SwiftUI binding dynamic array problem
I have an editor view that's broken up into several subviews. The model is a relatively small struct, but it does have a couple properties that can be variable-length arrays.The problem I'm having is after I add one entry to any one of these arrays, the view stops updating:struct ChecksView: View { @Binding var checks: [Check] var body: some View { HStack(alignment: .top, spacing: 0) { Button("add prereq", action: { self.checks.append(Check()) }) VStack { ForEach(self.checks.indices, id: \.self) { i in CheckView(check: self.$checks[i]) } } } } }In this subview, the first time you tap "add prereq", it will add to the array & update the UI. But every subsquent time, nothing updates until you navigate away & return. What am I doing wrong?
6
0
7.2k
May ’20
Prevent dismissal of sheet in SwiftUI
I'd like to emulate the behavior of UIViewController.isModalInPresentation in SwiftUI. In my first attempt, I defined the following view: struct ModalView<Content: View>: UIViewControllerRepresentable { 		var content: () -> Content 		func makeUIViewController(context: Context) -> UIHostingController<Content> { 				let controller = UIHostingController(rootView: content()) 				controller.isModalInPresentation = true 				return controller 		} 		func updateUIViewController(_ imagePickerController: UIHostingController<Content>, context: Context) {} } From my main app view, I then present the ModalView as a sheet: struct ContentView: View { 		@State 		var presentSheet: Bool = true 		var body: some View { 				Text("Hello, world!") 						.sheet(isPresented: $presentSheet) { 								ModalView { 										Text("Sheet") 								} 						} 		} } But the user is still able to dismiss the ModalView by swiping down. I would expect this sheet to be non-dismissible. Is anything like this supposed to work? If not, is there some other way to prevent the dismissal of a sheet in SwiftUI? The closest workaround I've found is to apply .highPriorityGesture(DragGesture()) to the content of the sheet, but swiping down with two fingers still works.
5
1
7.4k
Jun ’20
Xcode Previews doesn't work when used in a package that imports other packages.
I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the dependency I'm able to see the SwiftUI preview. I'm only able to use previews in packages that have no dependencies The error I get is: "LoadingError: failed to load library at path...Library not loaded " then it point to the dependency that it could not load in the current package. How can I access Xcode Previews from a package that depends on other packages?
32
20
18k
Jun ’20
LinkDylibError when previewing SwiftUI view from a package.
I have two (local) Swift packages (both with a single library product): RemoteImage, which defines setImage(from:) function on UIImageView and SatelitUI package which directly depends on the first one and defines some views. But when I'm trying to preview views from the second package I'm getting the following error: linker command failed with exit code 1 (use -v to see invocation) LinkDylibError: Failed to build TrailerView.swift Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: directory not found for option '-F/Applications/Xcode-beta.app/Contents/SharedFrameworks-iphonesimulator' Undefined symbols for architecture x86_64:   "(extension in RemoteImage):__C.UIImageView.setImage(from: Foundation.URL?) -> ()", referenced from:       (extension in SatelitUI_PreviewReplacement_TrailerView_2):SatelitUI.TrailerView.(previewupdate in _8C3731B0EF007627509BEEB93277D681)(with: SatelitUI.Trailer?) -> () in TrailerView.2.preview-thunk.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Apparently, Xcode fails to link the library from the first package because it's dynamic. Static linking works as expected. It's a bug I believe?
2
1
1.3k
Jun ’20