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

ObjectId does not conform to SortableType - sorted(by:ascending:) not working as expected #8647

Open
marcoboerner opened this issue Jul 7, 2024 · 3 comments

Comments

@marcoboerner
Copy link

How frequently does the bug occur?

Always

Description

I'm reading objects from my realm, I want to sort the results using the sorted(by:ascending:) method by the ObjectId. However, I get the warning:

Instance method 'sorted(by:ascending:)' requires that 'ObjectId.PersistedType' (aka 'ObjectId') conform to 'SortableType'

The documentation mentions, that sorting by ObjectId will usually result in sorting by creation date, so I assume it should be possible.

Example code in my project:

try await realm?
            .objects(UserToken.self)
            .sorted(by: \._id, ascending: true)
            .subscribe(name: #function)

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

10.52.1

What Atlas Services are you using?

Atlas Device Sync

Are you using encryption?

No

Platform OS and version(s)

iOS 18.0.x

Build environment

Xcode version: 16.0 beta 2 (16A5171r)
Dependency manager and version: SwiftPM - swift-tools-version: 5.10

Copy link

sync-by-unito bot commented Jul 7, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2406

@Jaycyn
Copy link

Jaycyn commented Jul 8, 2024

Easy fix.

Just change

.sorted(by: \._id, ascending: true)

to

.sorted(by: \._id.stringValue, ascending: true)

@marcoboerner
Copy link
Author

That's great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants