Realm-cocoa: RealmSwift.Error conflicts with Swift standard library Error

Created on 22 Sep 2016  路  4Comments  路  Source: realm/realm-cocoa

Goals

Make RealmSwift working with other libraries

Expected Results

RealmSwift should inherit from Swifts standard library Error instead of redeclare.

Actual Results

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

Steps to Reproduce

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.

Code Sample

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) {

    }
}

viewcontroller_swift

Version of Realm and Tooling

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

Most helpful comment

You have semantic version to resolve breaking changes issues in API.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings