Coder Social home page Coder Social logo

Comments (3)

rhx avatar rhx commented on August 25, 2024 1

You are on the right track with TypedListRef. However, TypeList* is for primitive types (such as CInt), but your list is tracking a reference to another GTK object (a TreePath), what you probably want here is something along the following lines:

myIconView.onSelectionChanged { (unownedSelf: IconViewRef) in
    print ("Change in selection")

    if let selectedItems = unownedSelf.selectedItems {

        let typedSelectedItems = ReferenceListRef<TreePathRef>(selectedItems)

        print ("Before the loop")

        for path in typedSelectedItems {
        
            print("Inside the loop")
            
            // (More code here...)
        }
    }
}

Could you let me know if this works for you?

from swiftglib.

jasaldivara avatar jasaldivara commented on August 25, 2024

The reason why I'm using a Glib.ListRef is because I'm on Gtk3, iterating over the selectedItems of an IconView, and the getSelectedRows() of a GtkTreeSelection. Both of them return a ListRef representing a list of TreePath objects.

After some digging on the latest commits, I found out Glib.ListRef was replaced with a typed variant: TypedListRef. ListRef still exists as generated code, but it does not longer conform to the Sequence protocol, while the new one TypedListRef does conform to the protocol.

After that, now I'm using IconView.selectedItems: ListRef to create a TypedListRef<TreePath>. This is how my code looks now:

myIconView.onSelectionChanged { (unownedSelf: IconViewRef) in
    print ("Change in selection")

    if let selectedItems = unownedSelf.selectedItems {

        let typedSelectedItems = TypedListRef<TreePath>(selectedItems)

        print ("Before the loop")

        for path in typedSelectedItems {
        
            print("Inside the loop")
            
            // (More code here...)
        }
    }
}

Now, my code compiles correctly, without any error messages, but I'm having a new problem: The program crashes when i'm iterating over the TypedListRef:

Change in selection
Before the loop
fish: Job 1, 'swift run MySwiftProgram' terminated by signal SIGSEGV (Address boundary error)

I think the crash happens in the for path in typedSelectedItems { line, because the previous message is printed to the terminal, but the inside print statement does not get executed.

from swiftglib.

jasaldivara avatar jasaldivara commented on August 25, 2024

Yes, using ReferenceListRef<TreePathRef> instead of TypedListRef<TreePath> solved my problem.

Thanks!

from swiftglib.

Related Issues (5)

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.