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

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 a Swift protocol which classes, structs and enums can and NSError does conform to. A … Read more

upload image to server using Alamofire

Try below code let image = UIImage.init(named: “myImage”) let imgData = UIImageJPEGRepresentation(image!, 0.2)! let parameters = [“name”: rname] //Optional for extra parameter Alamofire.upload(multipartFormData: { multipartFormData in multipartFormData.append(imgData, withName: “fileset”,fileName: “file.jpg”, mimeType: “image/jpg”) for (key, value) in parameters { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } //Optional for extra parameters }, to:”mysite/upload.php”) { (result) in switch result { … Read more

preferredStatusBarStyle removed in Swift 3?

In iOS 10, preferredStatusBarStyle is a property, not a method. So instead of overriding it with a func declaration as you’ve done, you override the getter with a var declaration: override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } The Swift compiler’s error message here could probably be better — since it seems to know your … Read more

Swiftlint warning : For Where Violation: `where` clauses are preferred over a single `if` inside a `for`. (for_where)

The syntax preferred by your swiftlint configuration is: for settingsKeys in searchResults where settingsKeys.key == settingsObject.key { settingsKeys.value = settingsObject.value try context.save() } Which is the similar to for settingsKeys in (searchResults.filter { $0.key == settingsObject.key }) { settingsKeys.value = settingsObject.value try context.save() } If you know there is only one result with the same … Read more

tech