Code Monkey home page Code Monkey logo

go-mobile-collection's Introduction

go-mobile-collection

Note: I threw this together very quickly to solve a simple problem, so its design/interfaces are hardly thought out. But it should provide a good example for how to generate collection wrappers that work with go mobile until there is support for that.

This is a quick utility I adapted from another git project by Brett Slatkin see article here: http://www.onebigfluke.com/2014/12/generic-programming-go-generate.html

The reason for this is that go mobile doesn't currently support slices. So a current work around is to wrap a go slice with another type and expose methods that operate on that slice. So a wrapper may have methods like push, pop, insert, count, etc for modifying or reading from the array.

Usage

What this repo does is build a command line utility that can then be automatically called using go generate semantics.

  • Find the file you that contains the struct definition you want to have a collection wrapper for.
  • At the top of the file add the following: //go:generate go-mobile-collection $GOFILE
  • Before the struct, add a comment to flag it:
// @collection-wrapper
type Example struct {
 ExampleField string
}
  • When you build your project a new file should now be generated called ($GOFILE)_collection.go that contains the automatically generated definitions.

go-mobile-collection's People

Contributors

scisci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-mobile-collection's Issues

Produces collection wrapper but fail on bind.

Hi @scisci - Tried the generator utility and got the file produced. But just ran into trouble while running

go mobile bind -target=ios

as it failed. I was looking forward to get the collection of 'person' available for ObjC. Am I doing anything wrong ? Any thoughts?

Attached are the files (a simple struct and an export function) and below is the stack trace.

gomobile: darwin-armv7: go build -p=8 -pkgdir=/Users/bob/gowork/pkg/gomobile/pkg_darwin_arm -tags="" -buildmode=c-archive -tags=ios -o /var/folders/_w/kb0xmwm51hg3gvtbcc3sz74xbk9c3p/T/gomobile-work-962964218/CollectionManager-arm.a /var/folders/_w/kb0xmwm51hg3gvtbcc3sz74xbk9c3p/T/gomobile-work-962964218/src/iosbin/main.go failed: exit status 2
# _/var/folders/_w/kb0xmwm51hg3gvtbcc3sz74xbk9c3p/T/gomobile-work-962964218/src/go_CollectionManager
/var/folders/_w/kb0xmwm51hg3gvtbcc3sz74xbk9c3p/T/gomobile-work-962964218/src/go_CollectionManager/go_CollectionManagermain.go:8: imported and not used: "golang.org/x/mobile/bind/seq"
/var/folders/_w/kb0xmwm51hg3gvtbcc3sz74xbk9c3p/T/gomobile-work-962964218/src/go_CollectionManager/go_CollectionManagermain.go:9: imported and not used: "research.com/CollectionPOC" as CollectionManager

gocodefiles.zip

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.