Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nil issue with several Array and Dictionary methods #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

programmingkidx
Copy link
Contributor

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:

/*
begin-skip
"class", "selector:", "note"
end-skip
*/

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.

@progrium
Copy link
Owner

progrium commented Mar 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants