0

我有以下代码打印更新图像的网址

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)

     }

}

此代码工作正常,但它只会打印第一个修改后的图像 url,但我想要所有修改后的图像 url 列表(修改后的图像数组)请帮助我

4

1 回答 1

1

使用时从集合中选择一个对象url.anyObject()。相反,您需要从集合中获取所有对象,然后遍历数组。以下代码应该可以帮助您:

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)
        }   
    }
}
于 2015-03-16T11:14:09.490 回答