This topic area is about the programming languages themselves, not about any specific API or tool. If you have an API question, go to the top level and look for a subtopic for that API. If you have a question about Apple developer tools, start in the Developer Tools & Services topic.
For Swift questions:
If your question is about the SwiftUI framework, start in UI Frameworks > SwiftUI.
If your question is specific to the Swift Playground app, ask over in Developer Tools & Services > Swift Playground
If you’re interested in the Swift open source effort — that includes the evolution of the language, the open source tools and libraries, and Swift on non-Apple platforms — check out Swift Forums
If your question is about the Swift language, that’s on topic for Programming Languages > Swift, but you might have more luck asking it in Swift Forums > Using Swift.
General:
Forums topic: Programming Languages
Swift:
Forums subtopic: Programming Languages > Swift
Forums tags: Swift
Developer > Swift website
Swift Programming Language website
The Swift Programming Language documentation
Swift Forums website, and specifically Swift Forums > Using Swift
Swift Package Index website
Concurrency Resources, which covers Swift concurrency
How to think properly about binding memory Swift Forums thread
Other:
Forums subtopic: Programming Languages > Generic
Forums tags: Objective-C
Programming with Objective-C archived documentation
Objective-C Runtime documentation
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Objective-C
RSS for tagObjective-C is a programming language for writing iOS, iPad OS, and macOS apps.
Posts under Objective-C tag
92 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Recently, we have adapted the passkey function on the Mac, but we always encounter the error message "Unable to verify the web credentials association of xxx with domain aaa. Please try again in a few seconds."
We can confirm that https://aaa/.well-known/apple-app-site-association has been configured and is accessible over the public network. Additionally, the entitlements in the app have also been set with webcredentials:aaa.
This feature has been experiencing inconsistent performance. When I restart my computer or reinstall the pkg, this feature may work or it may still not work. I believe this is a system issue.
Here is feed back ID: FB20876945
In the feedback, I provided the relevant logs.
If you have any suggestions or assistance, please contact me. I would be extremely grateful!
Topic:
Privacy & Security
SubTopic:
General
Tags:
macOS
Objective-C
Authentication Services
Passkeys in iCloud Keychain
Hi all,
when I launch my macOS app from Xcode 16 on ARM64, appKit logs me this error on the debug console:
It's not legal to call -layoutSubtreeIfNeeded on a view which is already being laid out. If you are implementing the view's -layout method, you can call -[super layout] instead. Break on _NSDetectedLayoutRecursion(void) to debug. This will be logged only once. This may break in the future.
_NSDetectedLayoutRecursion doesn't help a lot, giving me these assembly codes from a call to a subclassed window method that looks like this:
-(void) setFrame:(NSRect)frameRect display:(BOOL)flag {
if (!_frameLocked) [super setFrame:frameRect display:flag];
}
I have no direct call to -layoutSubtreeIfNeeded from a
-layout implementation in my codes. I have a few calls to this method from update methods, however even if I comment all of them, the error is still logged...
Finally, apart from that log, I cannot observe any layout error when running the program. So I wonder if this error can be safely ignored?
Thanks!
The MXCrashDiagnostic and MXHangDiagnostic reports are not being returned via MXMetricManager on the next app launch in iOS 17.2, 17.3, 17.4, and 17.5. This issue prevents collection of crash and hang diagnostics through the MetricKit framework, which worked as expected on earlier and later (18, 26) iOS versions.
Steps to Reproduce:-
Integrate MetricKit in an iOS app using:
MXMetricManager.shared.add(self)
and implement:
func didReceive(_ payloads: [MXDiagnosticPayload])
Install and run the app on a device running iOS 17.2 or later.
Cause a crash or hang scenario (e.g., dereference a null pointer or block the main thread).
Relaunch the app after the system terminates it.
Observe the callback for diagnostic payloads.
Expected Behavior
MXMetricManager.shared.didReceive(_:) should be invoked on the next launch, returning diagnostic payloads that include MXCrashDiagnostic or MXHangDiagnostic objects.
Actual Behavior:
No diagnostics are returned on subsequent launches.
didReceive(_:) is not triggered, or the diagnostic payloads array is empty.
This behavior is reproducible across multiple devices and iOS versions (17.2–17.5).
iOS Versions: 17.2, 17.3, 17.4, 17.5
Devices Tested: iPhone 14, iPhone 15 Pro
Xcode Version: 15.2 / 15.3
Framework: MetricKit
Diagnostic Type: Crash and Hang
Hello,
I have a question about data deserialization using NSKeyedUnarchiver in iOS SDK development.
Current Situation:
Previously, we were using the NSKeyedUnarchiver.unarchiveObject(with: Data) function
We have changed to using the NSKeyedUnarchiver.unarchivedObject(ofClasses:from:) method to deserialize complex objects stored in UserDefaults
We need to include all types in the ofClasses parameter, including Swift primitive types as well as various custom classes and structs within the project
Questions:
Implementation Approach: Is it correct pattern to include all classes defined in the project in the ofClasses array? Is this approach recommended?
Runtime Stability: When using this approach, is there a possibility of runtime crashes? Are there any performance issues?
Alternative Methods: If the current approach is not the correct pattern, what alternatives should we consider?
Current Code Structure:
All model classes conform to the NSSecureCoding protocol
We use the requiringSecureCoding: true parameter
We use a whitelist approach, explicitly listing only allowed classes
I would like to know if this structure is appropriate, or if we should consider a different approach.
Thank you.
Hi,
I’m trying to open a GPX file (route.gpx) from the Files app on my iPhone using my app (e.g., Aqua Map).
Since the latest iOS update (iOS 26), when I long-press the file and tap “Open with…”, my app does not appear in the list anymore.
I’ve checked that my app has the correct permissions for Files and Folders. I’m wondering:
Is this a user-side issue (Settings on iPhone)?
Or does it require developer-side changes in the app (Info.plist / UTI declarations) to make .gpx files appear in “Open with…” or “Share” menus?
What is the proper way to make my app appear as an option to open GPX files in Files.app on iOS 26?
Thanks in advance!
I have a custom object which gets passed back to the main app from XPC.
I whitelist it like so:
NSSet *expectedClass = [NSSet setWithObjects:[NSArray class],
[MyCustomClass class],
nil];
[interface setClasses:expectedClass forSelector:@selector(myMethodNameHere:withCompletion:)
argumentIndex:0
ofReply:YES];
Now my custom class conforms to NSSecureCoding. It does have an array property of another custom class.
@property (nonatomic,readonly) NSArray *arraypropertyOfOtherClass;
Which is decoded in -initWithCoder: using:
-decodeArrayOfObjectsOfClasses:forKey:
Now on macOS Tahoe this is all walking fine. But I just tested on macOS Monterey and I get the following error:
Exception: decodeObjectForKey: too many nested collections when explicitly decoding a single collection.
How should I handle this for earlier versions of macOS?
To establish a privileged helper daemon from a command line app to handle actions requiring root privileges I still use the old way of SMJobBless. But this is deprecated since OSX 10.13 and I want to finally update it to the new way using SMAppService.
As I'm concerned with securing it against malicious exploits, do you have a recommended up-to-date implementation in Objective-C establishing a privileged helper and verifying it is only used by my signed app?
I've seen the suggestion in the documentation to use SMAppService, but couldn't find a good implementation covering security aspects. My old implementation in brief is as follows:
bool runJobBless () {
// check if already installed
NSFileManager* filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath:@"/Library/PrivilegedHelperTools/com.company.Helper"] &&
[filemgr fileExistsAtPath:@"/Library/LaunchDaemons/com.company.Helper.plist"])
{
// check helper version to match the client
// ...
return true;
}
// create authorization reference
AuthorizationRef authRef;
OSStatus status = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authRef);
if (status != errAuthorizationSuccess) return false;
// obtain rights to install privileged helper
AuthorizationItem authItem = { kSMRightBlessPrivilegedHelper, 0, NULL, 0 };
AuthorizationRights authRights = { 1, &authItem };
AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
status = AuthorizationCopyRights (authRef, &authRights, kAuthorizationEmptyEnvironment, flags, NULL);
if (status != errAuthorizationSuccess) return false;
// SMJobBless does it all: verify helper against app and vice-versa, place and load embedded launchd.plist in /Library/LaunchDaemons, place executable in /Library/PrivilegedHelperTools
CFErrorRef cfError;
if (!SMJobBless (kSMDomainSystemLaunchd, (CFStringRef)@"com.company.Helper", authRef, &cfError)) {
// check helper version to match the client
// ...
return true;
} else {
CFBridgingRelease (cfError);
return false;
}
}
void connectToHelper () {
// connect to helper via XPC
NSXPCConnection* c = [[NSXPCConnection alloc] initWithMachServiceName:@"com.company.Helper.mach" options:NSXPCConnectionPrivileged];
c.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol (SilentInstallHelperProtocol)];
[c resume];
// call function on helper and wait for completion
dispatch_semaphore_t semaphore = dispatch_semaphore_create (0);
[[c remoteObjectProxy] callFunction:^() {
dispatch_semaphore_signal (semaphore);
}];
dispatch_semaphore_wait (semaphore, dispatch_time (DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC));
dispatch_release (semaphore);
[c invalidate];
[c release];
}
Looking to update one of my apps that uses SKStoreReviewController +requestReview (deprecated) to
AppStore.requestReview(in:)
umm...I have a few of questions...
Why is an NSViewController parameter required? It's really not so uncommon for an AppKit app to just use NSWindowController with a window that does not use NSViewController...
It should be possible to present the review request in a standalone alert (attached to a window is preferred IMO but it still should be possible to ask in separate window).
3)...why Swift..(err nevermind)
Ideally:
AppStore requestReview should take a NSWindow parameter but that parameter should be optional. If nil the request should be presented in a standalone window (like an alert). If non nil..present as a sheet on the window.
Why a view controller? Maybe I'm missing something.
Will Apple continue to support it, or will we wake up one day to find that Swift is the only viable language?It's a serious question. Careers depend on it. I don't accept the "No comment" approach that Apple usually takes. It's cruel.I'm willing to put the time into learning Swift if I have to. I'm not going to do it if I don't. I want to know.Frank
I have a project that need to get serial number and network SSID. I have looking anywhere to get those 2 value but no luck to find it. is there anyway i can get those information from the device?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x115fadbc0'
*** First throw call stack:
(0x1940bd8c8 0x1910097c4 0x194159838 0x19403a4f8 0x1940423a0 0x1e42cb9a8 0x1e42ce220 0x106f02c08 0x1080a461c 0x1080be2b0 0x1080acb2c 0x1080ad7b4 0x1080b9b00 0x1080b91a4 0x1eecdb3b8 0x1eecda8c0)
libc++abi: terminating due to uncaught exception of type NSException
InputAnalytics called timeIntervalSinceReferenceDate in dispatch_sync.The display issue of the call stack occurs in two stages: keyboard input analysis and folding the keyboard.
After adding protection to NSString, it can function normally, but I want to know the reason
#import "NSString+Safe.h"
@implementation NSString (Safe)
- (NSTimeInterval)timeIntervalSinceReferenceDate {
return 0;
}
- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)date {
return 0;
}
@end
I can compile this
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (strong) NSWindow *window;
@property (strong) NSSlider *slider;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
// Window size
NSRect frame = NSMakeRect(0, 0, 400, 300);
NSUInteger style = NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable |
NSWindowStyleMaskResizable;
self.window = [[NSWindow alloc] initWithContentRect:frame
styleMask:style
backing:NSBackingStoreBuffered
defer:NO];
[self.window setTitle:@"Centered Slider Example"];
[self.window makeKeyAndOrderFront:nil];
// Slider size
CGFloat sliderWidth = 200;
CGFloat sliderHeight = 32;
CGFloat windowWidth = self.window.frame.size.width;
CGFloat windowHeight = self.window.frame.size.height;
CGFloat sliderX = (windowWidth - sliderWidth) / 2;
CGFloat sliderY = (windowHeight - sliderHeight) / 2;
self.slider = [[NSSlider alloc] initWithFrame:NSMakeRect(sliderX, sliderY, sliderWidth, sliderHeight)];
[self.slider setMinValue:0];
[self.slider setMaxValue:100];
[self.slider setDoubleValue:50];
[self.window.contentView addSubview:self.slider];
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSApplication *app = [NSApplication sharedApplication];
AppDelegate *delegate = [[AppDelegate alloc] init];
[app setDelegate:delegate];
[app run];
}
return 0;
}
with
(base) johnzhou@Johns-MacBook-Pro liquidglasstest % clang -framework Foundation -framework AppKit testobjc.m
and get this neat liquid glass effect:
https://github.com/user-attachments/assets/4199493b-6011-4ad0-9c9f-25db8585e547
However if I use pyobjc to make an equivalent
import sys
from Cocoa import (
NSApplication, NSApp, NSWindow, NSSlider, NSMakeRect,
NSWindowStyleMaskTitled, NSWindowStyleMaskClosable,
NSWindowStyleMaskResizable, NSBackingStoreBuffered,
NSObject
)
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, notification):
# Create the main window
window_size = NSMakeRect(0, 0, 400, 300)
style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable
self.window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
window_size, style, NSBackingStoreBuffered, False
)
self.window.setTitle_("Centered Slider Example")
self.window.makeKeyAndOrderFront_(None)
# Slider size and positioning
slider_width = 200
slider_height = 32
window_width = self.window.frame().size.width
window_height = self.window.frame().size.height
slider_x = (window_width - slider_width) / 2
slider_y = (window_height - slider_height) / 2
self.slider = NSSlider.alloc().initWithFrame_(NSMakeRect(slider_x, slider_y, slider_width, slider_height))
self.slider.setMinValue_(0)
self.slider.setMaxValue_(100)
self.slider.setDoubleValue_(50)
self.window.contentView().addSubview_(self.slider)
if __name__ == "__main__":
app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
app.run()
I get a result shown at
https://github.com/user-attachments/assets/7da022bc-122b-491d-9e08-030dcb9337c3
which does not have the new liquid glass effect.
Why is this? Is this perhaps related to the requirement that you must compile on latest Xcode as indicated in the docs? Why, is the compiler doing some magic?
I am encountering a critical issue where a custom background image on a UIToolbar fails to display when the app is built with Xcode 26 and run on iOS 26 beta. The exact same implementation works perfectly on iOS 18 and earlier versions.
We first attempted to use the legacy setBackgroundImage method, which fails to render the image on iOS 26:
// 1. Get Navigation Bar and set basic properties
UINavigationBar* navBar = self.navigationBar;
navBar.hidden = NO;
navBar.translucent = NO;
// 2. Setup the UIToolbar instance
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:navBar.bounds];
toolBar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
// 3. Set the resizable image (This image does not appear on iOS 26)
UIImage* imagePortrait = [UIImage imageNamed:@"nav_bg"];
UIEdgeInsets insets = UIEdgeInsetsMake(0.f, 6.f, 0.f, 6.f);
[toolBar setBackgroundImage:[imagePortrait resizableImageWithCapInsets:insets]
forToolbarPosition:UIToolbarPositionAny
barMetrics:UIBarMetricsDefault];
We then migrated to the recommended modern UIToolbarAppearance to solve this, but the issue persists:
// 1. Prepare Image
UIImage* imagePortrait = [UIImage imageNamed:@"nav_bg"];
// Insets are applied via resizableImageWithCapInsets: (not shown in this snippet but implied)
// 2. Configure UIToolbarAppearance
UIToolbarAppearance *appearance = [[UIToolbarAppearance alloc] init];
appearance.backgroundImage = imagePortrait; // The image is correctly loaded (not nil)
// 3. Apply the Appearance
toolBar.standardAppearance = appearance;
// We also applied to scrollEdgeAppearance and compactAppearance.
Any information or recommended workarounds for displaying a custom background image on UIToolbar in the latest iOS 26 would be highly appreciated.
Hello,
I'm currently trying to make a collaborative app. But it just works only on Reality View, when I tried to use Compositor Layer like below, the personas disappeared.
ImmersiveSpace(id: "ImmersiveSpace-Metal") {
CompositorLayer(configuration: MetalLayerConfiguration()) { layerRenderer in
SpatialRenderer_InitAndRun(layerRenderer)
}
}
Is there any potential solution too see Personas in Metal view?
Thanks in advance!
I keep getting the following error when trying to run Passkey sign in on macOS.
Told not to present authorization sheet: Error Domain=com.apple.AuthenticationServicesCore.AuthorizationError Code=1 "(null)"
ASAuthorizationController credential request failed with error: Error Domain=com.apple.AuthenticationServices.AuthorizationError Code=1004 "(null)"
This is the specific error.
Application with identifier a is not associated with domain b
I have config the apple-app-site-association link and use ?mode=developer
Could there be any reason for this?
Topic:
Privacy & Security
SubTopic:
General
Tags:
macOS
Objective-C
Authentication Services
Passkeys in iCloud Keychain
Greetings,
With MacOS 15 Sequoia, Apple updated key-value-observations in such a way, that an unremoved observation by a now deallocated object will no longer cause an exception, when the observed object triggers said observation.
While this is fundamentally a positive change, the issue comes with the fact, that this change affects systems based on the version of their operating system and not the version of the operating system of the build system.
Many of our customers use old operating system versions and old hardware - meaning they can't easily update. Since we need to use up to date Xcode versions to develop for newer systems, our developers tend to have rather new OS versions.
This means, that we are increasingly facing bugs which only happen in customer systems but not in most developer (or QA) systems.
Currently, we still can use earlier OS versions with Xcode to fix these bugs, but once the used Xcode versions no longer support MacOS 14 or below this will become a major hurdle.
Are there known solutions to this issue?
We are currently attempting to swizzle observer adding and removal in order to fix the problem for old systems as well, but this has proven to be quite difficult and unstable. Since any weakly held property in the middle of an observation keypath can cause crashes, one would have to split up observations into multiple subobservations, which is less simple than it sounds, due to custom implementations of addObserver (such as there seems to be in array controller proxies) and collection operators.
Thanks for any suggestions!
We're trying to implement a backup/restore data feature in our business productivity iPad app using UIDocumentPickerViewController and AppleArchive, but discovered odd behavior of [UIDocumentPickerViewController initForOpeningContentTypes: asCopy:YES] when reading large archive files from a USB drive.
We've duplicated this behavior with iPadOS 16.6.1 and 17.7 when building our app with Xcode 15.4 targeting minimum deployment of iPadOS 16. We haven't tested this with bleeding edge iPadOS 18.
Here's our Objective-C code which presents the picker:
NSArray* contentTypeArray = @[UTTypeAppleArchive];
UIDocumentPickerViewController* docPickerVC = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:contentTypeArray asCopy:YES];
docPickerVC.delegate = self;
docPickerVC.allowsMultipleSelection = NO;
docPickerVC.shouldShowFileExtensions = YES;
docPickerVC.modalPresentationStyle = UIModalPresentationPopover;
docPickerVC.popoverPresentationController.sourceView = self.view;
[self presentViewController:docPickerVC animated:YES completion:nil];
The UIDocumentPickerViewController remains visible until the selected external archive file has been copied from the USB drive to the app's local tmp sandbox. This may take several seconds due to the slow access speed of the USB drive. During this time the UIDocumentPickerViewController does NOT disable its tableview rows displaying files found on the USB drive. Even the most patient user will tap the desired filename a second (or third or fourth) time since the user's initial tap appears to have been ignored by UIDocumentPickerViewController, which lacks sufficient UI feedback showing it's busy copying the selected file.
When the user taps the file a second time, UIDocumentPickerViewController apparently begins to copy the archive file once again. The end result is a truncated copy of the selected file based on the time between taps. For instance, a 788 MB source archive may be copied as a 56 MB file. Here, the UIDocumentPickerDelegate receives a 56 MB file instead of the original 788 MB of data.
Not surprisingly, AppleArchive fails to decrypt the local copy of the archive because it's missing data. Instead of failing gracefully, AppleArchive crashes in AAArchiveStreamClose() (see forums post 765102 for details).
Does anyone know if there's a workaround for this strange behavior of UIDocumentPickerViewController?
3
I am working on an application to get when input audio device is being used. Basically I want to know the application using the microphone (built-in or external)
This app runs on macOS. For Mac versions starting from Sonoma I can use this code:
int getAudioProcessPID(AudioObjectID process)
{
pid_t pid;
if (@available(macOS 14.0, *)) {
constexpr AudioObjectPropertyAddress prop {
kAudioProcessPropertyPID,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMain
};
UInt32 dataSize = sizeof(pid);
OSStatus error = AudioObjectGetPropertyData(process, &prop, 0, nullptr, &dataSize, &pid);
if (error != noErr) {
return -1;
}
} else {
// Pre sonoma code goes here
}
return pid;
}
which works.
However, kAudioProcessPropertyPID was added in macOS SDK 14.0.
Does anyone know how to achieve the same functionality on previous versions?
When the app launches, it assigns the correct string stored in NSUserDefaults to the instance variable (serverAddress) of type NSString.
Afterwards, when the app transitions to a suspended state and receives a VoIP Push notification approximately 4 hours later, causing the app to enter the background state, referencing the value of serverAddress may result in it showing as <NSMallocBlock: 0x106452d60> even though it hasn't been deallocated. This does not occur every time.
The specific class definitions are as follows.
@implementation NewPAPEOPLEClient
{
NSString* serverAddress;
NSString* apiKey;
dispatch_semaphore_t lock;
NSMutableArray* errCallID;
}
#define PREF_STR(key) [[NSUserDefaults standardUserDefaults] stringForKey:(key)
The global instance variable (serverAddress) is set with the following value when the application starts:
serverAddress = PREF_STR(@"APP_CONTACT_SERVICE_SERVER_ADDRESS")
Based on the above, please answer the following questions.
(1) If the instance variable's value becomes <NSMallocBlock: 0x106452d60>, does that mean the memory area has been released?
(2) Can the memory area of an instance variable be automatically released without being explicitly released?
Can an instance variable of type NSString that is not autoreleased be automatically released?
(3) Please tell me how to prevent the memory area from being automatically released. Will using retain prevent automatic release?