Description
Previous ID | SR-2371 |
Radar | rdar:///27875914 |
Original Reporter | curt (JIRA User) |
Type | Bug |
Attachment: Download
Environment
Xcode 8b6
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, RunTimeCrash |
Assignee | None |
Priority | Medium |
md5: 277dd98cf382487b488e4fb3c9d336e4
Issue Description:
- In the attached code, an NSMutableDictionary instance is created in an Obj-C method, +[OldSchool dictionary], that is called by Swift code, NewSchool.getDict().
The Swift code updates the dictionary to map a String to a Date, then attempts to pass that dictionary back to a C function, stringValueFromDictionary(), that expects an NSDictionary.
The compiler in Xcode 8b6 surfaces the C function as taking an argument of type [AnyHashable: Any], per #116. To provide the right type, we copy the NSMutableDictionary instance and cast it to [AnyHashable: Any].
In the implementation of stringValueFromDictionary(), we retrieve the date from the dictionary, expecting it to be an NSDate object. Calling any NSDate method on the value crashes.
Steps to Reproduce:
Compile and run the attached project.
Expected Results:
The bridging of the [AnyHashable: Any] value in Swift back to NSDictionary in C should bridge the Date object to NSDate.
Actual Results:
Crash:
2016-08-16 15:51:25.232 AnyWhatNow[62058:772408] -[_SwiftValue dateByAddingTimeInterval:]: unrecognized selector sent to instance 0x100d02420
2016-08-16 15:51:25.234 AnyWhatNow[62058:772408] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue dateByAddingTimeInterval:]: unrecognized selector sent to instance 0x100d02420'
-
-
- First throw call stack:
(
0 CoreFoundation 0x00007fff8a6064f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff916c8f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff8a6701ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8a576571 _forwarding_ + 1009
4 CoreFoundation 0x00007fff8a5760f8 _CF_forwarding_prep_0 + 120
5 AnyWhatNow 0x0000000100001f5b stringValueFromDictionary + 91
6 AnyWhatNow 0x000000010000228d _TFC10AnyWhatlibc++abi.dylib: terminating with uncaught exception of type NSException
- First throw call stack:
-
Notes:
It's entirely possible that I'm just "holding it wrong", but I've found no way to insert an date object into a dictionary in Swift and successfully make that date usable in Objective-C code that receives the dictionary.