0

This is the problem code:

NSURL *url = [NSURL URLWithString:@"http://photostiubhart.comoj.com/ReadGallery/stiubhart1readgallery.php"];
NSError* error; 
NSString* sizeString = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
double myDouble = [sizeString doubleValue];
int myInt = (int)(myDouble + (myDouble>0 ? 0.5 : -0.5));

//Create an array to hold the URLS
NSMutableArray *myURLS;

//Initialize the array with nil
myURLS = [[NSMutableArray alloc] init];

NSLog(@"Here1");
//Add all the URLs from the server to the array
for (int i = 0; i <= myInt; i++){
    NSString *tempString = [[NSString alloc] initWithFormat : @"http://photostiubhart.comoj.com/GalleryImages/%dstiubhart1.jpg", i];
    [myURLS addObject: [NSURL URLWithString:tempString]];
    [tempString release];
}

myPhotos = [[NSMutableArray alloc] init];

for(int i = 0; i < myInt; i++){
    [myPhotos addObject:[myURLS objectAtIndex:i]];
}

It gives the error:

2011-06-21 22:20:47.167 CHARLIE[666:207] -[NSURL length]: unrecognized selector sent to instance 0x70418c0

This is what the code does (at least supposed to):

  1. Generate an integer from the contents of the URL ("4").
  2. Use the integer in the for loops to add objects to arrays.

Can anyone tell me whats wrong here?

Thanks a lot,

Jack

3
  • That error isn't being produced by the code you've posted - it means that at some point, you send the length message to an NSURL object. There are no calls to length in your code. Can you post more about the error, or more of your code in this context? Commented Jun 21, 2011 at 21:37
  • is there some other code where you are asking for the NSURLs length? Commented Jun 21, 2011 at 21:38
  • is a negative value expected on myDouble? the loops are testing slightly different conditions. it looks like you just want myPhotos = [NSMutableArray arrayWithArray:myURLS]. can you determine which line is giving you that error? (it's indicative of over released objects or inappropriate casting) Commented Jun 21, 2011 at 21:45

1 Answer 1

2

If you want to add URLs as strings then shouldn't this –

for (int i = 0; i <= myInt; i++){
    NSString *tempString = [[NSString alloc] initWithFormat : @"http://photostiubhart.comoj.com/GalleryImages/%dstiubhart1.jpg", i];
    [myURLS addObject: [NSURL URLWithString:tempString]];
    [tempString release];
}

be –

for (int i = 0; i <= myInt; i++){
    NSString *tempString = [NSString stringWithFormat:@"http://photostiubhart.comoj.com/GalleryImages/%dstiubhart1.jpg", i];
    [myURLS addObject:tempString];
}

You're probably expecting them to be strings and later calling length method on them whereas they are stored as URLs in the array.

Additionally, myPhotos seems to be a property in which case you can substitute -

myPhotos = [[NSMutableArray alloc] init];

for(int i = 0; i < myInt; i++){
    [myPhotos addObject:[myURLS objectAtIndex:i]];
}

with this -

self.myPhotos = myURLS;
[myURLS release]; // To balance out the earlier alloc-init
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.