The NSXPC API passed NSDictionary data, and a crash occurred

I implemented an NSXPC for inter-process data transfer, and the data transferred is NSDictionary. However, a crash occurred during transmission.

The corresponding crash logs are as follows

Thread 16 Crashed::  Dispatch queue: xpc.test.queue
0   libobjc.A.dylib               	       0x1945a24d0 objc_retain + 16
1   Foundation                    	       0x1956b7764 -[NSDictionary(NSDictionary) encodeWithCoder:] + 604
2   Foundation                    	       0x195686d9c -[NSXPCEncoder _encodeObject:] + 520
3   Foundation                    	       0x19568c154 _NSXPCSerializationAddInvocationWithOnlyObjectArgumentsArray + 120
4   Foundation                    	       0x19568c000 -[NSXPCEncoder _encodeInvocationObjectArgumentsOnly:count:typeString:selector:isReply:into:] + 212
5   Foundation                    	       0x195684f98 -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 1448
6   Foundation                    	       0x19568d584 -[NSXPCConnection _sendSelector:withProxy:arg1:] + 132
7   Foundation                    	       0x19568d4a8 _NSXPCDistantObjectSimpleMessageSend1 + 68
8   TestDemo                 	       0x1041e9308 0x104184000 + 414472
9   libdispatch.dylib             	       0x1945565f0 _dispatch_call_block_and_release + 32
10  libdispatch.dylib             	       0x1945581b4 _dispatch_client_callout + 20
11  libdispatch.dylib             	       0x19455f8a8 _dispatch_lane_serial_drain + 668
12  libdispatch.dylib             	       0x194560404 _dispatch_lane_invoke + 392
13  libdispatch.dylib             	       0x19456ac98 _dispatch_workloop_worker_thread + 648
14  libsystem_pthread.dylib       	       0x194718360 _pthread_wqthread + 288
15  libsystem_pthread.dylib       	       0x194717080 start_wqthread + 8

want to know if there is any way to check if NSDictionary data is transferable, NSDictionary data is generated dynamically, and the assignment method used is Info[@ "baseInfo"] = ***. Is this method necessary to determine whether *** is not nil?

Problems like this are usually related to a memory management bug. How reproducible is it for you?

The corresponding crash logs are as follows

Please post an example crash report, per the advice in Posting a Crash Report.

the assignment method used is Info[@ "baseInfo"] = vvv. Is this method necessary to determine whether vvv is not nil?

A nil value won’t corrupt the dictionary. Rather, it’ll remove any existing entry for baseInfo. If there is no entry for baseInfo, it’s a no-op. For example, this code:

@import Foundation;

int main(int argc, char **argv) {
    NSMutableDictionary * d = [@{
        @"k": @"v",
    } mutableCopy];
    NSLog(@"%@", d);
    d[@"k"] = nil;
    NSLog(@"%@", d);
    d[@"k"] = nil;
    NSLog(@"%@", d);
    return EXIT_SUCCESS;
}

prints this:

{
    k = v;
}
{
}
{
}

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The NSXPC API passed NSDictionary data, and a crash occurred
 
 
Q