Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

792
Views
Cómo ordenar los resultados en Realm

Estoy usando Realm con Swift. Quiero ordenar las "imágenes" guardadas en Realm por PhotoCollectionViewController en orden inverso a la fecha. no se que debo hacer Me encantaría que me prestaras tu sabiduría.

Modelos.swift

 import RealmSwift class Entry: Object { @objc dynamic var text = "" @objc dynamic var date = Date() let pictures = List<Picture>() } class Picture: Object { @objc dynamic var fullImageName = "" @objc dynamic var thumbnailName = "" @objc dynamic var entry : Entry? }

PhotoCollectionViewController.swift

 import UIKit import RealmSwift class PhotoCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { var pictures : Results<Picture>? override func viewWillAppear(_ animated: Bool) { getPictures() } func getPictures() { if let realm = try? Realm() { pictures = realm.objects(Picture.self) //I want to sort pictures in the reverse order of date collectionView?.reloadData() } } … }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Debería poder ordenarlo con el siguiente código

 realm.objects(Picture.self).sorted(byKeyPath: "date", ascending: false)
over 4 years ago · Santiago Trujillo Report

0

Lo siento, lo resolví yo mismo. Cambié las "imágenes" de la siguiente manera, pude hacer lo que esperaba.

 pictures = realm.objects(Picture.self).sorted(byKeyPath: "entry.date", ascending: false)

Gracias por las respuestas y los consejos.

over 4 years ago · Santiago Trujillo Report

0

Si entendí correctamente, desea ordenar los objetos Entry y luego flatMap a un montón de Picture :

 var pictures = realm.objects(Entry.self) .sorted(byKeyPath: "date", ascending: false) .flatMap { $0.pictures }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!