Skip to content

Instantly share code, notes, and snippets.

@jon-davis-xamarin
Last active June 13, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-davis-xamarin/ba9523272432dc79caff to your computer and use it in GitHub Desktop.
Save jon-davis-xamarin/ba9523272432dc79caff to your computer and use it in GitHub Desktop.
NSString localizedStringWithFormat
public static class NSStringExtensions
{
[DllImport(Constants.ObjectiveCLibrary, EntryPoint="objc_msgSend")]
private extern static IntPtr IntPtr_objc_msgSend_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1);
public static NSString LocalizedStringWithFormat (this NSString @string)
{
var nsHandle = IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof(NSString)), Selector.GetHandle ("localizedStringWithFormat:"), @string.Handle);
var nsstring = Runtime.GetNSObject<NSString> (nsHandle);
return nsstring;
}
}
@cfin-mt
Copy link

cfin-mt commented Jun 13, 2016

This isn't yet working for me. My stringsdict is set up as the iOS documentation describes for English plurals. Is there something special I'm supposed to do with the returned NSString to get it's text value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment