开发者

NSString is being returned as 'null'

I have this simple method for returning the file path. I am passing the file name as argument. Then when I call this method this method returns 'null' if running on device but works fine on simulator. Is there anything I am doing wrong?

-(NSString*) getFilePathForFile:(NSString*)fileName
{
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   开发者_StackOverflow中文版 NSString *documentsDirectory = [array objectAtIndex:0];
    NSString *temp = [documentsDirectory stringByAppendingPathComponent:fileName];
    return temp;
}

NSString *path = [self getFilePathForFile:@"settingInfo.plist"]

Any help would be appreciated. Thanks


It sounds like some sort of memory management problem. Have you tried to use "Build and Analyze" to see if Xcode can pick up any memory problems?

Otherwise, try this and see if you get something non-null:

NSString *path = [[self getFilePathForFile:@"settingInfo.plist"] retain];


The only way that method can fail and not throw an exception is if the array returned by NSSearchPathForDirectoriesInDomains is nil. Check that a valid array is being returned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜