Post

Replies

Boosts

Views

Activity

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
NavigationStack and NavigationSplitView Runtime warnings
Overview: When running the demo code presented in "The SwiftUI cookbook for navigation" (https://developer.apple.com/wwdc22/10054) I ran into some issues: Runtime warnings: 2022-06-08 22:20:31.587169+0800 NavigationSplitViewDemo[17797:672165] [SwiftUI] A NavigationLink is presenting a value of type “Category” but there is no matching navigation destination visible from the location of the link. The link cannot be activated. onChange(of: UpdateTrigger) action tried to update multiple times per frame. 2022-06-08 22:15:23.432289+0800 NavigationSplitViewDemo[17645:662571] [UIFocus] _TtGC7SwiftUI14_UIHostingViewGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__ implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen. Feedback filed: FB10103041 and FB10104196
13
4
8.2k
Aug ’22
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.0k
Jul ’23
macOS test case - Could not launch app
Hi, Overview I am using Xcode Cloud for my multi platform app. The macOS test case fails, however the iOS test case runs and succeeds. I don't have any UI test cases written, the test case are simple and have nothing platform (macOS) specific. Questions What can I do to fix this? Is there any user privileges needed to launch the macOS app for testing? I ask because when I ran the UI tests locally it launched the app and asked for my macOS user password. Just wondering if that is the reason it didn't launch in Xcode Cloud. Error: <Appname> encountered an error (Failed to install or launch the test runner. If you believe this error represents a bug, please attach the result bundle at /Volumes/workspace/resultbundle.xcresult.(Underlying Error: Could not launch "AppnameTests. The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed. (Underlying Error: Launch job spawn failed) ))) × Could not launch "<Appname>" × Could not launch "AppnameTests" × AppnameUITests.testExample() Failed to get launch progress for <XCUIApplicationImpl: 0x600000564630 <BundleID> at /Volumes/workspace/TestProducts/Debug-Dev/<Appname>.app>: Could not launch "app name". The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed. (Underlying Error: Launch job spawn failed)) AppnameUITests.swift:28 * AppnameUITests.testLaunchPerformance) Failed to get launch progress for «XCUIApplicationimpl: 0x60000054630 <BundleID> at /Volumes/workspace/TestProducts/Debug-Dev/<Appname>.apps: Could not launch "<Appname>". The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed. (Underlying Error: Launch job spawn failed)) AppnameUITests.swift:37 g * AppnameUITestsLaunchTests.testLaunch) Failed to get launch progress for «XCUIApplicationimpl: 0x60000054630 <BundleID> at /Volumes/workspace/Testroducts/Debug-Dev/<Appname>.apps: Could not launch "<Appname>". The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed.
6
0
2.8k
Feb ’25
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.2k
May ’23
#Predicate doesn't work with enum
Problem The following code doesn't work: let predicate = #Predicate<Car> { car in car.size == size //This doesn't work } Console Error Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedPredicate) Root cause Size is an enum, #Predicate works with other type such as String however doesn't work with enum Enum value is saved however is not filtered by #Predicate Environment Xcode: 15.0 (15A240d) - App Store macOS: 14.0 (23A339) - Release Candidate Steps to reproduce Run the app on iOS 17 or macOS Sonoma Press the Add button Notice that the list remains empty Expected behaviour List should show the newly created small car Actual behaviour List remains empty inspite of successfully creating the small car. Feedback FB13194334 Code Size enum Size: String, Codable { case small case medium case large } Car import SwiftData @Model class Car { let id: UUID let name: String let size: Size init( id: UUID, name: String, size: Size ) { self.id = id self.name = name self.size = size } } ContentView struct ContentView: View { var body: some View { NavigationStack { CarList(size: .small) } } CarList import SwiftUI import SwiftData struct CarList: View { let size: Size @Environment(\.modelContext) private var modelContext @Query private var cars: [Car] init(size: Size) { self.size = size let predicate = #Predicate<Car> { car in car.size == size //This doesn't work } _cars = Query(filter: predicate, sort: \.name) } var body: some View { List(cars) { car in VStack(alignment: .leading) { Text(car.name) Text("\(car.size.rawValue)") Text(car.id.uuidString) .font(.footnote) } } .toolbar { Button("Add") { createCar() } } } private func createCar() { let name = "aaa" let car = Car( id: UUID(), name: name, size: size ) modelContext.insert(car) } }
6
1
2.4k
May ’25
Swift Concurrency (async let) - Cancellation
I am a bit confused about tasks being cancelled. Overview: checkCancellation function has 2 child tasks: computeA and computeB that run concurrently, computeB throws an error. Doubt: I expected child task computeA to be cancelled because computeB threw an error, but computeA was never cancelled. Is my understanding wrong or am I missing something? Or is this a bug? Note: I am using a SwiftUI project (as Swift Playgrounds don't support async let) macOS Big Sur 11.5.2 (20G95) Xcode Version 13.0 beta 5 (13A5212g) Output: A - started B - going to throw A - going to return, Task.isCancelled = false error: infinity Concurrent Function Definitions: import Foundation import UIKit enum ComputationError: Error { case infinity } fileprivate func computeA() async throws -&gt; Int { print("A - started") await Task.sleep(2 * 100_000_000) print("A - going to return, Task.isCancelled = \(Task.isCancelled)") //I expected Task.isCancelled to be true return 25 } fileprivate func computeB() async throws -&gt; Int { print("B - going to throw") throw ComputationError.infinity } func checkCancellation() async throws { async let a = computeA() async let b = computeB() let c = try await a + b print("c = \(c)") } Invoking Concurrent function struct ContentView: View { var body: some View { Button("check cancellation") { Task { do { try await checkCancellation() print("normal exit") } catch { print("error: \(error)") } } } } }
4
0
1.4k
Dec ’21
How to make Xcode Cloud compile code compiled in Xcode beta ?
Hi, I have an Xcode project that uses Xcode 14.0 beta 6 (14A5294g). How to make Xcode Cloud compile code compiled in Xcode beta? My code uses beta APIs that doesn't seem to compile on Xcode Cloud (throws compilation errors) Am I missing something as this would be a common scenario for many developers? How do I make the beta APIs compile on Xcode Cloud?
4
0
1.7k
Nov ’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.6k
Nov ’22
List Section with Swipe Action - glitches
Overview I have an iOS project where I have a list with sections. Each cell in the section can be swiped to have some action What needs to be done When swipe button is pressed the cell needs to move from one section to the other without a UI glitch. Problem When I press the swipe action button, there is a UI glitch and some warnings are thrown. UICollectionView internal inconsistency: unexpected removal of the current swipe occurrence's mask view. Please file a bug against UICollectionView. Reusable view: <SwiftUI.ListCollectionViewCell: 0x10700c200; baseClass = UICollectionViewListCell; frame = (16 40.3333; 370 52); hidden = YES; layer = <CALayer: 0x600000c12fa0>>; Collection view: <SwiftUI.UpdateCoalescingCollectionView: 0x106820800; baseClass = UICollectionView; frame = (0 0; 402 874); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000c13330>; backgroundColor = <UIDynamicSystemColor: 0x60000173a9c0; name = systemGroupedBackgroundColor>; layer = <CALayer: 0x600000c3a070>; contentOffset: {0, -62}; contentSize: {402, 229}; adjustedContentInset: {62, 0, 34, 0}; layout: <UICollectionViewCompositionalLayout: 0x10590edb0>; dataSource: <_TtGC7SwiftUI31UICollectionViewListCoordinatorGVS_28CollectionViewListDataSourceOs5Never_GOS_19SelectionManagerBoxS2___: 0x106822a00>>; Swipe occurrence: <UISwipeOccurrence: 0x103c161f0; indexPath: <NSIndexPath: 0xab1f048608f3828b> {length = 2, path = 0 - 0}, state: .triggered, direction: left, offset: 0> Test environment: Xcode 26.0.1 (17A400) iOS 26 Simulator (iPhone 17 Pro) Feedback filed: FB20890361 Code I have pasted below the minimum reproducible code ContentView import SwiftUI struct ContentView: View { @State private var dataStore = DataStore() var body: some View { List { ToDoSection(status: .notStarted, toDos: notStartedToDos) ToDoSection(status: .inProgress, toDos: inProgressToDos) ToDoSection(status: .completed, toDos: completedTodos) } } var notStartedToDos: [Binding<ToDoItem>] { $dataStore.todos.filter { $0.wrappedValue.status == .notStarted } } var inProgressToDos: [Binding<ToDoItem>] { $dataStore.todos.filter { $0.wrappedValue.status == .inProgress } } var completedTodos: [Binding<ToDoItem>] { $dataStore.todos.filter { $0.wrappedValue.status == .completed } } } ToDoSection import SwiftUI struct ToDoSection: View { let status: ToDoItem.Status let toDos: [Binding<ToDoItem>] var body: some View { if !toDos.isEmpty { Section(status.title) { ForEach(toDos) { toDo in Text(toDo.wrappedValue.title) .swipeActions(edge: .trailing) { if status == .notStarted { Button("Start") { toDo.wrappedValue.status = .inProgress } } if status != .completed { Button("Complete") { toDo.wrappedValue.status = .completed } Button("Move back") { toDo.wrappedValue.status = .notStarted } } } } } } } } ToDoItem import Foundation struct ToDoItem: Identifiable { let id: UUID let title: String var status: Status } extension ToDoItem { enum Status: Equatable { case notStarted case inProgress case completed var title: String { switch self { case .notStarted: "Not Started" case .inProgress: "In Progress" case .completed: "Completed" } } } } DataStore import Foundation @Observable class DataStore { var todos: [ToDoItem] init() { todos = [ ToDoItem(id: UUID(), title: "aaa", status: .notStarted), ToDoItem(id: UUID(), title: "bbb", status: .notStarted), ToDoItem(id: UUID(), title: "ccc", status: .notStarted) ] } }
Topic: UI Frameworks SubTopic: SwiftUI
4
1
218
Nov ’25
Binding value from an ObservableObject
Aim:I have a model which is an ObservableObject. It has a Bool property, I would like to use this Bool property to initialise a @Binding variable.Questions:How to convert an @ObservableObject to a @Binding ?Is creating a @State the only way to initialise a @Binding ?Note:I do understand I can make use of @ObservedObject / @EnvironmentObject, and I see it's usefulness, but I am not sure a simple button needs to have access to the entire model.Or is my understanding incorrect ?Code:import SwiftUI import Combine import SwiftUI import PlaygroundSupport class Car : ObservableObject { @Published var isReadyForSale = true } struct SaleButton : View { @Binding var isOn : Bool var body: some View { Button(action: { self.isOn.toggle() }) { Text(isOn ? "On" : "Off") } } } let car = Car() //How to convert an ObservableObject to a Binding //Is creating an ObservedObject or EnvironmentObject the only way to handle a Observable Object ? let button = SaleButton(isOn: car.isReadyForSale) //Throws a compilation error and rightly so, but how to pass it as a Binding variable ? PlaygroundPage.current.setLiveView(button)
3
5
24k
Sep ’21
Extract Data from P8 file
Hi,I am trying to extract the data from the P8 file to use it generate JWT.I understand that it is possible using dumpasn1 and extracting the OCTET STRING section. This is great, and is definitely possible.I was wondering if it was possible to do it on macOS using Apple's APIs (example SecItemImport), would make it simpler if it was possible all in the mac app.I tried the following but it didn't work:Error: I got the OSStatus as -25257Questions:- Is there a way to do this using SecItemImport or any other Apple APIs as I am using it in a command line mac app ?- Are the parameters to SecItemImport are incorrect ?- Am down the wrong path? , any direction to the correct API would help.What I tried with SecItemImport:- Data extracted from the file- Decoding the data from the file- Some input formatsMany thanks.import Foundation import Security func f1() { do { let fileURL = URL(fileURLWithPath: "some valid path"); let data = try Data(contentsOf: fileURL) guard let string = String(data: data, encoding: .utf8) else { print("Failed to convert data to string") return } let b64Text = string .replacingOccurrences(of: "-----END PRIVATE KEY-----", with: "") .replacingOccurrences(of: "-----BEGIN PRIVATE KEY-----", with: "") .replacingOccurrences(of: "\n", with: "") guard let b64Data = b64Text.data(using: .utf8), let decodedData = Data(base64Encoded: b64Data) else { print("Was not b64 data") return } print(string) var outArray : CFArray? let filename : CFString? = nil var inputFormat = SecExternalFormat.formatUnknown var itemType = SecExternalItemType.itemTypePrivateKey let flags = SecItemImportExportFlags() //I tried data, b64Data, decodedData all seems to return an error let status = SecItemImport(decodedData as CFData, filename, &amp;inputFormat, &amp;itemType, flags, nil, nil, &amp;outArray) //status = -25257 print("status = \(status)") for element in (outArray as [AnyObject]?) ?? [] { print("element = \(element)") } } catch { print("Error: \(error)") } } f1()
4
0
5.9k
May ’21
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
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
1.9k
Nov ’22
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
749
Aug ’23