Skip to content

[swiftgen] Generating bindings for super simple Swift examples #2643

@orestesgaolin

Description

@orestesgaolin

In my attempts to understand swiftgen a bit more I'm trying to play with simple Swift concepts and expose bindings to them in Dart.

Given this simple Swift file

import Foundation
// enum '@objc' enum must declare an integer raw type
@objc enum CompassPoint: Int {
    case north
    case south
    case east
    case west
}

// struct
public struct Person {
    var name: String
    var age: Int
}

// class
@objc public class Dog : NSObject {
    public var name: String
    public var breed: String
    
    public init(name: String, breed: String) {
        self.name = name
        self.breed = breed
    }
}

// function
public func greet(person: Person) -> String {
    return "Hello, \(person.name)!"
}

I'm trying to use current generate_code.dart script to create bindings to Dog, Person, greet() or CompassPoint. I've learned some details from the error messages (e.g. '@objc' enum must declare an integer raw typ) but I'm still not able to generate all the bindings:

  • class Dog is accessible but cannot be initialized, properties are not generated
  • greet is not available
  • Person is not available
  • CompassPoint is not available

Source code:

  • basic_swift.h comes from manual swiftc -c basic_swift.swift -module-name basic_swift -emit-objc-header-path basic_swift.h -emit-library -o libbasicswift.dylib
  • entire sample basic_swift.zip

I verified the Swift code can be run

Image

Is there any way to make this code work with Dart?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions