-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
NSDictionary and golang strings issue #114
Comments
All strings need to ultimately be wrapped with |
Ok I tried wrapping the strings but I still see an error. Here is the program I made:
When I run it I see this error: 2023-07-02 08:05:48.788 main[1459:20783] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?' Did I do something wrong? |
Hmm... not sure it's you. Could be related to not supporting Golang nil. Could be related to variadic calls. Also raises the issue that at least the core/foundation code should probably have some tests. |
Can you try the equivalent of this using |
Well I did try to but I ran into a few problem. There are no NSDictionary Init() or dictionaryWithObjectsAndKeys() methods. Not sure how to create an NSDictionary object. |
https://pkg.go.dev/github.com/progrium/[email protected]/macos/foundation#NewDictionary But it looks like we don't support variadic methods! Making a separate issue: #181 |
It should work with the latest PR, though the first object still has to be an func TestFoundationDictionary(t *testing.T) {
s := String_StringWithString("bar")
d1 := Dictionary_DictionaryWithObjectsAndKeys(s, "foo", "value", "key", nil)
m1 := DictToMap[string, string](d1)
d2 := DictOf(m1)
m2 := DictToMap[string, string](d2)
if !reflect.DeepEqual(m2, map[string]string{
"foo": "bar",
"key": "value",
}) {
t.Fatal("unexpected final map from dictionary")
}
} |
Closing since there are tests passing that satisfy the original issue. Please open another issue or discussion if there is still a problem or question. |
This program adds golang strings to an NSDictionary. When the program is ran it panics with this message:
2023/07/02 00:20:26 unhandled kind: string
panic: unhandled kind: string
goroutine 1 [running]:
log.Panicf({0x1004c14a8?, 0x1004ed2c0?}, {0x140000abe30?, 0x140000b4010?, 0x100918d28?})
/usr/local/go/src/log/log.go:391 +0x64
github.com/progrium/macdriver/objc.sendMsg({0x1005044e8, 0x140000b4020}, 0x0, {0x1004c2495, 0x17}, {0x140000c0000, 0x2, 0x1004b3f38?})
/Users/user/go/pkg/mod/github.com/progrium/[email protected]/objc/msg_arm64.go:159 +0xf28
github.com/progrium/macdriver/objc.object.Send(...)
/Users/user/go/pkg/mod/github.com/progrium/[email protected]/objc/msg_arm64.go:206
github.com/progrium/macdriver/core.NSDictionary_Init({0x140000c0000, 0x2, 0x2})
/Users/user/go/pkg/mod/github.com/progrium/[email protected]/core/NSDictionary.go:17 +0x50
main.main()
/Users/user/desktop/my go app/main.go:7 +0x58
exit status 2
Could a feature be added that makes golang strings usable in an NSDictionary?
The text was updated successfully, but these errors were encountered: