Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in creating relationship one-to-one #5531

Closed
mrfer opened this issue Dec 21, 2017 · 2 comments
Closed

Problem in creating relationship one-to-one #5531

mrfer opened this issue Dec 21, 2017 · 2 comments
Labels

Comments

@mrfer
Copy link

mrfer commented Dec 21, 2017

Good day!

I have two classes:

import SwiftyJSON
import Realm
import RealmSwift

class OfficeModel: Object {
    
    var id = RealmOptional<Int>()
    @objc dynamic var city: String?
    @objc dynamic var address: String?
    @objc dynamic var phone: String?

    @objc dynamic var coordinate: OfficeСoordinates?
    
    convenience init(json: JSON) {
        self.init()
        self.id.value = json["Id"].int
        self.city = json["City"].string
        self.address = json["Address"].string
        self.coordinate = OfficeСoordinates(json: json["Coordinates"])
    }
    
}

class OfficeСoordinates: Object {
    
    var latitude = RealmOptional<Double>()
    var longitude = RealmOptional<Double>()
    
    convenience init(json: JSON) {
        self.init()
        
        self.latitude.value = json["Latitude"].double
        self.longitude.value = json["Longitude"].double
    }
}

The first time you access realm, the following error occurs:
2017-12-21 13 19 25

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 "Schema validation failed due to the following errors:

  • Property 'OfficeModel.coordinate' of type 'object' has unknown object type 'OfficeСoordinates'" UserInfo={NSLocalizedDescription=Schema validation failed due to the following errors:
  • Property 'OfficeModel.coordinate' of type 'object' has unknown object type 'OfficeСoordinates', Error Code=1}: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.74.1/src/swift/stdlib/public/core/ErrorType.swift, line 181
    2017-12-21 13:19:05.559834+0500 EnergoIndividual[73534:5337172] Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 "Schema validation failed due to the following errors:
  • Property 'OfficeModel.coordinate' of type 'object' has unknown object type 'OfficeСoordinates'" UserInfo={NSLocalizedDescription=Schema validation failed due to the following errors:
  • Property 'OfficeModel.coordinate' of type 'object' has unknown object type 'OfficeСoordinates', Error Code=1}: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.74.1/src/swift/stdlib/public/core/ErrorType.swift, line 181

Declared the property @objc dynamic var coordinate: OfficeСoordinates? as indicated on this page: https://realm.io/docs/swift/latest/#using-the-realm-framework

2017-12-21 13 27 29

Tell me, please, what is the error here?

Realm framework version: 3.0.2

Realm Object Server version: n/a

Xcode version: 9.1

iOS/OSX version: iOS11

Dependency manager + version: Cocoapods 1.3.1

@mrfer mrfer changed the title Crash: Property 'OfficeModel.coordinate' of type 'object' has unknown object type 'OfficeСoordinates Problem in creating relationship one-to-one Dec 22, 2017
@bdash
Copy link
Contributor

bdash commented Jan 2, 2018

The underlying cause here is your use of Unicode codepoint 0421, CYRILLIC CAPITAL LETTER ES, in place of the uppercase C in the type name of OfficeСoordinates. Replacing that with a normal Latin C fixes the problem.

@bdash bdash closed this as completed Jan 2, 2018
@bdash bdash added the T-Help label Jan 2, 2018
@mrfer
Copy link
Author

mrfer commented Jan 5, 2018

@bdash Thank you very much, it helped!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants