0

I'm trying to import Agent Geometry Kit (https://github.com/hfossli/AGGeometryKit) which is written in Objective-C into a Swift project.

I start by copying all the source files into my project, then I create a bridge header file in which I import all the header files I just added (which looks like this https://gist.github.com/JeanCParis/97dc6c27c70a4f00dbb0)

My problem is that although all the imported classes and structs are now available in my project, unions like AGKQuad are not.

Am I doing something wrong, or are unions not usable in Swift and if so how can I best bypass this problem ? Many thanks in advance !

Jean-Christophe

EDIT : I'm still a neophyte in developing on IOS, but can't I just make a Objective-C class which I can call from my Swift project to "do the job" and send me the result I'm looking for ? I tried to do just that and it unfortunately does not give me the expected result, although it might be that I don't yet fully understanding how Agent Geometry Kit works (what the method does comes from the readme file on github)

@implementation DoTheJob

- (UIImageView*)DoDaJob:(UIImage*)image {

    UIImageView *view = [[UIImageView alloc] initWithImage:image];
    [view.layer ensureAnchorPointIsSetToZero]; // set the anchor point to [0, 0] (this method keeps the same position)

    AGKQuad quad = view.layer.quadrilateral;
    quad.br.x += 600; // shift bottom right x-value with 20 pixels
    quad.br.y += 500; // shift bottom right y-value with 50 pixels

    view.layer.quadrilateral = quad; // the quad is converted to CATransform3D and applied
    printf("DoingDaJob");
    return view;
}

@end

Should this work in principle ?

  • It seems that C unions are not supported, compare http://stackoverflow.com/questions/24622475/using-glkmath-from-glkit-in-swift. – Martin R Aug 20 '14 at 08:19
  • I was wondering if it was supported in the meantime or if a working solution existed. I'll wait a little longer before closing this question, in the hope someone can help me. Thanks ! – Pâris Jean-christophe Aug 20 '14 at 09:41
  • There is currently a pull request regarding this https://github.com/hfossli/AGGeometryKit/pull/20 . I am looking into this today. – hfossli Aug 26 '14 at 09:50
  • Questions like this is better to ask on the issues page on github https://github.com/hfossli/AGGeometryKit/issues – hfossli Aug 26 '14 at 09:51
  • See swift branch https://github.com/hfossli/AGGeometryKit/tree/swift – hfossli Aug 26 '14 at 14:47

1 Answers1

0

C unions are apparently not supported (yet).

The code I posted in my edited question works just fine, even though it might not be the optimal solution, I was simply misunderstanding how this library works.