Make RealmSwift working with other libraries
RealmSwift should inherit from Swifts standard library Error instead of redeclare.
For example: If you have a view controller which imports RealmSwift and MessageUI which is implementing a MFMailComposeViewControllerDelegate the project is no longer able to build. The error is:
'Error' is ambiguous for type lookup in this context
Just create a view controller which implements MFMailComposeViewControllerDelegate or as an other example UIWebViewDelegate. The project will build. As soon as you do a import RealmSwift the project will no longer build.
Here a sample of working code:
import UIKit
import MessageUI
//import RealmSwift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
// do something
}
}
extension ViewController: UIWebViewDelegate {
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
}
}
and as soon as you import RealmSwift it will break.
import UIKit
import MessageUI
import RealmSwift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
// do something
}
}
extension ViewController: UIWebViewDelegate {
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
}
}

Realm version:
Realm (1.1.0)
RealmSwift (1.1.0)
Xcode version:
Xcode 8.0
Build version 8A218a
iOS/OSX version:
ProductName: Mac OS X
ProductVersion: 10.11.6
BuildVersion: 15G1004
Buildtarget iOS: 9.x and newer
Dependency manager + version:
cocoapods 1.1.0.beta.1
Adding RealmSwift import will make existing code broken. Temporary workaround is replacing Error to Swift.Error for whole project. Not Swifty!
Changing this would be a breaking change. See previous discussions in #4113 and #4086.
You have semantic version to resolve breaking changes issues in API.
Indeed.
Most helpful comment
You have semantic version to resolve breaking changes issues in API.