Foundation.NSLocalizedStringWithDefaultValue

I’m currently working with Applanga’s CTO to make their framework compatible with Xojo.

Applanga offers translation services for iOS and Android apps.

The Applanga framework relies on calls to Foundation. NSLocalizedStringWithDefaultValue to detect localisable strings in the app.

This is my call to NSLocalizedStringWithDefaultValue

Declare Function mainBundle Lib FoundationLib selector "mainBundle" (clsRef As ptr) As ptr

Declare Function NSLocalizedStringWithDefaultValue Lib FoundationLib (key As CFStringRef, _
tableName As CFStringRef, _
bundle As ptr, _
value As CFStringRef, _
comment As CFStringRef) As CFStringRef


  Return NSLocalizedStringWithDefaultValue(key, Nil, mainBundle(NSClassFromString("NSBundle")), value, "")

As soon as the above function is called, the app crashes :

[quote]Termination Reason: DYLD, [0x4] Symbol missing

Application Specific Information:
CoreSimulator 375.20 - Device: iPhone 6 (FR) - Runtime: iOS 10.3 (14E269) - DeviceType: iPhone 6

Dyld Error Message:
Symbol not found: _NSLocalizedStringWithDefaultValue

[…]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 dyld 0x000fafde __abort_with_payload + 10
1 dyld 0x000fab52 abort_with_payload_wrapper_internal + 65
2 dyld 0x000fab9e abort_with_payload + 38
3 dyld_sim 0x001548a8 abort_with_payload + 55
4 dyld_sim 0x0014dc77 dyld::halt(char const*) + 329
5 dyld_sim 0x0014dd02 dyld::bindLazySymbol(mach_header const*, unsigned long*) + 139
6 dyld_sim 0x0015c7de stub_binding_helper_interface2 + 20
7 com.jeremieleroy.applanga 0x00041204 Foundation.LocalizedString%?%yy + 405
[/quote]

Any ideas ?

I’m not sure that’s the right signature. I just looked this up in the apple docs:
https://developer.apple.com/reference/foundation/nslocalizedstringwithdefaultvalue
It seems that the “function” you are trying to use doesn’t really exist without the C header (it’s a compiler define and not an actual function) so you should try the actual selector directly.

Thanks Jason.

Finally this seems to work:

[code]Declare Function mainBundle Lib FoundationLib selector “mainBundle” (clsRef As ptr) As ptr

Declare Function NSLocalizedString Lib FoundationLib selector “localizedStringForKey:value:table:” (bundle As ptr, _
key As CFStringRef, _
value As CFStringRef, _
table as CFStringRef) as CFStringRef

Return NSLocalizedString(mainBundle(NSClassFromString(“NSBundle”)), constName, value, nil)[/code]

Guess I’m confused why you need to declare into this at all ?
Dynamic constants already use this API so using dynamic constants should “just work”