Hi all

Hi all

I'm in the process of pulling the MS AppCenter frameworks into my Firemonkey iOS app and (eventually) managed to link in and build a sample app correctly.

I now need to "register" the framework but struggling to convert the swift code to Delphi. The issue is the need to pass an array of what look like class instances but I can't figure it out. When it converted the headers, it didn't expose a "self" method into the equivalent Delphi class - not sure if that's part of my troubles...

Any help would be appreciated as I'm so close to getting this working!

Swift:

MSAppCenter.start("secret key", withServices:[
MSAnalytics.self,
MSCrashes.self
])

Pascal header:

{ class } procedure start(appSecret: NSString; withServices: NSArray); cdecl;

Comments

  1. Chris Pimlott You can add any object to NSArray, but if the function expects array of classes and you pass array of strings... it is not unexpected that it crashes...

    But few things, regarding objc_getClass and NSClassFromString functions...

    First, you have to pass -ObjC flag to the linker - Project Options -> Delphi Compiler -> Linker

    If you don't do that, all the classes you need might not be linked, and functions trying to find class through reflection will not succeed.

    Next, there is possibility that Swift side of the framework uses alias class name, and that original Objective-C class name is different. If you are trying to find class through Swift name, you will get nil.

    ReplyDelete
  2. Dalija Prasnikar sorry I meant I passed the class into the NSArray (e.g. MSAnalysis) not the name as a string.

    The linker options already pass -ObjC as I needed this to link in the dependant system frameworks used the the MS AppCentre frameworks, but tour thoughts about aliases is an interesting one I’ll investigate.

    Thanks again!

    ReplyDelete
  3. Chris Pimlott Keep us posted.
    If I get any more ideas that could help, I will let you know.

    ReplyDelete

Post a Comment