Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1029335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:31:43+00:00 2026-05-16T12:31:43+00:00

I’m really desperate on this one. I’m trying to make a Framework which you

  • 0

I’m really desperate on this one. I’m trying to make a Framework which you can search and play YouTube videos with. But while testing it, I’m running in to a big problem.

In the search operation I’m adding YTVideos (a subclass of NSObject) to a NSMutableArray. When I loop thru it in the main(), I’m getting nil-objects:

Method

- (NSArray *)videosInRange:(NSRange)range {
 if(range.length > 50) {
  [NSException raise:@"Range lenth > 50"
     format:@"The range of -videosInRange: can't be bigger than 50"];
  return nil;
 }

 if((range.location + range.length) > 999) {
  [NSException raise:@"Range to big" 
     format:@"The given range was to big (%d, %d)", range.location, range.length];
  return nil;
 }

 NSString *searchURLString = [[self feedURL] absoluteString];
 searchURLString = [searchURLString stringBySettingURLAttribute:@"start-index" value:[NSString stringWithFormat:@"%d",range.location + 1]];
 searchURLString = [searchURLString stringBySettingURLAttribute:@"max-results" value:[NSString stringWithFormat:@"%d",range.length]];

 NSLog(@"%@",searchURLString);
 NSURL *url = [NSURL URLWithString:searchURLString];
 NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:url 
                 options:0
                   error:NULL];
 if(!xmlDoc)
  return nil;

 NSArray *videoElements = [[xmlDoc rootElement] elementsForName:@"entry"];
 NSMutableArray *videos = [[NSMutableArray alloc] initWithCapacity:[videoElements count]];
 register int i;
 for(i = 0; i < [videoElements count]; i++) {
  NSAutoreleasePool *addPool = [[NSAutoreleasePool alloc] init];

  YTVideo *vid = [[YTVideo alloc] initWithXMLElement:[videoElements objectAtIndex:i]];
  [videos addObject:vid];
  [vid release];

  [addPool drain];
 }

 NSArray *retValue = [NSArray arrayWithArray:videos];
 [videos release];
 return retValue;
}

main()

int main(int argc, const char *argv[]) {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

 YTSearchFeed *feed = [[YTSearchFeed alloc] initWithSearch:@"Eminem"];
 long long results = [feed videoCount];
 NSLog(@"%lld videos for search", results);

 long long i = 0;
 while(results != 0) {
  int length = (results >= 50) ? (50) : (results);

  NSArray *videos = [feed videosInRange:NSMakeRange(i, length)];
  NSLog(@"L: %d", [videos count]);
  int z;
  for(z = 0; z < [videos count]; z++, i++) {
   YTVideo *vid = [videos objectAtIndex:z];
   NSString *title = [vid title];
   NSLog(@"%d: %@", i+1, title);
  }

  results -= length;
 }

 [pool drain];

 return NSApplicationMain(argc, argv);
}

I hope someone can take the time to look at this, and if you need anymore information, just ask.

Thank you in advance,
ief2

EDIT: YTVideo

- (id)initWithXMLElement:(NSXMLElement *)element {
    self = [super init];
    if(self != nil) {
        _XMLElement = [element copy];
    }
    return self;
}

- (NSString *)title {
    if(!_title) {
        NSString *str = [[[self XMLElement] firstElementWithName:@"title"] stringValue];
        _title = [[str stringByDecodingHTMLEntities] retain];
    }

    return [[_title copy] autorelease];
}

I get the title (and other video information) only when it’s requested. the -stringByDecodingHTMLEntities works fine (Category on NSString).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:31:43+00:00Added an answer on May 16, 2026 at 12:31 pm

    I’ve rewritten the code and initialized all instance variables in the -initmethod

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.