I have view showing a list of contacts. When the user taps one, I want to raise a sheet that shows the contact's phone numbers and E-mail addresses and lets the user pick one.
When the user taps a list entry, I store the associated Contact object into a @State variable called selectedContact. Then I set the boolean that's bound to the sheet modifier's isPresented flag. That modifier:
.sheet(isPresented: $showContactMethodSheet, content: { ContactMethodView(withContact: selectedContact!) })
But the app crashes, because despite selectedContact having been set. It looks like the sheet was pre-built with a nil selected contact upon view load. Why, and what is the expected approach here?
Post
Replies
Boosts
Views
Activity
The only iOS 17 target available in Xcode 16.2's build settings appears to be iOS 17.6.
But there are no simulators (at least that I can find) with anything beyond iOS 17.5. Therefore you can't test on iOS 17 with a simulator, because none will show as a deployment target.
What is the expected course of action here? I'm sure there are many cases where developers need to test on iOS 17, but in mine I need to test the new framework for accessing a user's contacts; it has changed significantly, and I need to make sure it degrades gracefully on iOS 17.
I'm not inclined to make my application inaccessible to 20% of the user base.
In the past I've used #if available to isolate functionality gaps at the code level in my apps.
But yesterday I was trying to integrate the new methods Apple has made available for granting access to contacts, as discussed here: https://developer.apple.com/documentation/contacts/accessing-a-person-s-contact-data-using-contacts-and-contactsui
The problem is that their example is rife with code that won't compile for iOS 17, which is still (from the last stats I found) 20% of the user base.
I also experimented with @available; but when I was nearly done integrating the new methods, a compiler bug halted my entire project. It now simply doesn't build (the ol' non-zero exit code) with no further details or errors flagged. I filed a report, as requested in the logs.
In the meantime, I have to start over. What is the recommended method for isolating large blocks of functionality that are only available to a later OS version?
I'm trying to track down why an external tool is claiming that Xcode isn't installed, despite it being installed (and used daily) in its default location.
A visit to Xcode's Settings/Locations page shows a version selected for command-line tools, but underneath it says "No Xcode Selected."
Why?
Over and over I see claims that you can use ButtonStyle to style the appearance of NavigationLinks. But in my experience, this does not work.
What's going on here? In the screen shot, the list items (NavigationLinks) are styled with the same button style as the button below them. As you can see, this does nothing.
Code for the whole view:
// ContentView.swift
import SwiftUI
struct UserMessage : Hashable
{
var title: String
var text: String
}
let inMessages = [UserMessage(title: "Inbound 1", text: "Test message!"), UserMessage(title: "Inbound 2", text: "Test message!"), UserMessage(title: "Inbound 3", text: "Test message!")]
let outMessages = [UserMessage(title: "Outbound 1", text: "Test message!"), UserMessage(title: "Outbound 2", text: "Test message!"), UserMessage(title: "Outbound 3", text: "Test message!")]
struct NavLinkButton: ButtonStyle
{
func makeBody(configuration: Configuration) -> some View
{
configuration.label
.frame(maxWidth: .infinity)
.padding()
.foregroundStyle(.purple)
.background(configuration.isPressed ? .blue : .green)
.clipShape(RoundedRectangle(cornerRadius: 10))
.overlay {
RoundedRectangle(cornerRadius: 10)
.stroke(.red, lineWidth: configuration.isPressed ? 2 : 0)
}
.padding(3)
}
}
struct ContentView: View
{
var body: some View
{
NavigationStack
{
messageList(msgsIn: inMessages, msgsOut: outMessages)
.frame(maxWidth: 400, maxHeight: 400)
Button(action: {}, label: { Text("Styled button") })
.buttonStyle(NavLinkButton())
.frame(maxWidth: 400)
Spacer()
}
}
@ViewBuilder func messageList(msgsIn: [UserMessage], msgsOut: [UserMessage]) -> some View
{
List
{
Section(header: Text("Your Inbox"))
{
ForEach(msgsIn, id: \.self) { aMsg in
NavigationLink(destination: MessageDetailView(withMessage: aMsg), label: { Text("\(aMsg.title)") })
.buttonStyle(NavLinkButton())
}
.listRowBackground(Color.clear)
}
Section(header: Text("Your Outbox"))
{
ForEach(msgsOut, id: \.self) { aMsg in
NavigationLink(destination: MessageDetailView(withMessage: aMsg), label: { Text("\(aMsg.title)") })
.buttonStyle(NavLinkButton())
}
.listRowBackground(Color.clear)
}
}
.scrollContentBackground(.hidden)
}
}
struct MessageDetailView: View
{
var message: UserMessage?
init(withMessage: UserMessage)
{
message = withMessage
}
var body: some View
{
Text(message?.title ?? "")
}
}
I've written a little utility targeting Mac, for personal use. In it, I need to be able to select a file from an arbitrary location on my drive.
I have the "user selected file" entitlement added, and I have added my application to "Full Disk Access." But I still get a permissions error when I select a file with the file-open dialog (via .fileImporter).
I dragged the application from the Xcode build directory to Applications before adding it to Full Disk Access. Any ideas?
I'm trying (in Swift) to use CryptoKit to generate the required JWT for the Apple Music Web API, as documented (sort of) here.
But I'm getting 401s no matter what I try. I found some examples of generating JWTs online, but something isn't working here. I've set up my identifiers and gotten an API secret through my account in the dev portal. It's associated with an identifier requesting Music API access (I requested all three available Music-related capabilities).
For the secret, I'm using the long key string from the .p8 file I generated and downloaded from the dev portal.
Here's what I've tried:
struct APIToken
{
struct Header: Encodable
{
let alg = "HS256"
let kid: String
}
struct Payload: Encodable
{
let iss: String
let iat: String
let exp: String
}
static func tokenize(keyID: String, issuerID: String, secret: String) -> String
{
let privateKey = SymmetricKey(data: Data(secret.utf8))
let headerJSONData = try! JSONEncoder().encode(Header(kid: keyID))
let headerBase64String = headerJSONData.base64EncodedString()
let currUnixTime = Int(Date().timeIntervalSince1970)
let expUnixTime = currUnixTime + 5 * 2628288 // five months of seconds
let payloadJSONData = try! JSONEncoder().encode(Payload(iss: issuerID, iat: "\(currUnixTime)", exp: "\(expUnixTime)"))
let payloadBase64String = payloadJSONData.base64EncodedString()
let toSign = Data((headerBase64String + "." + payloadBase64String).utf8)
let signature = HMAC<SHA256>.authenticationCode(for: toSign, using: privateKey)
let signatureBase64String = Data(signature).base64EncodedString()
let token = [headerBase64String, payloadBase64String, signatureBase64String].joined(separator: ".")
print(token)
return token
}
}
I also tried making sure the base64 strings are URL-safe with this extension:
extension Data
{
func URLSafeBase64EncodedString() -> String
{
return base64EncodedString()
.replacingOccurrences(of: "+", with: "-")
.replacingOccurrences(of: "/", with: "_")
.replacingOccurrences(of: "=", with: "")
}
}
but that made no difference.
All the documentation says is
A decoded developer token has the following format.
{
"alg": "ES256",
"kid": "ABC123DEFG"
}
{
"iss": "DEF123GHIJ",
"iat": 1437179036,
"exp": 1493298100
}
After you create the token, sign it with your MusicKit private key using the ES256 algorithm.
Am I not doing that? Any insight appreciated.
Something (or a lot) is janky about apps built for "My Mac - designed for iPad."
Aside from things just not working, the amount of garbage spewed to the console during debugging is unmanageable. I can't see my own trace statements amongst screens and screens of repetitive nonsense.
I right-clicked on it and set it to filter out errors, but I'd like to get notified of legitimate errors. Anyone employing a clever filtering method I'm not aware of?
I can't find any way to search for a song by title only. You can search for songs, but any term you provide appears to be applied to any metadata associated with the song. Look at the largely nonsensical results when I search for a song with the letters "de":
In many cases, that string doesn't appear anywhere. I used
MusicCatalogSearchRequest(term: searchTerm, types: [Song.self])
Likewise it stands to reason that people want to search for artist and album names using text strings. How do we do that?
I don't see any certificates or CAs in the Passwords application, so now what?
My application suddenly started crashing on launch when I target "My Mac - designed for iPad." But only after the first build from scratch, which runs once. All subsequent runs crash with:
dyld[90869]: Symbol not found: _OBJC_CLASS_$_AVPlayerView
Referenced from: <D566512D-CAB4-3EA6-9B87-DBD15C6E71B3> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Debugger/libViewDebuggerSupport.dylib
Expected in: <4C34313C-03AD-32EB-8722-8A77C64AB959> /System/iOSSupport/System/Library/Frameworks/AVKit.framework/Versions/A/AVKit
I don't use AVPlayerView anywhere in my application. A file-contents search of the entire source tree doesn't turn it up either. The application doesn't even get to the point of instantiating the app object, so none of my code is involved.
If I switch the target to my iPhone, it will build and run repeatedly. If I then switch back to "My Mac," it will build and run once... and then crash every time.
Further research shows that this only happens in Debug builds.
This is a major issue right now because iOS 18 broke authentication certificates (thus HTTPS), so anyone writing or debugging an app that needs network functionality must use HTTP on localhost. In my case, I'm dead in the water because I can't debug on my local machine.
Has anyone seen something like this before? I can find no reference to anything like it.
Hi all. I renewed my membership, got a confirmation E-mail, and followed the link in it to check the status. It says "enrollment complete." But if I log into the developer portal, it says "membership expired."
There is no chat option for support, only a form for E-mail. The response time quoted is up to two days. Meanwhile, I can't implement some critical features in an app I'm building, because they require an active developer account.
Not cool, Apple. Anybody else experience this?
I have a project that has been building fine up until recently, when I started seeing spurious errors flagged in the editor on lines that were correct... and when the build was reported as successful and the app ran. The lines were often flagged twice for the same "error," and selecting the suggested "fix" produced syntactically incorrect lines because Xcode replaced the wrong characters.
Now the builds are actually failing, on correct lines and preprocessing failures (allegedly missing header files that have never been missing before, with no project changes).
Also there's a lot of
Could not read serialized diagnostics file: error("Invalid diagnostics signature")
reported in the build output, although that's categorized as a warning.
Cleaning and deleting DerivedData has no effect. I'm not using CocoaPods or Swift packages, which you see cited in a lot of reports about this.
Has anyone found a workaround?