title: Creating a custom album on swift (a request is interfering on the process)
body: <p>I have the following code which I got from this forum, and works perfectly. However the first time when it creates the album, requests the user for permission to access his photos. That causes the album doesn't be create until the second time the application is run. </p>
  
  <p>How can I control that?, in order that the album can be created the first time that is requested. Sorry if my english is not good, I only know a little bit. Hope somebody can help me!</p>
  
  <p><strong>Finally here is the code:</strong></p>
  
  <pre><code>import Photos
  var assetCollection: PHAssetCollection!
  var albumFound : Bool = false
  var photosAsset: PHFetchResult!
  var assetThumbnailSize:CGSize!
  var collection: PHAssetCollection!
  var assetCollectionPlaceholder: PHObjectPlaceholder!
  
  func createAlbum() {
  let fetchOptions = PHFetchOptions()
  fetchOptions.predicate = NSPredicate(format: "title = %@", "MyAlbum")
  let collection : PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.Album, subtype: .Any, options: fetchOptions)
  
  if let first_obj: AnyObject = collection.firstObject {
      self.albumFound = true
      assetCollection = collection.firstObject as PHAssetCollection
  } else {
      PHPhotoLibrary.sharedPhotoLibrary().performChanges({
          var createAlbumRequest : PHAssetCollectionChangeRequest = PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle("MyAlbum")
          self.assetCollectionPlaceholder = createAlbumRequest.placeholderForCreatedAssetCollection
          }, completionHandler: { success, error in
              self.albumFound = (success ? true: false)
  
              if (success) {
                  var collectionFetchResult = PHAssetCollection.fetchAssetCollectionsWithLocalIdentifiers([self.assetCollectionPlaceholder.localIdentifier], options: nil)
                  print(collectionFetchResult)
                  assetCollection = collectionFetchResult?.firstObject as PHAssetCollection
              }
      })
  }}
  </code></pre>