I get the error in Alamofire.downloand as below:
Alamofire.download(URLString).responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}else{
print(response.result.error)
}
}
Alamofire.AFError.responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.inputFileReadFailed(file:///private/var/mobile/Containers/Data/Application/40167F58-FF4A-4D19-B01A-F8ED90F794DD/tmp/CFNetworkDownload_1dnNQR.tmp)))
Can anyone help solved it or facing same issues?
Thanks
Change the Alamofire.download to Alamofire.request, it will download. Exact answer for your question, check here
Related
I'm facing weird issue. The print command in following code paints green area in debug window in xCode. It's random.
Why is it happening? How to fix it?
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
DispatchQueue.main.async {
completionHandler(nil, error)
}
return
}
print("############## Data ############################################################")
if let str = String(data: data, encoding: .utf8) { print(str) }
print("################################################################################")
}
The fix turn out to be the same age old trick, reboot the system. macOS has been crashing all day today when I use Xcode.
Restart did not help me.
Making Xcode go to fullscreen made it disappear, and was able to return back to non-fullscreen with it still not green.
Hi guys i am trying to download a bunch of images in my app using the Alamofireimage library. this is the code that i use and it is basically what they have in their documentation:
let downloader = ImageDownloader()
for (img):(ImageData) in imgDownloadList
{
let urlRequestx = img.downloadUrl
downloader.download(urlRequestx){ response in
print(response.request)
print(response.response)
debugPrint(response.result)
if let image = response.result.value {
print(image)
}
}
}
i got the error
Ambiguous reference to member
'download(_:receiptID:filter:progress:progressQueue:completion:)'
did someone face the same problem?
Thanks a lot.
Im using Xcode 8.3 with Swift 3. I have written one method named pdfFromData(data:) to form the pdf document from the Data, whenever I build my project its not getting build due to this method, means the compiler is got stopped/hanged when it start compile particular file where I coded pdfFromData(data:) method(In Xcode 8.2 with Swift 3 it worked fine). Whenever i comment this method and build means everything working fine.
func pdfFromData(data: Data) -> CGPDFDocument? { // Form pdf document from the data.
if let pdfData = data as? CFData {
if let provider = CGDataProvider(data: pdfData) {
let pdfDocument = CGPDFDocument(provider)
return pdfDocument
}
}
return nil
}
What's wrong with this method?. I want to build my project with this method as well. Thanks in advance.
I tried debugging your issue. This is what I found out:
if let pdfData = data as? CFData {
}
The above line for casting object of type Data to CFData is where it's taking too much time to build.
Replacing that with the following piece of code significantly reduces your build time.
let pdfNsData: NSData = NSData(data: data) // convert `Data` to `NSData`
if let cfPdfData: CFData = pdfNsData as? CFData {
// cast `NSData` to `CFData`
}
NSData and CFData are toll-free bridged.
Please let me know if there's any doubt
I'm trying to update the code in my app after the update to XCode 7 and it looks like I'm going to have to go through a serious learning curve again just to catch up. What am I doing wrong in the code below?
Is if let still being used?
I am so not familiar with try/catch outside of C#. I don't know how to use it in the context of swift and it'd be great to find an easy to understand guide that doesn't assume that I ever knew Objective C or have ever come across this before.
Use this instead:
do {
let json = try NSJSONSerialization.JSONObjectWithData(...)
return json
} catch let error as NSError {
print("JSON Error: \(error.localizedDescription)")
}
You are calling a method that throws a Swift error and as such, it needs to be marked with try.
do
{
let json = try NSJSONSerializer.JSONObjectWithData(...)
return json
}
catch
{
// By default the catch clause defines the variable error as whatever ws thrown
print("Error is \(error)")
return nil
}
Is pretty much what you want.
In case of my understanding is
let result: AnyObject? = try! NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.MutableContainers)
I'm having a strange issue. My app works fine in the iPhone 6 emulator, but not in any other emulators or on my iDevice. Here's the main code
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if(error == nil){
let imageObjects = objects as! [PFObject]
if let myObjects = objects {
for object in myObjects {
let myTitle = object["imageName"] as! NSString
println(myTitle)
let thumbNail = object["imageFile"] as! PFFile
// println(thumbNail)
thumbNail.getDataInBackgroundWithBlock({
(imageData: NSData?, error: NSError?) -> Void in
if (error == nil) {
self.imageArray.append(imageData!)
let image = UIImage(data:imageData!)
self.imageView.contentMode = .ScaleAspectFit
self.imageView.image=image
}
})//getDataInBackgroundWithBlock - end
}//for - end
}
}//end of if
else{
println("Error in retrieving \(error)")
}
}//findObjectsInBackgroundWithblock - end
I think this line is the culprit
let image = UIImage(data:imageData!)
But I'm not sure why. "image" returns nil in all other devices except iPhone 6 emulator. Any suggestions would be awesome.
Thanks
NOTE: the image displays just fine in iPhone 6 emulator. I'm using storyboard and unchecked autolayout.
There shouldn't really be a situation where the app only works on one simulator setting. Resetting your simulator should solve the problem.
One possibility is that you previously successfully downloaded this data, and Parse has cached the response in your iPhone app, but you've since changed the PFObject remotely and removed the image data. Or perhaps changed code.
Because Parse.com caches images, it's possible that it works only on this device because of Parse.com caching.
You could use the debugger, or worse, NSLog to determine what is nil. You need to determine if imageData is coming back nil or not. Also, is there a reason why you're assuming imageData is non-null? I'm referring to references to imageData! -- that seems dangerous. Just because there's no error doesn't mean imageData is non-null.