title: iCloud Error "The operation couldn't be completed. (LibrarianErrorDoman error 10 - Unable to configure the collection.)"
body: <p>i want to migrate my existing app to iCloud.</p>
  
  <p>in my attempt to learn what to do, i have tried a sample app that has worked as described in the demo (as seen in lecture 17 of the iTunes stanford university course).</p>
  
  <p>can someone who has had this problem help me diagnose what step i messed up to cause the following to fail?  is this just telling me basically that there's no data to query?  or is there something else going on that i haven't properly configured?</p>
  
  <p>i am getting the following in my console (which occurs in the code below immediately after i call <code>[self.iCloudQuery startQuery];</code></p>
  
  <pre><code>item update error: 0, Error Domain=LibrarianErrorDomain Code=10 "The operation couldn‚Äôt be completed.
  (LibrarianErrorDomain error 10 - Unable to configure the collection.)" UserInfo=0x11ee00 {NSDescription=Unable to
  configure the collection.}
  </code></pre>
  
  <p>i created a development provisioning profile that has iCloud turned on on iTunes connect.</p>
  
  <p>i turned on entitlements.  here are the contents:</p>
  
  <p><img src="https://i.stack.imgur.com/vf1Cz.png" alt="enter image description here"></p>
  
  <p>the code is straight from the Stanford University iTunes lectures:  </p>
  
  <pre><code>#import "DocumentViewController.h"
  
  @interface DocumentViewController ()
  @property (strong, nonatomic) NSArray* documents; // of NSURLs
  @property (strong, nonatomic) NSMetadataQuery* iCloudQuery;
  @end
  
  @implementation DocumentViewController
  @synthesize documents = _documents;
  @synthesize iCloudQuery = _iCloudQuery;
  
  - (void)setDocuments:(NSArray*)documents {
      // always sort documents alphabetically
      documents
        = [documents sortedArrayUsingComparator:^NSComparisonResult(NSURL* url1, NSURL* url2) {
              return [[url1 lastPathComponent] caseInsensitiveCompare:[url2 lastPathComponent]];
          }];
      if (![documents isEqualToArray:_documents])
      {
          _documents = documents;
          [self.tableView reloadData];
      }
  }
  
  - (NSMetadataQuery*)iCloudQuery {
      if (!_iCloudQuery)
      {
          _iCloudQuery = [[NSMetadataQuery alloc] init];
          _iCloudQuery.searchScopes
            = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope];
          _iCloudQuery.predicate
            = [NSPredicate predicateWithFormat:@"%K like '*'", NSMetadataItemFSNameKey];
          [[NSNotificationCenter defaultCenter] addObserver:self
                                                   selector:@selector(processCloudQueryResults:)
                                                       name:NSMetadataQueryDidFinishGatheringNotification
                                                     object:_iCloudQuery];
          [[NSNotificationCenter defaultCenter] addObserver:self
                                                   selector:@selector(processCloudQueryResults:)
                                                       name:NSMetadataQueryDidUpdateNotification
                                                     object:_iCloudQuery];
      }
      return _iCloudQuery;
  }
  
  #pragma mark - private implementation
  
  - (NSURL*)iCloudURL {
      return [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
  }
  
  - (NSURL*)iCloudDocumentsURL {
      return [self.iCloudURL URLByAppendingPathComponent:@"Documents"];
  }
  
  - (NSURL*)filePackageURLForCloudURL:(NSURL*)url
  {
      if ([url.path hasPrefix:self.iCloudDocumentsURL.path])
      {
          NSArray* iCloudDocumentsURLComponents = self.iCloudDocumentsURL.pathComponents;
          NSArray* urlComponents = url.pathComponents;
          if (iCloudDocumentsURLComponents.count &lt; urlComponents.count)
          {
              NSRange newRange = NSMakeRange(0, iCloudDocumentsURLComponents.count+1);
              urlComponents = [urlComponents subarrayWithRange:newRange];
              url = [NSURL fileURLWithPathComponents:urlComponents];
          }
      }
      return url;
  }
  
  - (void)processCloudQueryResults:(NSNotification*)notification
  {
      [self.iCloudQuery disableUpdates];
      NSMutableArray* documents = [NSMutableArray array];
      NSUInteger resultCount = self.iCloudQuery.resultCount;
      for (NSUInteger i = 0; i &lt; resultCount ; ++i)
      {
          NSMetadataItem* item = [self.iCloudQuery resultAtIndex:i];
          NSURL* url = [item valueForAttribute:NSMetadataItemURLKey];
          url = [self filePackageURLForCloudURL:url];
          [documents addObject:url];
      }
      self.documents = documents;
      [self.iCloudQuery enableUpdates];
  }
  
  #pragma mark - overrides
  
  - (void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:animated];
      if (![self.iCloudQuery isStarted])
          [self.iCloudQuery startQuery];
      [self.iCloudQuery enableUpdates];
  }
  
  - (void)viewWillDisappear:(BOOL)animated {
      [self.iCloudQuery disableUpdates];
      [super viewWillDisappear:animated];
  }
  </code></pre>