Post

Replies

Boosts

Views

Activity

Toolbar Menu button seems to look disabled
Overview On macOS, in a NavigationSplitView when the menu button is added to the detail view toolbar, it seems to look disabled Environment Xcode: 14.1 beta 3 (14B5033e) macOS: 13.0 Beta (22A5365d) Code: struct ContentView: View { @State private var selectedNumber: Int? var body: some View { NavigationSplitView { List(0..<100, selection: $selectedNumber) { number in Text("cell \(number)") } } detail: { Text("Detail") .toolbar { ToolbarItem { Menu { Button("aa") {} Button("bb") {} } label: { Label("Add Bookmark", systemImage: "book") } } } } } } Steps to reproduce: Run the project on macOS Select cell 0 on the sidebar Click on the book toolbar button and notice the menu appear Select cell 1 on the sidebar Expected Behaviour After step 4, the book toolbar button should look prominent (like it is enabled) Actual Behaviour After step 4, the book toolbar button looks like it is disabled. Screenshot
1
1
1.7k
Nov ’23
How to download macOS Sonoma installer?
I am only able to upgrade from Ventura to Sonoma. I don't want to upgrade, I would like to download the installer so that I can install Sonoma on a separate Volume instead of upgrading. Am I missing something? I only see an option to upgrade and the developer website only allows me to download a IPSW file. I have only 1 Mac and I am not sure how I can use the IPSW file to install macOS Sonoma. Any help would be much appreciated, thanks
18
1
18k
Oct ’23
Copyable doesn't work with NavigationSplitView
Problem When copyable is used with NavigationSplitView then it doesn't work The menu Edit > Copy is disabled Note When copyable is not used with a NavigationSplitView and used only with a plain List then it works. Question Is there anything I am missing? Feedback FB12990593 Platform macOS 14.0 Beta (23A5312d) Xcode 15.0 beta 6 (15A5219j) Steps to reproduce Run the app on mac Select some cars Press Command C Expected Behaviour Menu Edit > Copy should be enabled Pressing Command C should allow user to copy selected cars Actual Behaviour Menu Edit > Copy is disabled Pressing Command C doesn't allow user to copy selected cars Code struct ContentView: View { @State private var dataStore = DataStore() var body: some View { NavigationSplitView { Color.brown } detail: { CarListView(dataStore: dataStore) } } } struct CarListView: View { let dataStore: DataStore @State private var selectedCarIDs = Set<UUID>() var body: some View { List(selection: $selectedCarIDs) { ForEach(dataStore.cars) { car in CarCell(car: car) .draggable(car) } } .copyable(selectedCars()) } private func selectedCars() -> [Car] { dataStore.cars.filter { selectedCarIDs.contains($0.id) } } } struct CarCell: View { let car: Car var body: some View { VStack(alignment: .leading) { Text(car.name) Text("\(car.price)") } } } @Observable class DataStore { var cars = [ Car(name: "aaa", price: 10), Car(name: "bbb", price: 20), Car(name: "ccc", price: 30), Car(name: "ddd", price: 40) ] } struct Car: Codable, Transferable, Identifiable { let id: UUID let name: String let price: Int init(name: String, price: Int) { self.id = UUID() self.name = name self.price = price } static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .car) } } extension UTType { static let car = UTType("com.example.car")! }
2
2
949
Aug ’23
EditButton causes the selection in sidebar view to be lost
Problem When app is run on iPhone 14 pro simulator running iOS 17 tapping on the EditButton shows the text "No folder selected" Feedback Feedback ID: FB12953838 Steps to reproduce: Run the app on iOS 17 iPhone simulator Tap on the "Edit" Button Expected Behaviour The view should show the car list in the edit mode Actual Behaviour The view shows the text "No folder selected" Note: Problem happens only the first time, subsequently EditButton works fine. Environment: iOS: 17 Platform: iPhone 14 pro simulator Xcode: 15.0 beta 6 (15A5219j) Code ContentView import SwiftUI struct ContentView: View { @State private var selectedFolderID: Int? @StateObject private var dataStore = DataStore() var body: some View { NavigationSplitView { FolderListView( selectedFolderID: $selectedFolderID, dataStore: dataStore ) } detail: { if let selectedFolderID { CarListView( selectedFolderID: selectedFolderID, dataStore: dataStore ) } else { Text("No folder selected") } } } } FolderListView import SwiftUI struct FolderListView: View { @Binding var selectedFolderID: Int? @ObservedObject var dataStore: DataStore var body: some View { List(dataStore.folders, selection: $selectedFolderID) { folder in NavigationLink(value: folder.id) { Text(folder.name) } } .task { selectedFolderID = dataStore.folders.first?.id } } } CarListView import SwiftUI struct CarListView: View { let selectedFolderID: Int @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { List( dataStore.cars(withFolderID: selectedFolderID), selection: $selectedCarIDs ) { car in Text(car.name) } .toolbar { //Tapping on the EditButton on the iPhone, shows the text "No folder selected". EditButton() } } } DataStore import Foundation class DataStore: ObservableObject { @Published var folders = [Folder(id: 0, name: "Folder 1"), Folder(id: 1, name: "Folder 2"), Folder(id: 2, name: "Folder 3"), Folder(id: 3, name: "Folder 4"), Folder(id: 4, name: "Folder 5")] @Published var carIDsInFolder: [Folder.ID : [Car.ID]] = [0: [0, 1], 1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [8, 9]] @Published var cars = [Car(id: 0, name: "aaa", price: 100), Car(id: 1, name: "bbb", price: 110), Car(id: 2, name: "ccc", price: 120), Car(id: 3, name: "ddd", price: 130), Car(id: 4, name: "eee", price: 140), Car(id: 5, name: "fff", price: 150), Car(id: 6, name: "iii", price: 160), Car(id: 7, name: "jjj", price: 170), Car(id: 8, name: "***", price: 180), Car(id: 9, name: "lll", price: 190)] func cars(withFolderID folderID: Folder.ID) -> [Car] { let carIDs = carIDsInFolder[folderID] ?? [] return carIDs.compactMap { car(withID: $0) } } func car(withID carID: Car.ID) -> Car? { cars.first { $0.id == carID } } } Car import Foundation struct Car: Identifiable { var id: Int var name: String var price: Int } Folder import Foundation struct Folder: Identifiable { var id: Int var name: String }
2
0
803
Aug ’23
Draggable doesn't work with multiple items in a list
Problem: On macOS, unable to drag multiple car items from FolderDetail List Single items from a list are draggable but multiple items are not draggable. Feedback FB10128110 I am really saddened that this is not fixed for over a year. Please look into this. Platform macOS 14 (beta 3), macOS 13 Steps to reproduce Run the code provided below Tap the sidebar button to show the sidebar Select "Folder 0" from the sidebar Drag "car a" into "Folder 1" (Go to Folder 2 to notice this happened successfully, you will be able to see "car a" in Folder 1) Select "Folder 0" from the sidebar Select "car a" and "car b" and try to drag them to "Folder 2" Expected Behaviour "car a" and "car b" must be both draggable (multiple items should be draggable). The entire cell needs to be draggable not just the Text. Actual Behaviour Though “car a” and “car b” are selected, when dragged only one of the 2 items is dragged You also can drag them only when dragging the Text unlike in iOS where you can drag the cell. Note: Same code works on iOS Code: UTType extension UTType { static var car = UTType(exportedAs: "com.example.DragAndDropListDemo.car") } Car import Foundation import CoreTransferable struct Car: Identifiable { var id: Int var name: String } //extension Car: Codable {} extension Car: Codable, Transferable { static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .car) } } Folder struct Folder: Identifiable, Hashable { var id: Int var name: String } DataStore class DataStore: ObservableObject { var folders = (0..<100).map { Folder(id: $0, name: "folder \($0)")} var cars = [0: [Car(id: 0, name:"car a"), Car(id: 1, name:"car b")], 1: [Car(id: 2, name:"car c"), Car(id: 3, name:"car d")]] } Views ContentView struct ContentView: View { @StateObject private var dataStore = DataStore() @State private var selectedFolder: Folder? var body: some View { NavigationSplitView { FolderList(selectedFolder: $selectedFolder, dataStore: dataStore) } detail: { FolderDetail(folder: selectedFolder, dataStore: dataStore) } } } FolderList struct FolderList: View { @Binding var selectedFolder: Folder? @ObservedObject var dataStore: DataStore var body: some View { List(dataStore.folders, selection: $selectedFolder) { folder in NavigationLink(value: folder) { Text(folder.name) .dropDestination(for: Car.self) { cars, location in print("cars = \(cars) location = \(location)") if let existingCars = dataStore.cars[folder.id] { dataStore.cars[folder.id] = existingCars + cars } else { dataStore.cars[folder.id] = cars } return true } } } } } FolderDetail struct FolderDetail: View { let folder: Folder? @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { if let folder { List(dataStore.cars[folder.id] ?? [], selection: $selectedCarIDs) { car in Text(car.name) .draggable(car) } } else { Text("no folder selected") } } }
0
0
1.2k
Jul ’23
SwiftData Query relationships not working
Overview I have 2 models: Deparment and Student Each Department can contain multiple students Each Student can only be in one Department I have DepartmentList, tapping on the department should take it to the StudentList which lists all students in the department Problem When I use Query in StudentList to filter only students for a specific department id, no students are shown. Questions: What should I do to list the students in a department? (see complete code below). let filter = #Predicate<Student> { student in student.department?.id == departmentID } let query = Query(filter: filter, sort: \.name) _students = query Complete code App @main struct SchoolApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer(for: [Department.self, Student.self]) } } Department import Foundation import SwiftData @Model class Department { var id: UUID var name: String var students: [Student] init( id: UUID, name: String, students: [Student] = [] ) { self.id = id self.name = name self.students = students } } Student import Foundation import SwiftData @Model class Student { var id: UUID var name: String @Relationship(inverse: \Department.students) var department: Department? init( id: UUID, name: String, department: Department? = nil ) { self.id = id self.name = name self.department = department } } ContentView import SwiftUI struct ContentView: View { @State private var selectedDepartment: Department? var body: some View { NavigationSplitView { DepartmentList(selectedDepartment: $selectedDepartment) } detail: { if let department = selectedDepartment { StudentList(department: department) } else { Text("no department selected") } } .task { printStoreFilePath() } } private func printStoreFilePath() { let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask) if let path = urls.map({ $0.path(percentEncoded: false) }).first { print("Storage: \(path)") } } } DepartmentList import SwiftUI import SwiftData struct DepartmentList: View { @Binding var selectedDepartment: Department? @Query(sort: \.name) private var departments: [Department] @Environment(\.modelContext) private var modelContext var body: some View { List(selection: $selectedDepartment) { ForEach(departments) { department in NavigationLink(value: department) { Text(department.name) } } } .toolbar { ToolbarItem { Button { addDepartment() } label: { Label("Add", systemImage: "plus") } } } } private func addDepartment() { guard let index = (1000..<10000).randomElement() else { return } let department = Department(id: UUID(), name: "Department \(index)") modelContext.insert(department) } } StudentList import SwiftUI import SwiftData struct StudentList: View { var department: Department @Query private var students: [Student] @Environment(\.modelContext) private var modelContext init(department: Department) { self.department = department let departmentID = department.id let filter = #Predicate<Student> { student in student.department?.id == departmentID } let query = Query(filter: filter, sort: \.name) _students = query } var body: some View { List { ForEach(students) { student in Text(student.name) } } .toolbar { ToolbarItem { Button { addStudent() } label: { Label("Add", systemImage: "plus") } } } } private func addStudent() { guard let index = (1000..<10000).randomElement() else { return } let student = Student( id: UUID(), name: "Student \(index)", department: department ) modelContext.insert(student) } }
10
4
4.1k
Jul ’23
App Icon colors don't match Display P3 color profile (16 bits / channel)
Hi, Overview: My app's icon uses Display P3 colors. The PNG when opened in Preview seems to have the correct colours, but when added to Asset catalog as App icon, the installed app's app icon doesn't have the correct colors. The Preview app's inspector shows the following: Colour Model: RGB Depth: 16 DPI Height: 72 DPI Width: 72 Orientation: 1 (Normal) Pixel Height: 1,024 Pixel Width: 1,024 Profile Name: Display P3 Steps followed: I have an app icon that uses the Display P3 color profile. In Sketch, I have assigned the P3 Display color profile, exported as PNG. Realised it was using only 8 bits / channel color depth. So opened PNG in Pixelmator and changed color depth to 16 bits / channel and exported the PNG. The PNG when opened in Preview seems to have the correct colours, but when used in I even tried to use Display P3 Gamut in asset catalog and provide the same icon for sRGB and Display P3, yet the installed app's icon's colors don't match Questions: What should I do to correct this problem? Any help would be much appreciated.
6
0
2.3k
May ’23
You can only submit two builds per day to Beta App Review.
Overview I am using Xcode Cloud to create builds. It contains 2 post actions: TestFlight Internal Testing - Succeeded TestFlight External Testing - Failed Error Xcode doesn't display the exact error it only shows the status as Not Submitted for Beta Review When I checked AppStoreConnect > TestFlight I saw the status as Read to Submit. When I manually tried to add external testers to the build using AppStoreConnect website, then I got the error: You can only submit two builds per day to Beta App Review. Questions This seems like a very odd limitation. How do we test multiple builds? Why isn't Xcode the exact error? It only shows Not Submitted for Beta Review
3
0
3.5k
Feb ’23
Beta app review submission failed (Submission limit has been reached.)
Hi, I have Xcode Cloud setup for external testers to test my app which is not yet released on the App Store. It is a multi platform app, the iOS app is successful and is available for testing. TestFlight External Testing - macOS (Post-Actions) status: iOS: Successful (available for external testers) macOS: Failed - Beta app review submission failed (Submission limit has been reached.) Developer Server Status doesn't seem to show any outages. It would be great if it could be fixed and also if it is related to Apple Server issues it would be great if this is also tracked so that it is more transparent and is alerted to the relevant team to be fixed @Jason could you help with this, many thanks!
0
0
1.3k
Dec ’22
Add keyboard shortcut for Search
Overview I have a SwiftUI list with a search field I would like to add a keyboard shortcut for search field to be in focus Questions: How can I add a keyboard shortcut for search field? import SwiftUI struct ContentView: View { @State private var searchText = "" var body: some View { NavigationStack { List(0..<100) { index in Text("Cell \(index)") } .searchable(text: $searchText) } } }
0
1
958
Dec ’22
Logger on Xcode console
Overview: I am logging some messages using Logger I would like these messages to be printed on to Xcode without the timestamp and other details I want only the message to be displayed Questions: How can I display only the message on the Xcode console (see preferred output)? Is there a setting in Xcode to remove the timestamp prefix? Is there an alternate approach? Note: I need to use Logger because this app would be released, so print is not an option. Example Code import SwiftUI import os struct ContentView: View { let logger = Logger(subsystem: "MyApp", category: "MyCategory") var body: some View { Text("Hello, world!") .onAppear { logger.debug("content view displayed") } } } Actual Output: 2022-11-25 18:41:10.116408+0800 Demo[36175:5518724] [MyCategory] content view displayed Preferred Output: One of the following would be ideal: content view displayed Demo[36175:5518724] [MyCategory] content view displayed My Failed Attempt I event tried to use print in debug mode, but couldn't make it compile: Following is my failed attempt: import os #if DEBUG struct Logger { let subsystem: String let category: String func debug(_ message: String) { print(message) } //This will not help: // func debug(_ message: OSLogMessage) { // print(message) // } } #endif
4
1
4.8k
Nov ’22
On macOS Open system settings > Security & Privacy > Calendar - Follow-up: 814223720
Hi, I have a Mac app that uses calendar. When the user has not granted access and still wants to access the calendar I would like to open System Settings Privacy and Security pane for calendar on the mac. How can I do this? Is it ok to open system settings this way? Or is there a better way? I would like to publish this app to the AppStore so want to know if this is ok? if let urlString = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars") { NSWorkspace.shared.open(urlString) }
2
0
2.0k
Nov ’22
FB11812450: DatePicker on macOS after Esc key is pressed becomes unresponsive / unselectable
Overview On macOS when a user clicks on the date in a date picker field a pop up opens with options to select the date if the user taps on Esc key, then there is no option to select that field or any other field. Feedback: FB11812450 Questions: Am I missing something? Is this a bug? (Feedback: FB11812450) Steps to reproduce Run the code (see below) on macOS Click on the date portion of the date picker field A pop up opens Press the Esc key Actual Behaviour You can't select the date picker again to change the date. Expected Behaviour When the the escape key is pressed the popup should close and the date picker and other text fields should be selectable again. Code struct ContentView: View { @State private var date = Date() @State private var note = "hello world" var body: some View { VStack { DatePicker("Birthday", selection: $date) TextField("Note", text: $note) } } }
1
0
969
Nov ’22
iPad NavigationSplitView - Detect if contentView is a slide over
Overview I have a 3 column NavigationSplitView On iPad I would like to detect if the sidebar (red) / content (green) is a slide over I don't want to rely on orientation as it is possible to have multiple apps side by side and that can change the view size Questions: On iPad, how can I detect if sidebar (red) / content (green) is a slide over? Or is there an alternate approach? Code: struct ContentView: View { @State private var splitViewVisibility = NavigationSplitViewVisibility.automatic var body: some View { NavigationSplitView(columnVisibility: $splitViewVisibility) { Color.red } content: { Color.green } detail: { Color.blue } } } Screenshot Slide over Not Slide Over
0
0
821
Nov ’22
FB11794798: NSPersistentCloudKitContainer throws lots of error / debug messages
Hi, When using NSPersistentCloudKitContainer lots of error / debug messages are shown in Xcode Debug area. Feedback FB11794798: Overview When I use NSPersistentCloudKitContainer I get the following error / debug messages printed on the Xcode Debug Area. Syncing seems to happen fine. Tested on device and simulator. I am still using Development (not deployed to Production yet) I even tried with a new project using the default code generated for by enabling CloudKit coredata sync and I still get the same messages. I have filed a feedback FB11794798 Steps to Reproduce Create a new project check Use CoreData and Host in CloudKit check boxes Run the project Notice the error messages shown below. Questions How to resolve these errors? Or is this a bug from the Apple Frameworks? (Feedback FB11794798) Error / debug message printed on Xcode debug area CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](36): Validating options: <NSCloudKitMirroringDelegateOptions: 0x600000760510> containerIdentifier:<MyContainerID> databaseScope:Private ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO useDeviceToDeviceEncryption:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<PFCloudKitContainerProvider: 0x600003764210> storeMonitorProvider:<PFCloudKitStoreMonitorProvider: 0x600003764220> metricsClient:<PFCloudKitMetricsClient: 0x600003764230> metadataPurger:<PFCloudKitMetadataPurger: 0x600003764240> scheduler:<null> notificationListener:<null> containerOptions:<null> defaultOperationConfiguration:<null> progressProvider:<NSPersistentCloudKitContainer: 0x60000205d200> test_useLegacySavePolicy:YES archivingUtilities:<PFCloudKitArchivingUtilities: 0x600003764250> bypassSchedulerActivityForInitialImport:NO storeOptions: { NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; NSPersistentCloudKitContainerOptionsKey = "<NSPersistentCloudKitContainerOptions: 0x600003b3a190>"; NSPersistentHistoryTrackingKey = 1; NSPersistentStoreMirroringOptionsKey = { NSPersistentStoreMirroringDelegateOptionKey = "<NSCloudKitMirroringDelegate: 0x600000c642a0>"; }; NSPersistentStoreRemoteChangeNotificationOptionKey = 1; } CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate observeChangesForStore:inPersistentStoreCoordinator:](416): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Observing store: <NSSQLCore: 0x14080aec0> (URL: file:///Users/<my home folder>/Library/Group%20Containers/group.<app name>/<filename>.sqlite) CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _setUpCloudKitIntegration](562): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Successfully enqueued setup request. CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest](3209): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Checking for pending requests. CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]_block_invoke(3222): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Executing: <NSCloudKitMirroringDelegateSetupRequest: 0x600001643f20> D3975DD0-1198-40F2-9D6A-B9994B9710B6 CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](446): Skipping migration for 'ANSCKDATABASEMETADATA' because it already has a column named 'ZLASTFETCHDATE'
0
1
1.4k
Nov ’22
Toolbar Menu button seems to look disabled
Overview On macOS, in a NavigationSplitView when the menu button is added to the detail view toolbar, it seems to look disabled Environment Xcode: 14.1 beta 3 (14B5033e) macOS: 13.0 Beta (22A5365d) Code: struct ContentView: View { @State private var selectedNumber: Int? var body: some View { NavigationSplitView { List(0..<100, selection: $selectedNumber) { number in Text("cell \(number)") } } detail: { Text("Detail") .toolbar { ToolbarItem { Menu { Button("aa") {} Button("bb") {} } label: { Label("Add Bookmark", systemImage: "book") } } } } } } Steps to reproduce: Run the project on macOS Select cell 0 on the sidebar Click on the book toolbar button and notice the menu appear Select cell 1 on the sidebar Expected Behaviour After step 4, the book toolbar button should look prominent (like it is enabled) Actual Behaviour After step 4, the book toolbar button looks like it is disabled. Screenshot
Replies
1
Boosts
1
Views
1.7k
Activity
Nov ’23
How to download macOS Sonoma installer?
I am only able to upgrade from Ventura to Sonoma. I don't want to upgrade, I would like to download the installer so that I can install Sonoma on a separate Volume instead of upgrading. Am I missing something? I only see an option to upgrade and the developer website only allows me to download a IPSW file. I have only 1 Mac and I am not sure how I can use the IPSW file to install macOS Sonoma. Any help would be much appreciated, thanks
Replies
18
Boosts
1
Views
18k
Activity
Oct ’23
Copyable doesn't work with NavigationSplitView
Problem When copyable is used with NavigationSplitView then it doesn't work The menu Edit > Copy is disabled Note When copyable is not used with a NavigationSplitView and used only with a plain List then it works. Question Is there anything I am missing? Feedback FB12990593 Platform macOS 14.0 Beta (23A5312d) Xcode 15.0 beta 6 (15A5219j) Steps to reproduce Run the app on mac Select some cars Press Command C Expected Behaviour Menu Edit > Copy should be enabled Pressing Command C should allow user to copy selected cars Actual Behaviour Menu Edit > Copy is disabled Pressing Command C doesn't allow user to copy selected cars Code struct ContentView: View { @State private var dataStore = DataStore() var body: some View { NavigationSplitView { Color.brown } detail: { CarListView(dataStore: dataStore) } } } struct CarListView: View { let dataStore: DataStore @State private var selectedCarIDs = Set<UUID>() var body: some View { List(selection: $selectedCarIDs) { ForEach(dataStore.cars) { car in CarCell(car: car) .draggable(car) } } .copyable(selectedCars()) } private func selectedCars() -> [Car] { dataStore.cars.filter { selectedCarIDs.contains($0.id) } } } struct CarCell: View { let car: Car var body: some View { VStack(alignment: .leading) { Text(car.name) Text("\(car.price)") } } } @Observable class DataStore { var cars = [ Car(name: "aaa", price: 10), Car(name: "bbb", price: 20), Car(name: "ccc", price: 30), Car(name: "ddd", price: 40) ] } struct Car: Codable, Transferable, Identifiable { let id: UUID let name: String let price: Int init(name: String, price: Int) { self.id = UUID() self.name = name self.price = price } static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .car) } } extension UTType { static let car = UTType("com.example.car")! }
Replies
2
Boosts
2
Views
949
Activity
Aug ’23
EditButton causes the selection in sidebar view to be lost
Problem When app is run on iPhone 14 pro simulator running iOS 17 tapping on the EditButton shows the text "No folder selected" Feedback Feedback ID: FB12953838 Steps to reproduce: Run the app on iOS 17 iPhone simulator Tap on the "Edit" Button Expected Behaviour The view should show the car list in the edit mode Actual Behaviour The view shows the text "No folder selected" Note: Problem happens only the first time, subsequently EditButton works fine. Environment: iOS: 17 Platform: iPhone 14 pro simulator Xcode: 15.0 beta 6 (15A5219j) Code ContentView import SwiftUI struct ContentView: View { @State private var selectedFolderID: Int? @StateObject private var dataStore = DataStore() var body: some View { NavigationSplitView { FolderListView( selectedFolderID: $selectedFolderID, dataStore: dataStore ) } detail: { if let selectedFolderID { CarListView( selectedFolderID: selectedFolderID, dataStore: dataStore ) } else { Text("No folder selected") } } } } FolderListView import SwiftUI struct FolderListView: View { @Binding var selectedFolderID: Int? @ObservedObject var dataStore: DataStore var body: some View { List(dataStore.folders, selection: $selectedFolderID) { folder in NavigationLink(value: folder.id) { Text(folder.name) } } .task { selectedFolderID = dataStore.folders.first?.id } } } CarListView import SwiftUI struct CarListView: View { let selectedFolderID: Int @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { List( dataStore.cars(withFolderID: selectedFolderID), selection: $selectedCarIDs ) { car in Text(car.name) } .toolbar { //Tapping on the EditButton on the iPhone, shows the text "No folder selected". EditButton() } } } DataStore import Foundation class DataStore: ObservableObject { @Published var folders = [Folder(id: 0, name: "Folder 1"), Folder(id: 1, name: "Folder 2"), Folder(id: 2, name: "Folder 3"), Folder(id: 3, name: "Folder 4"), Folder(id: 4, name: "Folder 5")] @Published var carIDsInFolder: [Folder.ID : [Car.ID]] = [0: [0, 1], 1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [8, 9]] @Published var cars = [Car(id: 0, name: "aaa", price: 100), Car(id: 1, name: "bbb", price: 110), Car(id: 2, name: "ccc", price: 120), Car(id: 3, name: "ddd", price: 130), Car(id: 4, name: "eee", price: 140), Car(id: 5, name: "fff", price: 150), Car(id: 6, name: "iii", price: 160), Car(id: 7, name: "jjj", price: 170), Car(id: 8, name: "***", price: 180), Car(id: 9, name: "lll", price: 190)] func cars(withFolderID folderID: Folder.ID) -> [Car] { let carIDs = carIDsInFolder[folderID] ?? [] return carIDs.compactMap { car(withID: $0) } } func car(withID carID: Car.ID) -> Car? { cars.first { $0.id == carID } } } Car import Foundation struct Car: Identifiable { var id: Int var name: String var price: Int } Folder import Foundation struct Folder: Identifiable { var id: Int var name: String }
Replies
2
Boosts
0
Views
803
Activity
Aug ’23
Draggable doesn't work with multiple items in a list
Problem: On macOS, unable to drag multiple car items from FolderDetail List Single items from a list are draggable but multiple items are not draggable. Feedback FB10128110 I am really saddened that this is not fixed for over a year. Please look into this. Platform macOS 14 (beta 3), macOS 13 Steps to reproduce Run the code provided below Tap the sidebar button to show the sidebar Select "Folder 0" from the sidebar Drag "car a" into "Folder 1" (Go to Folder 2 to notice this happened successfully, you will be able to see "car a" in Folder 1) Select "Folder 0" from the sidebar Select "car a" and "car b" and try to drag them to "Folder 2" Expected Behaviour "car a" and "car b" must be both draggable (multiple items should be draggable). The entire cell needs to be draggable not just the Text. Actual Behaviour Though “car a” and “car b” are selected, when dragged only one of the 2 items is dragged You also can drag them only when dragging the Text unlike in iOS where you can drag the cell. Note: Same code works on iOS Code: UTType extension UTType { static var car = UTType(exportedAs: "com.example.DragAndDropListDemo.car") } Car import Foundation import CoreTransferable struct Car: Identifiable { var id: Int var name: String } //extension Car: Codable {} extension Car: Codable, Transferable { static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .car) } } Folder struct Folder: Identifiable, Hashable { var id: Int var name: String } DataStore class DataStore: ObservableObject { var folders = (0..<100).map { Folder(id: $0, name: "folder \($0)")} var cars = [0: [Car(id: 0, name:"car a"), Car(id: 1, name:"car b")], 1: [Car(id: 2, name:"car c"), Car(id: 3, name:"car d")]] } Views ContentView struct ContentView: View { @StateObject private var dataStore = DataStore() @State private var selectedFolder: Folder? var body: some View { NavigationSplitView { FolderList(selectedFolder: $selectedFolder, dataStore: dataStore) } detail: { FolderDetail(folder: selectedFolder, dataStore: dataStore) } } } FolderList struct FolderList: View { @Binding var selectedFolder: Folder? @ObservedObject var dataStore: DataStore var body: some View { List(dataStore.folders, selection: $selectedFolder) { folder in NavigationLink(value: folder) { Text(folder.name) .dropDestination(for: Car.self) { cars, location in print("cars = \(cars) location = \(location)") if let existingCars = dataStore.cars[folder.id] { dataStore.cars[folder.id] = existingCars + cars } else { dataStore.cars[folder.id] = cars } return true } } } } } FolderDetail struct FolderDetail: View { let folder: Folder? @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { if let folder { List(dataStore.cars[folder.id] ?? [], selection: $selectedCarIDs) { car in Text(car.name) .draggable(car) } } else { Text("no folder selected") } } }
Replies
0
Boosts
0
Views
1.2k
Activity
Jul ’23
SwiftData Query relationships not working
Overview I have 2 models: Deparment and Student Each Department can contain multiple students Each Student can only be in one Department I have DepartmentList, tapping on the department should take it to the StudentList which lists all students in the department Problem When I use Query in StudentList to filter only students for a specific department id, no students are shown. Questions: What should I do to list the students in a department? (see complete code below). let filter = #Predicate<Student> { student in student.department?.id == departmentID } let query = Query(filter: filter, sort: \.name) _students = query Complete code App @main struct SchoolApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer(for: [Department.self, Student.self]) } } Department import Foundation import SwiftData @Model class Department { var id: UUID var name: String var students: [Student] init( id: UUID, name: String, students: [Student] = [] ) { self.id = id self.name = name self.students = students } } Student import Foundation import SwiftData @Model class Student { var id: UUID var name: String @Relationship(inverse: \Department.students) var department: Department? init( id: UUID, name: String, department: Department? = nil ) { self.id = id self.name = name self.department = department } } ContentView import SwiftUI struct ContentView: View { @State private var selectedDepartment: Department? var body: some View { NavigationSplitView { DepartmentList(selectedDepartment: $selectedDepartment) } detail: { if let department = selectedDepartment { StudentList(department: department) } else { Text("no department selected") } } .task { printStoreFilePath() } } private func printStoreFilePath() { let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask) if let path = urls.map({ $0.path(percentEncoded: false) }).first { print("Storage: \(path)") } } } DepartmentList import SwiftUI import SwiftData struct DepartmentList: View { @Binding var selectedDepartment: Department? @Query(sort: \.name) private var departments: [Department] @Environment(\.modelContext) private var modelContext var body: some View { List(selection: $selectedDepartment) { ForEach(departments) { department in NavigationLink(value: department) { Text(department.name) } } } .toolbar { ToolbarItem { Button { addDepartment() } label: { Label("Add", systemImage: "plus") } } } } private func addDepartment() { guard let index = (1000..<10000).randomElement() else { return } let department = Department(id: UUID(), name: "Department \(index)") modelContext.insert(department) } } StudentList import SwiftUI import SwiftData struct StudentList: View { var department: Department @Query private var students: [Student] @Environment(\.modelContext) private var modelContext init(department: Department) { self.department = department let departmentID = department.id let filter = #Predicate<Student> { student in student.department?.id == departmentID } let query = Query(filter: filter, sort: \.name) _students = query } var body: some View { List { ForEach(students) { student in Text(student.name) } } .toolbar { ToolbarItem { Button { addStudent() } label: { Label("Add", systemImage: "plus") } } } } private func addStudent() { guard let index = (1000..<10000).randomElement() else { return } let student = Student( id: UUID(), name: "Student \(index)", department: department ) modelContext.insert(student) } }
Replies
10
Boosts
4
Views
4.1k
Activity
Jul ’23
App Icon colors don't match Display P3 color profile (16 bits / channel)
Hi, Overview: My app's icon uses Display P3 colors. The PNG when opened in Preview seems to have the correct colours, but when added to Asset catalog as App icon, the installed app's app icon doesn't have the correct colors. The Preview app's inspector shows the following: Colour Model: RGB Depth: 16 DPI Height: 72 DPI Width: 72 Orientation: 1 (Normal) Pixel Height: 1,024 Pixel Width: 1,024 Profile Name: Display P3 Steps followed: I have an app icon that uses the Display P3 color profile. In Sketch, I have assigned the P3 Display color profile, exported as PNG. Realised it was using only 8 bits / channel color depth. So opened PNG in Pixelmator and changed color depth to 16 bits / channel and exported the PNG. The PNG when opened in Preview seems to have the correct colours, but when used in I even tried to use Display P3 Gamut in asset catalog and provide the same icon for sRGB and Display P3, yet the installed app's icon's colors don't match Questions: What should I do to correct this problem? Any help would be much appreciated.
Replies
6
Boosts
0
Views
2.3k
Activity
May ’23
You can only submit two builds per day to Beta App Review.
Overview I am using Xcode Cloud to create builds. It contains 2 post actions: TestFlight Internal Testing - Succeeded TestFlight External Testing - Failed Error Xcode doesn't display the exact error it only shows the status as Not Submitted for Beta Review When I checked AppStoreConnect > TestFlight I saw the status as Read to Submit. When I manually tried to add external testers to the build using AppStoreConnect website, then I got the error: You can only submit two builds per day to Beta App Review. Questions This seems like a very odd limitation. How do we test multiple builds? Why isn't Xcode the exact error? It only shows Not Submitted for Beta Review
Replies
3
Boosts
0
Views
3.5k
Activity
Feb ’23
Beta app review submission failed (Submission limit has been reached.)
Hi, I have Xcode Cloud setup for external testers to test my app which is not yet released on the App Store. It is a multi platform app, the iOS app is successful and is available for testing. TestFlight External Testing - macOS (Post-Actions) status: iOS: Successful (available for external testers) macOS: Failed - Beta app review submission failed (Submission limit has been reached.) Developer Server Status doesn't seem to show any outages. It would be great if it could be fixed and also if it is related to Apple Server issues it would be great if this is also tracked so that it is more transparent and is alerted to the relevant team to be fixed @Jason could you help with this, many thanks!
Replies
0
Boosts
0
Views
1.3k
Activity
Dec ’22
Add keyboard shortcut for Search
Overview I have a SwiftUI list with a search field I would like to add a keyboard shortcut for search field to be in focus Questions: How can I add a keyboard shortcut for search field? import SwiftUI struct ContentView: View { @State private var searchText = "" var body: some View { NavigationStack { List(0..<100) { index in Text("Cell \(index)") } .searchable(text: $searchText) } } }
Replies
0
Boosts
1
Views
958
Activity
Dec ’22
Logger on Xcode console
Overview: I am logging some messages using Logger I would like these messages to be printed on to Xcode without the timestamp and other details I want only the message to be displayed Questions: How can I display only the message on the Xcode console (see preferred output)? Is there a setting in Xcode to remove the timestamp prefix? Is there an alternate approach? Note: I need to use Logger because this app would be released, so print is not an option. Example Code import SwiftUI import os struct ContentView: View { let logger = Logger(subsystem: "MyApp", category: "MyCategory") var body: some View { Text("Hello, world!") .onAppear { logger.debug("content view displayed") } } } Actual Output: 2022-11-25 18:41:10.116408+0800 Demo[36175:5518724] [MyCategory] content view displayed Preferred Output: One of the following would be ideal: content view displayed Demo[36175:5518724] [MyCategory] content view displayed My Failed Attempt I event tried to use print in debug mode, but couldn't make it compile: Following is my failed attempt: import os #if DEBUG struct Logger { let subsystem: String let category: String func debug(_ message: String) { print(message) } //This will not help: // func debug(_ message: OSLogMessage) { // print(message) // } } #endif
Replies
4
Boosts
1
Views
4.8k
Activity
Nov ’22
On macOS Open system settings > Security & Privacy > Calendar - Follow-up: 814223720
Hi, I have a Mac app that uses calendar. When the user has not granted access and still wants to access the calendar I would like to open System Settings Privacy and Security pane for calendar on the mac. How can I do this? Is it ok to open system settings this way? Or is there a better way? I would like to publish this app to the AppStore so want to know if this is ok? if let urlString = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars") { NSWorkspace.shared.open(urlString) }
Replies
2
Boosts
0
Views
2.0k
Activity
Nov ’22
FB11812450: DatePicker on macOS after Esc key is pressed becomes unresponsive / unselectable
Overview On macOS when a user clicks on the date in a date picker field a pop up opens with options to select the date if the user taps on Esc key, then there is no option to select that field or any other field. Feedback: FB11812450 Questions: Am I missing something? Is this a bug? (Feedback: FB11812450) Steps to reproduce Run the code (see below) on macOS Click on the date portion of the date picker field A pop up opens Press the Esc key Actual Behaviour You can't select the date picker again to change the date. Expected Behaviour When the the escape key is pressed the popup should close and the date picker and other text fields should be selectable again. Code struct ContentView: View { @State private var date = Date() @State private var note = "hello world" var body: some View { VStack { DatePicker("Birthday", selection: $date) TextField("Note", text: $note) } } }
Replies
1
Boosts
0
Views
969
Activity
Nov ’22
iPad NavigationSplitView - Detect if contentView is a slide over
Overview I have a 3 column NavigationSplitView On iPad I would like to detect if the sidebar (red) / content (green) is a slide over I don't want to rely on orientation as it is possible to have multiple apps side by side and that can change the view size Questions: On iPad, how can I detect if sidebar (red) / content (green) is a slide over? Or is there an alternate approach? Code: struct ContentView: View { @State private var splitViewVisibility = NavigationSplitViewVisibility.automatic var body: some View { NavigationSplitView(columnVisibility: $splitViewVisibility) { Color.red } content: { Color.green } detail: { Color.blue } } } Screenshot Slide over Not Slide Over
Replies
0
Boosts
0
Views
821
Activity
Nov ’22
FB11794798: NSPersistentCloudKitContainer throws lots of error / debug messages
Hi, When using NSPersistentCloudKitContainer lots of error / debug messages are shown in Xcode Debug area. Feedback FB11794798: Overview When I use NSPersistentCloudKitContainer I get the following error / debug messages printed on the Xcode Debug Area. Syncing seems to happen fine. Tested on device and simulator. I am still using Development (not deployed to Production yet) I even tried with a new project using the default code generated for by enabling CloudKit coredata sync and I still get the same messages. I have filed a feedback FB11794798 Steps to Reproduce Create a new project check Use CoreData and Host in CloudKit check boxes Run the project Notice the error messages shown below. Questions How to resolve these errors? Or is this a bug from the Apple Frameworks? (Feedback FB11794798) Error / debug message printed on Xcode debug area CoreData: debug: CoreData+CloudKit: -[PFCloudKitOptionsValidator validateOptions:andStoreOptions:error:](36): Validating options: <NSCloudKitMirroringDelegateOptions: 0x600000760510> containerIdentifier:<MyContainerID> databaseScope:Private ckAssetThresholdBytes:<null> operationMemoryThresholdBytes:<null> useEncryptedStorage:NO useDeviceToDeviceEncryption:NO automaticallyDownloadFileBackedFutures:NO automaticallyScheduleImportAndExportOperations:YES skipCloudKitSetup:NO preserveLegacyRecordMetadataBehavior:NO useDaemon:YES apsConnectionMachServiceName:<null> containerProvider:<PFCloudKitContainerProvider: 0x600003764210> storeMonitorProvider:<PFCloudKitStoreMonitorProvider: 0x600003764220> metricsClient:<PFCloudKitMetricsClient: 0x600003764230> metadataPurger:<PFCloudKitMetadataPurger: 0x600003764240> scheduler:<null> notificationListener:<null> containerOptions:<null> defaultOperationConfiguration:<null> progressProvider:<NSPersistentCloudKitContainer: 0x60000205d200> test_useLegacySavePolicy:YES archivingUtilities:<PFCloudKitArchivingUtilities: 0x600003764250> bypassSchedulerActivityForInitialImport:NO storeOptions: { NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; NSPersistentCloudKitContainerOptionsKey = "<NSPersistentCloudKitContainerOptions: 0x600003b3a190>"; NSPersistentHistoryTrackingKey = 1; NSPersistentStoreMirroringOptionsKey = { NSPersistentStoreMirroringDelegateOptionKey = "<NSCloudKitMirroringDelegate: 0x600000c642a0>"; }; NSPersistentStoreRemoteChangeNotificationOptionKey = 1; } CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate observeChangesForStore:inPersistentStoreCoordinator:](416): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Observing store: <NSSQLCore: 0x14080aec0> (URL: file:///Users/<my home folder>/Library/Group%20Containers/group.<app name>/<filename>.sqlite) CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _setUpCloudKitIntegration](562): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Successfully enqueued setup request. CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest](3209): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Checking for pending requests. CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndExecuteNextRequest]_block_invoke(3222): <NSCloudKitMirroringDelegate: 0x600000c642a0>: Executing: <NSCloudKitMirroringDelegateSetupRequest: 0x600001643f20> D3975DD0-1198-40F2-9D6A-B9994B9710B6 CoreData: debug: CoreData+CloudKit: -[PFCloudKitMetadataModelMigrator calculateMigrationStepsWithConnection:error:](446): Skipping migration for 'ANSCKDATABASEMETADATA' because it already has a column named 'ZLASTFETCHDATE'
Replies
0
Boosts
1
Views
1.4k
Activity
Nov ’22