Open programmingkidx opened 6 months ago
This is an equivalent Objective-C program:
// Description: Demonstrate the use of NSDictionary's dictionaryWithObjectsAndKeys:
// Build command: clang -framework foundation dictionarytest.m && ./a.out
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"value", @"key", nil];
NSLog(@"%@", dictionary);
}
return 0;
}
When the nil argument is removed, the same kind of crash and message is displayed that the Go program experiences.
Strange, it should work with nil but maybe nil isn't being converted properly?
It looks like Objective-C doesn't like Go's nil.
Wanna look into that? Write some failing tests and then look into the conversion code to see if you can fix and make tests pass with a PR.
Actually I am finishing up my work now.
These are all the methods I know that are effected by the same issue - having to terminate a list of objects using nil:
NSDictionary initWithObjectsAndKeys
NSDictionary dictionaryWithObjectsAndKeys
NSMutableDictionary initWithObjectsAndKeys
NSMutableDictionary dictionaryWithObjectsAndKeys
NSArray arrayWithObjects
NSArray initWithObjects
NSArray NewArrayWithObjects
NSMutableArray arrayWithObjects
NSMutableArray initWithObjects
NSMutableArray NewMutableArrayWithObjects
If anyone knows of more, please let me know. Thank you.
Dictionary's DictionaryWithObjectsAndKeys() throws an NSInvalidArgumentException when it is used.
This example program will cause an exception to be thrown when ran:
Here is the error message produced by running this program:
The program still crashes when nil is removed from DictionaryWithObjectsAndKeys() arguments.