pathForResource is not working...?

Discussion in 'iOS Programming' started by detz, Oct 14, 2008.

  1. detz macrumors 65816

    Joined:
    Jun 29, 2007
    #1
    NSString *resource = [[NSBundle mainBundle] pathForResource:mad:"test" ofType:mad:"txt"];
    NSString *content = [NSString stringWithContentsOfFile:resource];

    there is a test.txt file in my Resource directory but both of these values are nil. Any ideas?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Are you 100% sure it's called "test.txt" not "Test.txt" or "test.TXT" for example?
     
  3. lawicko macrumors member

    Joined:
    Jul 17, 2008
    #3
    I notice that sometimes there is a problem if you release the path to the resource to early, so try not to release resource string before you actually use content object.
     
  4. detz thread starter macrumors 65816

    Joined:
    Jun 29, 2007
    #4
    Weird, I tried everything and the only thing that worked was deleting the txt file and re-creating it. Maybe there was an encoding issue or something.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    NSString stringWithContentsOfFile: is deprecated and there's no reason that you should use it. Use stringWithContentsOfFile:encoding:error:
     

Share This Page