Skip to content

There is a compilation error with Entity.id.isEqual(to:id) #90

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

Open
1 task done
welkinbai opened this issue Feb 3, 2025 · 2 comments
Open
1 task done

There is a compilation error with Entity.id.isEqual(to:id) #90

welkinbai opened this issue Feb 3, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@welkinbai
Copy link

Is there an existing issue?

Build info

  • ObjectBox version: [4.1.0]
  • OS: IOS 17
  • Device/chipset: iPhone 15

Steps to reproduce

  1. my class:
// objectbox: entity
class OneEntity :{
    var id: Id = 0
    
    var text: String?
    init(){}
  
}

query code:

func query(id: Id) -> [OneEntity] {
        do {
            let query: Query<OneEntity>?

            query = try entityDataBox?.query {OneEntity.id.isEqual(to: id) }
                .build()

            
            if let result = try query?.find(limit: 15) {
                return result
            }
            
            return []
        } catch {
            print("query fail, err:\(error)")
            return []
        }
    }

I encountered a compilation error at OneEntity.id.isEqual(to: id) here:
Ambiguous use of 'isEqual(to:)'

Expected behavior

I expect OneEntity.id.isEqual(to: id) should work

Actual behavior

Compilation error

@welkinbai welkinbai added the bug Something isn't working label Feb 3, 2025
@welkinbai
Copy link
Author

I noticed that isEqual has two definitions:

extension Property where V : ObjectBox.IdBase {

    /// Equivalent to the == operator in query blocks.
    public func isEqual(to value: ObjectBox.Id) -> ObjectBox.PropertyQueryCondition<ObjectBox.Property<E, V, R>.EntityType, ObjectBox.Id>
}
extension Property where V : FixedWidthInteger {

    /// Equivalent to the == operator in query blocks.
    public func isEqual(to value: ObjectBox.Property<E, V, R>.ValueType) -> ObjectBox.PropertyQueryCondition<ObjectBox.Property<E, V, R>.EntityType, ObjectBox.Property<E, V, R>.ValueType>
}

I think this might be the cause of the problem, but I don't know how to solve it.

@greenrobot-team
Copy link
Member

Thank you for reporting!

I also have not found a workaround for this when this is one of many query conditions.

However, if the only query condition is an isEqual on the ID, like the above example, you can instead write code to just get the object from its Box using the ID: entityDataBox.get(id)

Internal issue for this is objectbox-swift#314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants