Coder Social home page Coder Social logo

Comments (8)

progrium avatar progrium commented on May 13, 2024

All strings need to ultimately be wrapped with core.String(), so that should help here. I think the idea was the manual bindings would do this for you, but when it takes arguments of any type here we can't do that. Well, we could have a function do a type switch and convert...

from macdriver.

programmingkidx avatar programmingkidx commented on May 13, 2024

Ok I tried wrapping the strings but I still see an error. Here is the program I made:

package main

import "github.com/progrium/macdriver/core"
import "fmt"

func main() {
	oneStr := core.String("one")
	twoStr := core.String("two")
	dict := core.NSDictionary_Init(oneStr, twoStr, nil)
	fmt.Println("dictionary:", dict)
}

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?'
*** First throw call stack:
(
0 CoreFoundation 0x00000001bf532b08 __exceptionPreprocess + 240
1 libobjc.A.dylib 0x00000001bf27de14 objc_exception_throw + 60
2 CoreFoundation 0x00000001bf476764 -[NSDictionary initWithObjectsAndKeys:] + 792
3 main 0x0000000104a16960 VariadicCall + 96
4 ??? 0x000001400011c750 0x0 + 1374390699856
)
libc++abi: terminating with uncaught exception of type NSException
SIGABRT: abort
PC=0x1bf3b0db8 m=0 sigcode=0
signal arrived during cgo execution

Did I do something wrong?

from macdriver.

progrium avatar progrium commented on May 13, 2024

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.

from macdriver.

progrium avatar progrium commented on May 13, 2024

Can you try the equivalent of this using darwinkit or in main when this PR is merged:
#176

from macdriver.

programmingkidx avatar programmingkidx commented on May 13, 2024

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.

from macdriver.

progrium avatar progrium commented on May 13, 2024

https://pkg.go.dev/github.com/progrium/[email protected]/macos/foundation#NewDictionary
https://pkg.go.dev/github.com/progrium/[email protected]/macos/foundation#Dictionary_DictionaryWithObjectsAndKeys

But it looks like we don't support variadic methods! Making a separate issue: #181

from macdriver.

progrium avatar progrium commented on May 13, 2024

It should work with the latest PR, though the first object still has to be an IObject, however there are some custom helpers for more easily building NSDictionaries from Go maps. There is now a test case that demonstrates all of this, which I'll include here:

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")
	}
}

from macdriver.

progrium avatar progrium commented on May 13, 2024

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.

from macdriver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.