0

The plist has the file suffix .xml and is a normal array of dictionaries.

In the app delegate:

#define docDir [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

-(NSString *)cacheFile:(NSString *)filename sitepath:(NSString *)url {
    NSMutableString *retfn=[NSMutableString string];
    NSString *mediaUrl=[NSString stringWithFormat:@"%@%@",url,filename];
    if(nil != mediaUrl){
        NSData* imageData;
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
        @try {
            imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
        }
        @catch (NSException * e) {  //error
            NSLog(@"%@",@"CacheFile error!");
        }
        @finally {  //save to Documents
            [retfn appendFormat:@"%@%@%@",docDir,@"/",filename];
            [imageData writeToFile:retfn atomically:YES];
        }
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [imageData release];
    }
    return retfn;
}

In my tableView controller:

#define fname @"myplist.xml"
#define fdir @"http://mysite.com/iPhoneApp/"

- (void)viewDidLoad {
    appdel=(EksjoHusAppDelegate *) [[UIApplication sharedApplication] delegate];
    NSString *husDataF=[appdel cacheFile:fname sitepath:fdir];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:husDataF];

    if (([husDataF length]>0)&&(fileExists)) {
        NSMutableArray *lochusData=[[NSMutableArray alloc] initWithContentsOfFile:husDataF];
        appdel.husData=lochusData;
        [lochusData release];
    }   
}

initWithContentsOfFile sets lochusData to 0x0. This the part of code I'm asking about, really. The rest is more for completion. cacheFile returns the local filepath or an empty string. All the values are correct, but it just won't load / go into the array.

Feeling dumb. I just don't see the error. Is there something I'm missing?

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
  • The code is correct, the problem was with Content-Type/Character Set. The script that generated the file saved it on the server with the wrong attributes. Still won't validate, but works. – Henrik Erlandsson Oct 07 '10 at 14:17

1 Answers1

0

Answer was, "Check your charset when saving the generated XML, dude" :)

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63