Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:38:07+00:00 2026-05-17T15:38:07+00:00

I have an iPhone iOS4.1 application that uses localized strings. I have just started

  • 0

I have an iPhone iOS4.1 application that uses localized strings. I have just started building unit tests using the SenTestingKit. I have been able to successfully test many different types of values.

I am unable to correctly test any of my code that uses NSLocalizedString calls, because when the code runs in my LogicTests target, all of my NSLocalizedString calls only return the string key.

I have added my Localizable.strings file to the LogicTests target.

My question is: How must I configure my LogicTests target so that calls to NSLocalizedString will return the localized string and not the string key.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:38:07+00:00Added an answer on May 17, 2026 at 3:38 pm

    This problem was driving me crazy, but I was able to get NSLocalizedString to behave.

    zoul was right, if you print the mainBundle to the console in a logic test, it’s not the same bundle that contains your Localizable.strings file. You need to conditionally redefine NSLocalizedString whenever you run your unit tests. I did it in the following steps:

    1. We need a way to tell when we’re in our logic tests target, so add something like LOGIC_TESTS to your logic tests target’s Preprocessor Macros build setting.
    2. There’s only 1 place in my code where I need to redefine NSLocalizedString, so I was able to place the following code in the header corresponding to that class. If you’re having this problem in multiple places, I’d suggest putting the following code in a header and #include-ing it where you need it (I tried using a .pch file but it doesn’t work in Logic Tests). Anyway, place this somewhere in the header of class(es) that use NSLocalizedString:

      #ifdef LOGIC_TESTS
      #undef NSLocalizedString
      #define NSLocalizedString(key, comment) [[NSBundle bundleWithIdentifier:@"YOUR_IDENTIFIER"] localizedStringForKey:(key) value:@"" table:nil]
      #endif
      

    Replace YOUR_IDENTIFIER with the Bundle Identifier of your app’s bundle (found in your Info.plist file, key is CFBundleIdentifier). This assumes that you’ve defined LOGIC_TESTS as a preprocessor macro only in your Logic Tests target.

    edit: Curiously, once I removed some debugging code this solution stopped working. It looks like you have to trick Xcode into loading the bundle as well. The following does it:

    NSString *path = @"path_to_main_bundle";
    NSBundle *bundle = [NSBundle bundleWithPath:path];
    NSLog(@"bundles: %@", [NSBundle allBundles]);
    

    Where path_to_main_bundle is == [[NSBundle mainBundle] bundlePath] when you run your main target. Just log it once in gdb or using NSLog on your app delegate to grab the path. It should look something like /Users/YOUR_USER_NAME/Library/Application Support/iPhone Simulator/4.1/Applications/UUID_LOTS_OF_LETTERS_AND_NUMBERS_HERE/App.app.

    I placed that code in the setUp call for one of my logic test classes. And no, I have no idea why I have to log allBundles to make it work, so anyone who has a clue, please let me know!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone application with a settings.bundle that handles various settings for my
I have found a crash in an iPhone application with target iOS 4 that
I currently have an iPhone application that makes a call to an API to
I have an iPhone app that hides the status bar. However, my main view
I have an iPhone app that compiles and runs fine in the Simulator on
I have a simple iphone app that's based on the CrashLanding sample app. So
I have an application that has been running fine since its launch over a
I'm using CoreData (with SQLite as the store) in an iOS 4 iPhone application
Currently, I have an iPhone app published in AppStore. I've developed it using XCode
I am writing an application that uses UIImagePickerController to take multiple pictures with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.