I'm developing a SwiftUI, CoreData / CloudKit App with Xcode 16.2 & Sequoia 15.2. The main CoreData entity has 20 NSManaged vars and 5 derived vars, the latter being computed from the managed vars and dependent computed vars - this somewhat akin to a spreadsheet. The data entry/updating Form is complex for each managed var because the user needs to be able to enter data in either Imperial or Metric units, and then switch (by Button) between units for viewing equivalents. This has to happen on an individual managed var basis, because some source data are in Imperial and others Metric.
Consequently, I use a generalised SubView on the Form for processing the managed var (passed as a parameter with its identity) and then updating the CoreData Entity (about 100 lines of code in total): i.e. there are 20 uses of the generalised SubView within the Main Form. However, none of the SubViews triggers an update of the managed var in the Form, nor computations of the derived vars. On initial load of the app, the CoreData entity is retrieved and the computations happen correctly: thereafter not.
No technique for refreshing either View works: e.g. trigger based on NSManagedObjectContextDidSave; nor does reloading the CoreData entity after Context Save (CoreData doesn't recognise changes at the attribute level anyway). If the SubView is removed and replaced with code within the Form View itself, then it works. However, this will require about 40 @State vars, 20 onCommits, etc - so it's not something I'm keen to do.
Below is a much-simplified example of the problem.
Form{
Section(header: Text("Test Record")){
Text(testRec.dateString ?? "n/a")
TextField("Notes",text:$text)
.onSubmit{
testRec.notes = text
dataStore.contextSave()
}
//DoubleNumberEntry(testRec: testRec) - doesn't work
TextField("Double",value:$numDbl,format: .number)
// This works
.onSubmit{
testRec.dblNum = numDbl
dataStore.contextSave()
}
TextField("Integer",value: $numInt,format: .number)
.onSubmit{
testRec.intNum = Int16(numInt)
dataStore.contextSave()
}
Text(String(format:"%.2f",testRec.computation))
Section(header: Text("Computations")) {
Text(String(format:"%.2f",testRec.computation))
Text(String(format:"%.2f",testRec.anotherComputation))
}
}
}
A much simplified version of my NSManaged var entry/updating.
struct DoubleNumberEntry: View {
let dataStore = MainController.shared.dataStore
var testRec : TestRec
@State private var numDbl: Double
init(testRec: TestRec) {
self.testRec = testRec
self.numDbl = testRec.dblNum
}
var body: some View {
TextField("Double",value:$numDbl,format: .number)
.onSubmit{
testRec.dblNum = numDbl
dataStore.contextSave()
}
}
}
I'd appreciate any offered solution or advice.
Regards, Michaela
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Posts under SwiftUI tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
macOS: Sequoia
Xcode: 16.1
I am working on a macOS app and it has a widget feature.
When I use Swift 6 (Build Settings > Swift Language Version) in IntentExtension, the intent configuration won't show up in macOS Sequoia.
If I downgrade to Swift 5, it works without any other changes.
Is it a bug or am I missing something? How can I use Swift 6 with IntentExtension.
I have this code to make ARVR Stereo View To Be Used in VR Box Or Google Cardboard, it uses iOS 18 New RealityView but it is not Act as an AR but rather Static VR on a Camera background so as I move the iPhone the cube move with it and that's not suppose to happen if its Anchored in a plane or to world coordinate.
import SwiftUI
import RealityKit
struct ContentView : View {
let anchor1 = AnchorEntity(.camera)
let anchor2 = AnchorEntity(.camera)
var body: some View {
HStack (spacing: 0){
MainView(anchor: anchor1)
MainView(anchor: anchor2)
}
.background(.black)
}
}
struct MainView : View {
@State var anchor = AnchorEntity()
var body: some View {
RealityView { content in
content.camera = .spatialTracking
let item = ModelEntity(mesh: .generateBox(size: 0.25), materials: [SimpleMaterial()])
anchor.addChild(item)
content.add(anchor)
anchor.position.z = -1.0
anchor.orientation = .init(angle: .pi/4, axis:[0,1,1])
}
}
}
the thing is if I remove .camera like this
let anchor1 = AnchorEntity()
let anchor2 = AnchorEntity()
It would work as AR Anchored to world coordinates but on the other hand is does not work but on the left view only not both views
Meanwhile this was so easy before RealityView and SwiftUI by cloning the view like in ARSCNView Example :
import UIKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
//create Any Two ARSCNView's in Story board
// and link each to the next (dont mind dimensions)
@IBOutlet var sceneView: ARSCNView!
@IBOutlet var sceneView2: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
sceneView.delegate = self
sceneView.session.delegate = self
// Create SceneKit box
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0.01)
let item = SCNNode(geometry: box)
item.geometry?.materials.first?.diffuse.contents = UIColor.green
item.position = SCNVector3(0.0, 0.0, -1.0)
item.orientation = SCNVector4(0, 1, 1, .pi/4.0)
// retrieve the ship node
sceneView.scene.rootNode.addChildNode(item)
}
override func viewDidLayoutSubviews() // To Do Add the 4 Buttons
{
// Stop Screen Dimming or Closing While The App Is Running
UIApplication.shared.isIdleTimerDisabled = true
let screen: CGRect = UIScreen.main.bounds
let topPadding: CGFloat = self.view.safeAreaInsets.top
let bottomPadding: CGFloat = self.view.safeAreaInsets.bottom
let leftPadding: CGFloat = self.view.safeAreaInsets.left
let rightPadding: CGFloat = self.view.safeAreaInsets.right
let safeArea: CGRect = CGRect(x: leftPadding, y: topPadding, width: screen.size.width - leftPadding - rightPadding, height: screen.size.height - topPadding - bottomPadding)
DispatchQueue.main.async
{
if self.sceneView != nil
{
self.sceneView.frame = CGRect(x: safeArea.size.width * 0 + safeArea.origin.x, y: safeArea.size.height * 0 + safeArea.origin.y, width: safeArea.size.width * 0.5, height: safeArea.size.height * 1)
}
if self.sceneView2 != nil
{
self.sceneView2.frame = CGRect(x: safeArea.size.width * 0.5 + safeArea.origin.x, y: safeArea.size.height * 0 + safeArea.origin.y, width: safeArea.size.width * 0.5, height: safeArea.size.height * 1)
}
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let configuration = ARWorldTrackingConfiguration()
sceneView.session.run(configuration)
sceneView2.scene = sceneView.scene
sceneView2.session = sceneView.session
}
}
And here is the video for it
I am creating a UIKit application but that contains SwiftUI Views embedded using the hostingcontroller.
I have a particular approach for it..but it requires instantiating a swiftUI view, creating a hostingcontroller object from it and storing a reference to it. So that later If I wanted to update the view, I can simply get the reference back and update the swiftUI view using it.
I wanted to understand what does apple recommends on this. Can we store a swiftUI instance? Does it cause any issue or it is okay to do so?
Hello,
I'm using an HMSoft Bluetooth module that connects reliably to Android devices, maintaining a stable connection. However, when I try to connect it to my iPhone 12, the connection randomly disconnects after a few minutes (usually around 3 minutes). This issue occurs even when using apps like LightBlue and other BLE-based medical equipment apps, so it doesn't seem related to my app code.
Any suggestions on what I can do to prevent these unexpected disconnects? Should I change any specific settings on my iPhone or the module itself?
I have this code to make ARVR Stereo View To Be Used in VR Box Or Google Cardboard, it uses iOS 18 New RealityView but for some reason the left side showing the Entity (Box) more near to the camera than the right side which make it not identical, I wonder is this a bug and need to be fixed or what ? thanx
Here is the code
import SwiftUI
import RealityKit
struct ContentView : View {
let anchor1 = AnchorEntity(.camera)
let anchor2 = AnchorEntity(.camera)
var body: some View {
HStack (spacing: 0){
MainView(anchor: anchor1)
MainView(anchor: anchor2)
}
.background(.black)
}
}
struct MainView : View {
@State var anchor = AnchorEntity()
var body: some View {
RealityView { content in
content.camera = .spatialTracking
let item = ModelEntity(mesh: .generateBox(size: 0.25), materials: [SimpleMaterial()])
anchor.addChild(item)
content.add(anchor)
anchor.position.z = -1.0
anchor.orientation = .init(angle: .pi/4, axis:[0,1,1])
}
}
}
And Here is the View
Hi,
The dataModule in code below is a swiftData object being passed to the view and its property as key path but when trying to modify it I'm getting the error ."Cannot assign through subscript: 'self' is immutable" how to solve this issue ?
Kind Regards
struct ListSel<T: PersistentModel>: View {
@Bindable var dataModule: T
@Binding var txtValue: String
var keyPath: WritableKeyPath<T, String>
var turncate: CGFloat? = 94.0
var image = ""
var body: some View {
HStack {
Text(txtValue)
.foregroundColor(sysSecondary)
.font(.subheadline)
.onChange(of: txtValue) { value in
dataModule[keyPath: keyPath] = value
}
Image(systemName: image)
.foregroundColor(sysSecondary)
.font(.subheadline)
.imageScale(.small)
.symbolRenderingMode(.hierarchical)
.scaleEffect(0.8)
}
.frame(width: turncate, height: 20, alignment: .leading)
.truncationMode(.tail)
}
}
Hello team,
We recently found a EXC_BAD_ACCESS crash when using UIHostingControllers on a SPM local Package in our application. This is happening from time to time when we run the app on simulators using Debug configurations.
Also, this issue is consistent when we run application tests, there is something weird that we found after making a research... If we disable app test target and only keep packages tests, the crash is not happening, but as soon as we re-enable the app test target from the test suite the crash returns.
This is the full error message:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xbad4017) A bad access to memory terminated the process.
Is this s known issue? We've been performing explorations for some days and couldn't find any real solution for this.
A basic call on UIHostingController inside of a SPM local Package is enough to make the app crash, nothing custom being done:
UIHostingController(rootView: MyView())
When developing with SwiftUI, I encountered the following error:
failed to produce diagnostic for expression;
please submit a bug report (https://swift.org/contributing/#reporting-bugs)
Since I don’t understand the reason behind this error, what details should I include in the report?
Can I integrate Timer along with liveUpdates(_:) in order to manipulate the frequency. Let say for example I need the user location ever 1 min. Is it possible to do so?
I have an issue using RealityView to show two screens of AR, while I did succeed to make it as a non AR but now my code not working.
Also it is working using Storyboard and Swift with SceneKit, so why it is not working in RealityView?
import SwiftUI
import RealityKit
struct ContentView : View {
var body: some View {
HStack (spacing: 0){
MainView()
MainView()
}
.background(.black)
}
}
struct MainView : View {
@State var anchor = AnchorEntity()
var body: some View {
RealityView { content in
let item = ModelEntity(mesh: .generateBox(size: 0.2), materials: [SimpleMaterial()])
content.camera = .spatialTracking
anchor.addChild(item)
anchor.position = [0.0, 0.0, -1.0]
anchor.orientation = .init(angle: .pi/4, axis:[0,1,1])
// Add the horizontal plane anchor to the scene
content.add(anchor)
}
}
}
Working on a macOS app. I need to display user-added images as a background to the view, with all of:
Tiling (auto repeat in both axes)
Scaling (user-configured scale of the image)
Offset (user-configured offset)
I've been able to achieve scaling and offset with:
Image(nsImage: nsImage)
.scaleEffect(mapImage.scale)
.offset(mapImage.offset)
.frame(width: scaledImageSize.width, height: scaledImageSize.height)
But when I try to incorporate tiling into that with .resizable(resizingMode: .tile) everything breaks.
Is there a way to position the "anchor" of an image, scale it, and tile it in both axes to fill a container view?
I have a RealityView displaying a Reality Composer Pro scene in window. Things are generally working fine, but the content seems to be appearing in front of and blocking the VisionOS window, rather than being contained inside it. Do I need to switch to a volumetric view for this to work? My scene simply contains a flat display which renders 3D content (it has a material that sends different imagery to each eye).
I am making app which one of functionality is register user with firebase, but sometime when I register user I got app crash but user is added into db.
I am getting error like this: EXC_BAD_ACCESS (code=2, address=0x2600000000) or adres = 0x10 which mean the is some memory leak but when I use instrumental leak every thing is ok.
Second weird thing is that when I use instrumental leak I am not getting error (I added something like 40 users) but when I close instrumental and rebuilt I got crash in max 3 attempts.
// FormComponent.swift
// SpaceManager
//
// Created by Kuba Kromomołowski on 17/04/2024.
//
import Foundation
import SwiftUI
struct FormComponent: View {
var isRegister: Bool = true
@State private var repeatedPassword: String = ""
@StateObject private var loginHandler = LoginViewModel()
@StateObject private var registerHandler = RegisterViewModel()
@EnvironmentObject var permissionViewModel: PermissionViewModel
var body: some View {
Form {
TextField("Email", text: isRegister ? $registerHandler.email : $loginHandler.email)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(size: 25))
.multilineTextAlignment(.center)
.autocapitalization(.none)
.disableAutocorrection(true)
SecureField("Hasło", text: isRegister ? $registerHandler.password : $loginHandler.password)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(size: 25))
.multilineTextAlignment(.center)
.autocapitalization(.none)
.disableAutocorrection(true)
if (isRegister) {
SecureField("Powtórz haslo", text: $registerHandler.repeatedPassword)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(size: 25))
.multilineTextAlignment(.center)
.autocapitalization(.none)
.disableAutocorrection(true)
}
BtnClearComponet(btnText: isRegister ? "Zarejestruj się" : "Zaloguj się",
btnRegister: isRegister,
action: {
if isRegister {
registerHandler.registerUser() {
permissionViewModel.getPermission()
}
} else {
loginHandler.userLogin() {
permissionViewModel.getPermission()
}
}
},
loginHandler: loginHandler,
registerHandler: registerHandler
)
.padding(.bottom, 5)
}
.frame(width:350,height:400)
.scrollContentBackground(.hidden)
.padding(.top, 50)
}
}
//
// RegisterViewModel.swift
// SpaceManager
//
// Created by Kuba Kromomołowski on 03/05/2024.
//
import Foundation
import Firebase
import FirebaseAuth
import FirebaseFirestore
class RegisterViewModel : ObservableObject {
@Published var email: String = ""
@Published var password: String = ""
@Published var repeatedPassword: String = ""
@Published var isFail: Bool = false
@Published var message: String = ""
func registerUser(completion: @escaping () -> Void) {
if(!validInput()){
return
}
Auth.auth().createUser(withEmail: email, password: password) { [weak self] res,
err in
guard let self = self else { return }
if let err = err {
self.isFail = true
self.message = "Błąd przy rejestracji \(err.localizedDescription)"
return
}
guard let userID = res?.user.uid else {
return
}
// DispatchQueue.main.async {
// print("Starting adding...")
self.addIntoDatabe(userID: userID, email: self.email)
// }
completion()
}
}
private func addIntoDatabe(userID: String, email: String) {
let newUser = User(uid: userID, email: email, permission: Permission.Admin, itemReads: [["Prop":2]],
numberOfAddedItem: 0, numberOfReadItem: 0)
let db = Firestore.firestore()
db.collection("users")
.document(userID)
.setData(["uid": newUser.uid, "email": newUser.email, "permission": newUser.permission.rawValue, "itemReads": newUser.itemReads, "numberOfAddedItem": newUser.numberOfAddedItem, "numberOfReadItem": newUser.numberOfReadItem])
print("User has been added into db")
}
}
You'll have to forgive me, I am still pretty new to Swift, but I'm really struggling to figure out what I'm doing wrong or how I can fix it. I'm working on an app that generates an image from some views and then exports that image, but it always returns this very vague error:
The operation couldn’t be completed. (SwiftUI.FileExportOperation.Error error 0.)
Here's most of the program:
import SwiftUI
import UniformTypeIdentifiers
struct ContentView: View {
@State private var backgroundColor = Color.black
@State private var fileExporterIsPresented = false
@State private var image: NSImage?
@State private var fileExporterErrorAlertIsPresented = false
@State private var fileExporterErrorDescription: String?
var body: some View {
let wallpaper = Rectangle()
.foregroundStyle(backgroundColor)
.aspectRatio(16 / 9, contentMode: .fit)
VStack {
wallpaper
.clipShape(.rect(cornerRadius: 10))
.overlay {
RoundedRectangle(cornerRadius: 10)
.strokeBorder(.separator, lineWidth: 5)
}
ColorPicker("Background Color", selection: $backgroundColor, supportsOpacity: false)
Button("Generate Wallpaper") {
let renderer = ImageRenderer(content: wallpaper.frame(width: 3840, height: 2160))
image = renderer.nsImage
fileExporterIsPresented = true
}
.fileExporter(
isPresented: $fileExporterIsPresented,
item: image,
contentTypes: [UTType.heic, UTType.png]
) { result in
if case .failure(let error) = result {
fileExporterErrorDescription = error.localizedDescription
fileExporterErrorAlertIsPresented = true
}
}
.alert("File Exporter Failure", isPresented: $fileExporterErrorAlertIsPresented, actions: {
Button("OK") {}
}, message: {
if let fileExporterErrorDescription {
Text(fileExporterErrorDescription)
}
})
.dialogSeverity(.critical)
}
.padding()
}
}
#Preview {
ContentView()
}
We are having issues with implementing a List that has Views in it that contain a Textfield.
The criteria we are trying to achieve is
Select to edit the quantity of a product
Auto focus on the row with that textfield, with the textfield's contents selected
Display/Dismiss the keyboard
Mask other rows in the list while interacting with a qty field
We explored many routes and are looking for direction on what the designated approach is. This originally was a Tech Support Incident, and I was instructed to post here. There were 2 working project examples available if needed.
In an implementation that has the FocusState on the parent view, we see collisions in animation / weird jumpiness
// MARK: - Constant
enum Constant {
static let logTag = "AddReplenishmentProductView"
}
@Binding var state: ContentViewState
// MARK: - Private Properties
@State private var focusedLineItemId: String?
// MARK: - Life cycle
var body: some View {
VStack {
replenishmentProductList
}
.background(.tertiary)
.navigationTitle("Add Products")
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
}
// MARK: - Private Computed properties
@ViewBuilder
private var replenishmentProductList: some View {
ScrollViewReader { proxy in
List {
let list = Array(state.lineItems.enumerated())
ForEach(list, id: \.1.product.id) { (index, lineItem) in
RowView(
lineItem: $state.lineItems[index],
focusedLineItemId: $focusedLineItemId
)
.id(lineItem.id.uuidString)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.alignmentGuide(.listRowSeparatorLeading) { _ in
return 0
}
// Blocks all the other rows that we are not focusing on.
.maskingOverlay(focusId: $focusedLineItemId, elementId: "\(lineItem.id)")
}
.listSectionSeparator(.hidden)
}
.listStyle(.plain)
.scrollDismissesKeyboard(.never)
.scrollContentBackground(.hidden)
/*
We are looking for a solution that doesn't require us to have this onChange modifier
whenever we want to change a focus.
*/
.onChange(of: focusedLineItemId) {
guard let lineItemId = focusedLineItemId else { return }
/*
We need to scroll to a whole RowView so we can see both done and cancel buttons.
Without this, the focus will auto-scroll only to the text field, due to updating FocusState.
We are experiencing weird jumping issues. It feels like the animations for focus on
text field and RowView are clashing between each other.
To fix this, we added a delay to the scroll so the focus animation completes first and then we
scroll to the RowView.
However, when we attempt to focus on a row that is partially shown, sometimes the RowView won't
update it's focus and won't focus ultimately on the TextField until we scroll.
*/
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
withAnimation {
// We need to add the withAnimation call to animate the scroll to the whole row.
proxy.scrollTo(lineItemId, anchor: .top)
}
}
}
}
}
}
In an implementation where the FocusState is on the row views, we see issues with actually being able to focus. When quantity field we tap is located on a row near the top/bottom of the screen it does not look to be identified correctly, and the ability to scrollTo / the keyboard being presented are broken.
struct ContentView: View {
// MARK: - Constant
enum Constant {
static let logTag = "AddReplenishmentProductView"
}
@Binding var state: ContentViewState
// MARK: - Private Properties
@State private var focusedLineItemId: String?
@FocusState private var focus: String?
// MARK: - Life cycle
var body: some View {
VStack {
replenishmentProductList
}
.background(.tertiary)
.navigationTitle("Add Products")
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
}
// MARK: - Private Computed properties
@ViewBuilder
private var replenishmentProductList: some View {
ScrollViewReader { proxy in
List {
let list = Array(state.lineItems.enumerated())
ForEach(list, id: \.1.product.id) { (index, lineItem) in
RowView(
lineItem: $state.lineItems[index],
focusedLineItemId: $focusedLineItemId,
focus: $focus
)
.id(lineItem.id.uuidString)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.alignmentGuide(.listRowSeparatorLeading) { _ in
return 0
}
// Blocks all the other rows that we are not focusing on.
.maskingOverlay(focusId: $focusedLineItemId, elementId: "\(lineItem.id)")
}
.listSectionSeparator(.hidden)
}
.listStyle(.plain)
.scrollDismissesKeyboard(.never)
.scrollContentBackground(.hidden)
/*
We are looking for a solution that doesn't require us to have this onChange modifier
whenever we want to change a focus.
*/
.onChange(of: focusedLineItemId) {
/*
We need to scroll to a whole RowView so we can see both done and cancel buttons.
Without this, the focus will auto-scroll only to the text field, due to updating FocusState.
However, we are experiencing weird jumping issues. It feels like the animations for focus on
text field and RowView are clashing between each other.
*/
focus = focusedLineItemId
guard let lineItemId = focusedLineItemId else { return }
withAnimation {
// We need to add the withAnimation call to animate the scroll to the whole row.
proxy.scrollTo(lineItemId, anchor: .top)
}
}
}
}
}
Development environment: Xcode 16.1, macOS 15.1 (24B83)
OS version: iOS iOS 17.5 and above
When NavigationStack is presented by a sheet, and navigationDestination API is being used for navigation within the stack, the sheet content is forced to be reevaluated when app is in background.
Sample Project
import SwiftUI
struct TestView: View {
var id: Int
@State private var isLoading = false
@State private var presentSheet = false
var body: some View {
let _ = Self._printChanges()
VStack {
if isLoading {
ProgressView()
} else {
VStack {
Text("View: \(id)")
Text("Not loading")
Button("Present Sheet in NavStack") {
presentSheet = true
}
NavigationLink("Show Link", value: id * 100)
}
}
}
.sheet(
isPresented: $presentSheet,
content: {
NavigationStack {
TestView(id: self.id + 1)
// Comment this block out and note the view no longer reloads when app is in background when there's > 1 sheet modals
.navigationDestination(for: Int.self, destination: { num in
TestView(id: num)
})
}
}
)
.task {
isLoading = true
defer {
isLoading = false
}
try? await Task.sleep(for: .seconds(1))
}
}
}
struct ContentView: View {
var body: some View {
let _ = Self._printChanges()
VStack {
content
.padding()
}
}
var content: some View {
VStack {
NavigationStack {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
TestView(id: 0)
}
.navigationDestination(for: Int.self, destination: { num in
TestView(id: num)
})
}
}
}
}
Steps to reproduce:
To reproduce the issue in the sample project:
Tap on present sheet in navstack button to invoke View #1 presented in sheet
Put the app into multitasking mode by tapping on the simulator home button twice
Observe that console does not emit debug messages on SwiftUI View change. Also observe that there was no loading in the view
Tap on present sheet in navstack button again to invoke View #2 presented in sheet
Repeat step #2, but this time observe that console does emit debug message that SwiftUI View were changed due to the following:
TestView: @self, @identity, _isLoading, _presentSheet changed.
TestView: _isLoading changed.
TestView: _isLoading changed.
To remove the issue:
7. Comment out the block on navigationDestination. Recompile the app and run it in simulator
8. Repeat step 2-5. Note this time the console does not emit debug message that SwiftUI View were changed.
I have a Split View with the sidebar, content, and detail. Everything is working, but when I select on a NavigationLink in my detail view, the back button is seen next to the title above the content view. I want that back button to be displayed in the top bar on the left side of the detail view. I was expecting it to do this automatically, but I must be missing something.
This is where I want it to appear.
This is where it appears.
I made a simplified version of my code, because it would be too much to post but this has the same behavior.
struct TestView: View {
enum SidebarSelections {
case cycles
}
@State private var sidebarSelection: SidebarSelections = .cycles
var body: some View {
NavigationSplitView(sidebar: {
List(selection: $sidebarSelection, content: {
Label("Cycles", systemImage: "calendar")
.tag(SidebarSelections.cycles)
})
}, content: {
switch sidebarSelection {
case .cycles:
NavigationStack {
List {
// Displayed in Content
NavigationLink("Cycle link", destination: {
// Displayed in the Detail
NavigationStack {
List {
NavigationLink("Detail Link", destination: {
Text("More details")
})
}
}
})
}
}
}
}, detail: {
ContentUnavailableView("Nothing to see here", systemImage: "cloud")
})
}
}
Is what I want to do possible? Here is a Stack Overflow post that had it working at one point.
I am using a Mac Catalyst with SwiftUI for our document-based app with DocumentGroup. The issue is that when we create a new document or open an existing one, the opened view is completely blank. It is only blank/empty when the "Optimzie for Mac" is checked. If it is "Scaled t oMatch iPad", then it works well.
Xcode 16.1
macOS 15.1
struct DocumentGroupTestApp: App {
var body: some Scene {
DocumentGroup(newDocument: WritingAppDocument()) { file in
TestView() // it is empty when it gets opened. It does not work if the option "Optimize for Mac" is checked. If it is scale iPad, then it works.
}
}
}
struct TestView: View {
var body: some View {
Text("Hello, World!")
}
}
Hello,
I'm seeing a strange error on another user's device where the SwiftUI file importer doesn't do anything at all. When selecting multiple files and hitting "open", the importer just freezes. Here's a video showing the problem: https://streamable.com/u5grgy
I'm unable to replicate on my own device, so I'm not sure what could be going on. I have startAccessingSecurityScopedResource and stopAccessingSecurityResource everywhere I access a file from fileImporter as well.