Fix nil issue with several Array and Dictionary methods#247
Fix nil issue with several Array and Dictionary methods#247programmingkidx wants to merge 1 commit intoprogrium:mainfrom
Conversation
|
Since only certain files are generated, you could make this "special file" in the target package. As long as it doesn't have ".gen" in the filename. Seems like an easier approach you could have used? Unless I'm missing something for this new approach. |
|
Also, couldn't we just convert go nil to objc nil somewhere? |
That could work. |
That would not work. As soon as a call to say NSArray's dictionaryWithObjectsAndKeys: from a Go wrapper a crash would happen. |
I guess to clarify are we trying to make passing |
Actually both. For people who want to stick with the Objective-c convention of terminating an array with nil, they win. For people who want to move away from terminating an array with nil, they win too. This method is used to handle nil. It might be able to explain things: |
Several foundation methods take a list of objects and expect a nil to be used to terminate the list. Problem is the nil these methods want is an Objective-c nil. Using Go's nil causes a crash to take place.
This pull request fixes the issue with several nil terminated methods. The way I fixed the issue was by introducing a new system that uses a file called special.go to override and prevent the generation of specified methods.
A new folder called special will be in the "generated" folder of DarwinKit. In this folder will be a platform folder. Currently we have a macOS folder. Inside the platform folder is a framework folder. This currently has a foundation folder. Inside this folder is a file called special.go. This file will contain the definition for methods that we don't want the generation system to make. To tell the generation system not to try to generate any method, the special.go file will contain a table. This table has this format:
It is all located inside a comment. It begins with the text "begin-skip" on its own line, and ends with the text "end-skip" on its own line. Between these lines will be three fields that are separated by commas and each is wrapped with double quotes. The fields will be an objective-c class name, a selector, and a note.
Example: "NSMutableDictionary", "initWithObjectsAndKeys:", "using custom implementation"
With this pull request methods like MutableDictionary's InitWithObjectsAndKeys() will actually work. Go's nil can be used to terminate the list or it can be omitted.