0

Hey guys, I'm receiving a SIGABRT when trying to use an instance variable for anything but an NSLOG :

//Class_X.H
@interface MeldingController : UIViewController 
{   
    NSString *refURLAsString;
}
@property (nonatomic, retain) NSString *refURLAsString;

//Class_X.M
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.refURLAsString = [info objectForKey:UIImagePickerControllerReferenceURL];
    NSLog(@"%@",self.refURLAsString);//Successfully outputs the ReferenceURL string
}

-(void)function_abc
{
    NSLog(@"%@",self.refURLAsString);//Successfully outputs the ReferenceURL string
    NSURL *URL = [NSURL URLWithString:self.refURLAsString]; //SIGABRT
    //Or even trying to make another string using refUrlAsString 
    NSString *string = [[NSString alloc]init];
    string = self.refURLAsString;//SIGABRT
}

iPhone Simulator iOS version 4.3, Xcode 4.

Any ideas anyone? cheers.

Uxxish
  • 115
  • 1
  • 9

5 Answers5

3

Your refURLAsString is of type NSString *, but [info objectForKey:UIImagePickerControllerReferenceURL] should return a NSURL * instance according to the docs. You want:

self.refURLAsString = [[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];

The reason why the NSLog works is because it calls the description method on each object that is to be printed via the %@ sequence, and that does return a string. But refURLAsString is pointing to a NSURL instead of a NSString, and that makes [NSURL URLWithString:self.refURLAsString]; crash.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
0

try this

string =[refURLAsString copy];
nambi
  • 547
  • 3
  • 10
0

Your code is screwing up refURLAsString. I can't tell you how from the posted code. Activate NSZombieEnabled for details.

Community
  • 1
  • 1
Jano
  • 62,815
  • 21
  • 164
  • 192
0

Not sure exactly whats the issue is, but try string = [NSString stringWithFormat:@"%@",self.refURLAsString]; and see if it crashes here too

Nithin
  • 6,435
  • 5
  • 43
  • 56
0

NSString *string = [NSString stringWithFormat:@"%@",self.refURLAsString];

no need to alloc here