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)
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Post
Replies
Boosts
Views
Activity
I know it's possible to set the line limit to nil, enabling a text view to grow, but is it possible to disable truncation completely? In some odd text wrapping situations, it seems the views still prefer to truncate rather than grow an additional line, especially in cases where only a partial word would wrap.
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!
What is the SwiftUI equivalent to returnKeyType? How do we implement it?
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?
How can you add the clearbutton to a TextField?
Default TabView comes in light grey background color. the accentColor modifier works ok for changing the icon selected color, but I can not get the background color to change.Modifiers I've tried: .background(Color.white)This should work, but it doesn't. Could someone point me to the right direction?Thank you!
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.
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.
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.
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!
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!
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"
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?
Does anyone know if there is a way to move the "Maps" and "Legal" text in the Map SwiftUI view? App Store Guidelines require that the text be shown, but if you are trying to add some type of sheet or view overlay for some of the map, I can't seem to find a way to add extra bottom padding to this text.
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.
How do I hide the separation lines inside Lists in SwiftUI for iOS 14?
Previously I could use
UITableView.appearance().separatorStyle = .none
but this doesn't seem to work anymore.
I wonder where can I find source of ShapeEdit app mentioned in the WWDC 2020 SwiftUI videos. All I can find is old ShapeEdit.
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?
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?