Giter Club home page Giter Club logo

Comments (6)

tomball avatar tomball commented on August 16, 2024

Mapping files are now documented, and can be used to define Objective-C method names as desired. We'll still pursue adding support for method name annotations.

from j2objc.

tomball avatar tomball commented on August 16, 2024

From nbransby on the old issue tracker:

Was the ObjectiveCName annotation added for methods or only classes? I think being able to give friendlier names to exposed methods that are designed to be called from objective c code is really important despite the risk of selector clash.

Just as important I feel is the translation of arguments to their native types when the annotation is used. In other words not exposing any of the 'javaness' to the client of the translated code. I believe if you can wrap up your cross platform library in a familiar coating for iOS developers it will decrease the suspicion around using such a libary.

Just class names right now, but now that I verified that method name mapping works correctly, adding support for methods should be much easier than starting from scratch.

I'm not sure what you mean by "native types," but the types are copied verbatim from a method mapping (including typos!).

from j2objc.

nbransby avatar nbransby commented on August 16, 2024

By native types I mean converting any emulated classes to their native counterparts, e.g IosObjectArray to NSArray (in fact this maybe the only instance of this)

from j2objc.

tomball avatar tomball commented on August 16, 2024

We first tried mapping Java arrays to NSArray, but found that they differ in several critical ways. Java arrays are mutable but fixed size, while NSArray is immutable and NSMutableArray's size changes. NSArray also cannot have nil elements, while Java arrays do (and Java developers expect).

It's easy to convert between NSArray and IOSObjectArray, though. To convert from an NSArray to IOSObjectArray:

NSArray *nsArray = [NSArray arrayWithObjects: @"one", @"two", @"three", nil];
IOSObjectArray *javaArray =
    [IOSObjectArray *arrayWithNSArray:nsArray type:[IOSClass stringClass]];

To convert from an IOSObjectArray to NSArray (if javaArray doesn't have any nil elements):

NSArray *newArray = [NSArray arrayWithObjects:javaArray->buffer_
                                        count:[javaArray size]];

If you want a visible API that only uses NSArrays, you'll need to write a wrapper with the above converters.

from j2objc.

tomball avatar tomball commented on August 16, 2024

Methods and constructors are now supported for the @ObjectiveCName annotation. This allows developers to rename a method to whatever selector looks best (as long as it is unique in the class). The translator will warn if an attempt is made to rename an overridden method if that super-method doesn't have the same annotation value, and will then ignore that annotation so as to not break polymorphism.

from j2objc.

tomball avatar tomball commented on August 16, 2024

Since issues are filed for specific problems with method mapping (64, 359, 378, and 389), I'm closing this general issue in favor of j2objc-discuss discussions.

from j2objc.

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.