Comments (8)
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.
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.
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.
Can you try the equivalent of this using darwinkit
or in main
when this PR is merged:
#176
from macdriver.
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.
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.
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.
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)
- Framework Request: CryptoKit
- Related project: c_ocoa HOT 2
- Are there any plans to add Keychain Service?
- SetDefaultApplicationAtURLToOpenContentTypeCompletionHandler error
- ComboBox `SetDelegate` uses `TextField`'s `SetDelegte` resulting in error HOT 1
- module github.com/progrium/macdriver@latest found (v0.4.0), but does not contain package github.com/progrium/macdriver/keycode HOT 2
- Can I use Network Extension HOT 2
- Framework Request: ScreenCaptureKit
- DarwinKit: Rendering Problem with OutlineView
- SetDuration Can not set duration for amination
- Nib's InstantiateWithOwnerTopLevelObjects() not returning objects HOT 9
- Generator change: keep Objective-C type when parameter is a pointer to a pointer HOT 1
- Framework Request: StoreKit HOT 2
- enumexport error with call to s.Parse
- Generating appkit problem with enumtypes.gen.go and aliastypes.gen.go
- APFS (Case-sensitive) filesystem protocols.gen.m:3:9: fatal error:: 'Appkit/Appkit.h' file not found
- Can macdriver be used to implement macOS widgets and install them directly into the macOS notification center or desktop?
- corelocation API giving panic HOT 6
- Dictionary's DictionaryWithObjectsAndKeys() throws NSInvalidArgumentException HOT 6
- An error occurs when running the layout example. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from macdriver.