nserror

iOS Swift : Error Domain=NSOSStatusErrorDomain Code=-12792?

╄→гoц情女王★ 提交于 2019-12-06 05:29:54
I'm trying to get video thumbnails with the following code: let asset = AVAsset(URL: url) let imageGenerator = AVAssetImageGenerator(asset: asset) imageGenerator.appliesPreferredTrackTransform = true do { let cgImage = try imgGenerator.copyCGImageAtTime(CMTimeMake(1, 30), actualTime: nil) let uiImage = UIImage(CGImage: cgImage) imageview.image = uiImage } catch let error as NSError { print("Image generation failed with error \(error)") } Sometimes it works and sometime it doesn't showing the following error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed

How to handle NSData and return UIImage (Swift)

和自甴很熟 提交于 2019-12-06 00:28:57
I am trying to retrieve an image from a URL from a backendless database & convert this into an image, and return the function with a UIImageView. How do I handle a NSError in this code, and still return the UIImageView? func getImage() -> UIView { let imageLink = backendless.userService.currentUser.getProperty("Avatar") let URL = NSURL(string: imageLink as! String) let data = NSData(contentsOfURL: URL!) let image: UIImage! image = UIImage(data: data!) return UIImageView(image: image!) } Updated my answer based on the comments. You can return a placeholder image if the one you are looking for

Best way to handle errors from async closures in Swift 2?

◇◆丶佛笑我妖孽 提交于 2019-12-05 11:13:08
I'm using a lot of async network request (btw any network request in iOS need to by async) and I'm finding way to better handle errors from Apple's dataTaskWithRequest which not supports throws . I have code like that: func sendRequest(someData: MyCustomClass?, completion: (response: NSData?) -> ()) { let request = NSURLRequest(URL: NSURL(string: "http://google.com")!) if someData == nil { // throw my custom error } let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in // here I want to handle Apple's error } task.resume() } I need to parse my possible

Value of type 'Error' has no member 'code' [duplicate]

喜夏-厌秋 提交于 2019-12-05 09:45:45
问题 This question already has answers here : Accessing code in Swift 3 Error (5 answers) Closed 3 years ago . I am moving a test application over to Xcode 8 Beta 5 and converted my code to Swift 3. I am left with a few errors regarding the switch to Error from NSError . I get an error in Xcode saying, 'Value of type 'Error' has no member 'code' . I can still use localizedDescription . Is code no longer a value within Error or is it just a bug within Xcode? 回答1: Figured the answer out on my own

CloudKit error handling - retry logic

穿精又带淫゛_ 提交于 2019-12-05 02:43:32
问题 I want to put excellent CloudKit error handling in my app as Apple wants us to do. I want to save and modify a record right now. Here is my basic save logic... func addNewRecord(managedObj: NSManagedObject) { let newRec = managedObj.convertToCkRecord() publicDB.saveRecord(newRec, completionHandler: saveHandler) } func saveHandler(savedRecord: CKRecord?, error: NSError?) { // handle errors here if let error = error { if error.code == CKErrorCode.NotAuthenticated.rawValue { // debug print("Not

Value of type 'Error' has no member 'code' [duplicate]

守給你的承諾、 提交于 2019-12-03 22:24:41
This question already has an answer here: Accessing code in Swift 3 Error 5 answers I am moving a test application over to Xcode 8 Beta 5 and converted my code to Swift 3. I am left with a few errors regarding the switch to Error from NSError . I get an error in Xcode saying, 'Value of type 'Error' has no member 'code' . I can still use localizedDescription . Is code no longer a value within Error or is it just a bug within Xcode? Figured the answer out on my own minutes later. Xcode decided to give me a did you mean suggestion and .code is now ._code . 来源: https://stackoverflow.com/questions

CloudKit error handling - retry logic

旧街凉风 提交于 2019-12-03 20:21:52
I want to put excellent CloudKit error handling in my app as Apple wants us to do. I want to save and modify a record right now. Here is my basic save logic... func addNewRecord(managedObj: NSManagedObject) { let newRec = managedObj.convertToCkRecord() publicDB.saveRecord(newRec, completionHandler: saveHandler) } func saveHandler(savedRecord: CKRecord?, error: NSError?) { // handle errors here if let error = error { if error.code == CKErrorCode.NotAuthenticated.rawValue { // debug print("Not authentricated") } else if error.code == CKErrorCode.NetworkFailure.rawValue { print("Network failure!!

SSErrorDomain, SKReceiptRefreshRequest, SKRequest did fail with error, code = 16, code = 110

雨燕双飞 提交于 2019-12-03 13:07:28
iOS 9.2.1, Xcode 7.2.1, ARC enabled I am using the following method to check for failures of SKProductsRequest and SKReceiptRefreshRequest : - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { NSLog(@"error: %@", error); } My question is specifically about SKReceiptRefreshRequest . I am testing for two conditions, (1) when the user cancels the sign-in to iTunes Store for the receipt request and (2) when the user tries to sign-in and there is no connection (Air Plane Mode). I get the following errors: When there is no connection: Error Domain=SSErrorDomain Code=110 "Cannot

Returning an NSString from an NSError

天大地大妈咪最大 提交于 2019-12-03 04:12:24
I am using the NSURLRequest class in my iPhone app, and the method that calls it returns an NSString which is great for when the connection goes through ok, but the issue is I need to convert the NSError into an NSString so I can either return it back or run some if() statements on it. Any ideas? :) -[NSError localizedDescription] . (Also, every ObjC object inherited from NSObject implements -description which returns an NSString.) for folks new to objective c (me), following is example code that makes accepted answer from 'KennyTM' work -> [self showAlertWithTitle:@"Error:" withMessage:error

What's the difference between Error and NSError in Swift?

空扰寡人 提交于 2019-12-02 21:55:32
I am creating a library that should return errors so I'm wondering which one should use for my purposes. UPDATE: I should clarify, the returned result will be from a asynchronous call so I need to inform to the user if there was an error and I would like to know which type I should use Error or NSError. vadian NSError is a Cocoa class An NSError object encapsulates information about an error condition in an extendable, object-oriented manner. It consists of a predefined error domain, a domain-specific error code, and a user info dictionary containing application-specific information. Error is