Coder Social home page Coder Social logo

Comments (15)

progrium avatar progrium commented on May 13, 2024

Oof, returning objc collections is not something I've run into much yet. There's a design issue here as well as a technical one. I think what we'd want to do will depend on the type it would normally return in objc ... if it's a simple iterable we can maybe build a slice, which would involve using objc methods to iterate and build the slice. The exception being if it's a mutable collection and its part of the intended use of the API (since changing a built slice in Go won't reflect in objc). Or if the iterable class has other domain specific methods, it would make more sense to wrap in a Go type for the iterable objc class. This would mean you'd have to interact with it using methods, not Go slice/array mechanisms.

So looking at the API they're using NSArray, which is for "static" arrays, so I'd say it would make sense to iterate over the array and build a Go slice of NSRunningApplication objects.

from macdriver.

AStrangwood avatar AStrangwood commented on May 13, 2024

Thanks for the info. Using NSArray and iteration is working for me so far.

I haven't got my head around objc yet. Do you have an example of how i could get the type returned instead of just assuming its an NSArray.

from macdriver.

progrium avatar progrium commented on May 13, 2024

You can usually get an object type with the class method of any object:
https://developer.apple.com/documentation/objectivec/1418956-nsobject/1571949-class

But obviously docs are where I start.

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

@AStrangwood What is the main method of that function? Is there a delegate being set? is there an app.Send("run") anywhere?

from macdriver.

progrium avatar progrium commented on May 13, 2024

@asad-awadia what are you trying to accomplish?

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

@progrium I am trying to get the application that is currently in focus/active

func main() {
	delegate := objc.Get("NSWorkspace").Alloc().Init()
	app := delegate.Send("sharedWorkspace") //.Send("activeApplication")
	app.Set("delegate:", delegate)
	fmt.Println(app)
}

this is my code atm and it returns nil

from macdriver.

AStrangwood avatar AStrangwood commented on May 13, 2024

@asad-awadia

The below works for me. Although the docs say "activeApplication " is depreciated and to use "runningApplications" which is what i have been doing in my code.

var NSWorkspace_ = NSWorkspace{objc.Get("NSWorkspace")}

type NSWorkspace struct {
	objc.Object
}

func NSWorkspaceShared() NSWorkspace {
	return NSWorkspace{NSWorkspace_.Send("sharedWorkspace")}
}

func (ws NSWorkspace) ActiveApplication() core.NSDictionary {
	return core.NSDictionary{ws.Send("activeApplication")}
}


func main(){
	workspace := NSWorkspaceShared()
	app := workspace.ActiveApplication()
}

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

shit it works!

thank you so much!

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

how do you know when to use get, send, allc/init??

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

func main() {
	app := objc.Get("NSWorkspace").Send("sharedWorkspace").Send("activeApplication")
	fmt.Println(app)
}

why does this not work? It is the same thing just without the wrapper structs no?

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

how do you even read the values from the returned thing in your above example? :S

from macdriver.

AStrangwood avatar AStrangwood commented on May 13, 2024

@asad-awadia


func main() {
	app := objc.Get("NSWorkspace").Send("sharedWorkspace").Send("activeApplication")
	fmt.Println(app)
}

why does this not work? It is the same thing just without the wrapper structs no?

Tried the code and it worked for me.

how do you know when to use get, send, allc/init??

The best answer to this is do some reading up on Objective-C
get,send will both work in the say way in the above cases. The difference is send allows you to pass on variables to the method you are calling. https://github.com/progrium/macdriver/blob/main/objc/object.go#L121

how do you know when to use get, send, allc/init??

allow/init are used to create a new instance/object of a class.

how do you even read the values from the returned thing in your above example? :S

You will need to implement the methods in NSDictionary first then you can use them.
https://developer.apple.com/documentation/foundation/nsdictionary?language=objc

from macdriver.

progrium avatar progrium commented on May 13, 2024

can somebody clarify if we can close this or what the next actionable thing is?

from macdriver.

asad-awadia avatar asad-awadia commented on May 13, 2024

@progrium it is closed from my end

but the project needs some more documentation

from macdriver.

progrium avatar progrium commented on May 13, 2024

was there something specific in mind or is that a general musing? i also think the project needs some more documentation, but that's not really a step forward.

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.