Where is the right documentation?
You'll need to provide more information. What documentation are you looking for?
Ok, lets look for this, I want to save every time an item(string) to array. From official documentation I created that:
import Foundation
import RealmSwift
import Realm
class Item: Object {
// MARK: - Properties
dynamic var scannedText = ""
}
class ScanObjects: Object {
// MARK: - Properties
var items = List<Item>()
}
Looks good, but I start to save data to that "list":
if let scannedText = scannedText {
if let realm = try? Realm() {
do {
try realm.write {
let item = Item()
item.scannedText = scannedText
let scannedObject = ScanObjects()
scannedObject.items.insert(item, at: 0)
realm.add(scannedObject)
}
} catch {
print(error.localizedDescription)
}
}
}
Also, looks verry good, but, how to retrieve that array from database, I cant explain:
I tried:
if let realm = try? Realm() {
let objects = realm.objects(Item.self)
print(objects.count) /// 0 objects
}
also:
if let realm = try? Realm() {
let objects = realm.objects(ScanObjects.self)
print(objects.count) // 0 objects
}
If you create that "magnifique" database, please provide a normal documentation to use:
1: Ho to save data: array, dicts, primitive data etc;
HOW???
Thanks!
I dropped the code you provided into a test project and got the expected result (1 of each object).
The first thing to check is whether your if let scannedText = scannedText block is even being entered. If the block isn't entered, no objects will be stored. A breakpoint or print statement would help confirm this.
Ok, why I retrieve 0? I run the same code. How to retrieve data? Please provide the full answer no 5%.
Or let admin of this Repo respond to my question.
As I stated, the most likely reason you're seeing zero is that scannedText is nil and so you're never adding any objects to the Realm. In my test I'm explicitly setting it to a non-nil value:
let scannedText: String? = "Scanned text"
See https://gist.github.com/bdash/799e9c496d387bda98e196289e2def71 for the full code I tested.
I cant see the resolve of this problem from you.
The conclusion is: Realm has a suck documentation!
I'm really not clear what you expected here. I demonstrated that given correct inputs, the code you shared works correctly, and I provided a hypothesis as to which of your inputs is incorrect and is leading to the incorrect behavior you're seeing. If you're not willing to debug your own code to test this hypothesis, I don't think there's anything we can do to help you.
Man, are you ill? What I'm write at start?
If you create that "magnifique" database, please provide a normal documentation to use:
1: Ho to save data: array, dicts, primitive data etc;
I cant found that info on official super realmwebsite.
All of that information is covered at https://realm.io/docs/swift/latest/, which you'd get to by clicking on the Docs link at the top of the Realm homepage.
Sorry, but this documentation is not useful.
@mihailsalari: I wanted to chime in here and affirm that @bdash's example (available here) indeed works and that I also saw an object returned during my own testing.
We are happy to help you resolve this (and any other) issue you may experience (now or in the future) but I/we don't appreciate the personal attacks on @bdash or anyone else.
Please take some time to read through Realm's Code of Conduct.
Most helpful comment
@mihailsalari: I wanted to chime in here and affirm that @bdash's example (available here) indeed works and that I also saw an object returned during my own testing.
We are happy to help you resolve this (and any other) issue you may experience (now or in the future) but I/we don't appreciate the personal attacks on @bdash or anyone else.
Please take some time to read through Realm's Code of Conduct.