how to pass array to NSNotification in swift

1.4k Views Asked by At

i have the following code which print the url of updated image

override func viewWillAppear(animated: Bool) {
  NSNotificationCenter.defaultCenter().addObserver(self, selector: "assetChange:", name: ALAssetsLibraryChangedNotification, object: nil) }


func assetChange(notification: NSNotification){

  if var info:NSDictionary = notification.userInfo { var url:NSSet = info.objectForKey(ALAssetLibraryUpdatedAssetsKey) as NSSet
      var aurl:NSURL = url.anyObject() as NSURL
        println(aurl)

     }

}

this code work fine but it will print only first modified image url,but i want all the list of modified image url(array of modified images) please help me

1

There are 1 best solutions below

0
Elliott Minns On BEST ANSWER

You're choosing one object from the set when using url.anyObject(). Instead you need to get all objects from the set and then iterate through the array. The following code should help you:

func assetChange(notification: NSNotification) {

    if var info:NSDictionary = notification.userInfo { var url:NSSet = info.objectForKey(ALAssetLibraryUpdatedAssetsKey) as NSSet
        var urls: [NSURL] = url.allObjects as [NSURL]
        for singleUrl in urls {
            println(singleUrl)
        }   
    }
}