Skip to content

objc: Send[[]objc.ID] should automatically convert NSArray returns to Go slices #410

@tmc

Description

@tmc

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • Android
  • iOS

What feature would you like to be added?

objc.Send[[]objc.ID](obj, sel) should return a []objc.ID when the Objective-C method returns NSArray*. Currently it panics with "purego: unsupported return kind: slice".

Why is this needed?

Many Foundation APIs return NSArray* (NSProcessInfo.arguments, NSDictionary.allKeys, NSString.componentsSeparatedByString:, etc.). Today you have to manually iterate:

array := obj.Send(sel)
count := objc.Send[uint](array, sel_count)
result := make([]objc.ID, count)
for i := uint(0); i < count; i++ {
    result[i] = objc.Send[objc.ID](array, sel_objectAtIndex, i)
}

The natural Go spelling should just work:

args := objc.Send[[]objc.ID](processInfo, sel_arguments)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions