jeudi 26 mars 2015

Checking property of images crashing in swift

I used this function to scan all photos from the Camera Album in iPhone/ iPad. I don't know why, for me it was crashing all the time. I really don't have any idea about where it is crashing in this function, . Sometimes it worked fine, when I changed iCloud Photo Stream to ON/OFF in Settings in iPhone/IPad. I have no idea why this happens.


This is the function which I wrote. I am passing array of PHAssets into this function.



func gettingSize(from array : NSMutableArray)
{
func enumerateAllImages(imageArray : NSMutableArray, completion : ((ArrayPassed : NSMutableArray) -> Void)?)
{

// Performing progressView addition

var TempArray : NSMutableArray = NSMutableArray()

var options : PHImageRequestOptions = PHImageRequestOptions()
options.synchronous = true
options.networkAccessAllowed = false // to skip download image from iCloud

let imageManager : PHImageManager = PHImageManager()

for index in 0...(imageArray.count - 1)
{
var ID = imageManager.requestImageDataForAsset( imageArray[index] as PHAsset, options: options, resultHandler:
{
data,stringValue,orientation,object in

var value : NSString = stringValue

if (value as NSString).containsString(".png")
{
if let isIniCloud = object as NSDictionary?
{
var isIniCloudDICT : NSDictionary = isIniCloud

if let integerCloudValue = isIniCloudDICT.valueForKeyPath(PHImageResultIsInCloudKey) as? Int
{

if integerCloudValue == 0
{
if index == (imageArray.count - 1)
{
self.tempImageSize = self.tempImageSize + data.length
TempArray.addObject(imageArray[index])
self.increasingTheValue()
completion!(ArrayPassed: TempArray)
}
else
{
self.tempImageSize = self.tempImageSize + data.length
TempArray.addObject(imageArray[index])
}

} // Checking condition for integerValueCloud
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}

} // Is in iCloud Optional checking
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}

} // Is in iCloud NSDictionary optional checking
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}
}
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}
}) // Image Manager
} // For loop
} // Nested Function

enumerateAllImages( array, { ArrayPassed in

if ArrayPassed.count == 0
{
dispatch_async(dispatch_get_main_queue(), {

self.progressView.progress = 0
self.tempProgress = 0
self.increasingTheValue()
})
}
else
{
self.Array = ArrayPassed
}
})
}


Does anybody knows why this happens, when I run it, it crashes? Crahes on this line



var value : NSString = stringValue


Multiple times, no idea why this happens.?




Aucun commentaire:

Enregistrer un commentaire