iosswiftrncryptor

kRNCryptorAES256Settings referenced error


I am trying to use RNCryptor in my app to do some data encryption.

Look at the code below:

 var encryptedData: NSData = RNEncryptor.encryptData(data, withSettings:kRNCryptorAES256Settings, password: aPassword, error: nil)

Undefined symbols for architecture i386:
"_kRNCryptorAES256Settings", referenced from: __TFC8UtraceUI24ChatBubbleViewController21textFieldShouldReturnfS0_FCSo11UITextFieldSb in ChatBubbleViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am not sure why does it try to look for the constant name with an underscore; ideally it should have tried to look for kRNCryptorAES256Settings which is their in the bridgesupport and other header files.

Any clue what might be going wrong ?

Thanks !


Solution

  • Swift cannot deal with C Structs, which is what kRNCryptorAES256Settings is. This issue has nothing to do with the architecture of the devices.

    So to go around that, I created my own method in RNEcryptor with the sole reason to abstract the need of the C struct.

    + (NSData *)EncryptDataForSwift:(NSData *)data password:(NSString *)password error:(NSError **)error
    {
        return [RNEncryptor encryptData:data withSettings:kRNCryptorAES256Settings password:password error:error];
    }
    

    I am not sure whether it good idea or not, but this makes my project compilable, as I can call my method via Swift without needing to reference any C-only code:

    var encryptedData:NSData = RNEncryptor.EncryptDataForSwift(data, password: Password, error: nil)
    

    Hope this will help someone.