- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用 Realmsvift 在我的应用程序中创建了数据库。这是控制台中的输出。请告诉我,如何在应用程序中从中读取数据?例如,我想显示键值对:Oslo - 2.89。感谢您的帮助。
class ViewController: UIViewController {
var city_list: [String] = ["Moscow", "London", "Oslo", "Paris"]
let realm = try! Realm()
override func viewDidLoad() {
super.viewDidLoad()
let manager: ManagerData = ManagerData()
for name in city_list {
manager.loadJSON(city: name)
}
let localWeather = realm.objects(WeatherData.self)
print(localWeather)
/////////////////////////////////////
Results<WeatherData> (
[0] WeatherData {
city_name = Moscow;
tempList = RLMArray <0x6080002e2b00> (
[0] Temp {
temp = -4.25;
}
);
},
[1] WeatherData {
city_name = London;
tempList = RLMArray <0x6000002e4700> (
[0] Temp {
temp = 9.630000000000001;
}
);
},
[2] WeatherData {
city_name = Paris;
tempList = RLMArray <0x6000002e4800> (
[0] Temp {
temp = 6.59;
}
);
},
[3] WeatherData {
city_name = Oslo;
tempList = RLMArray <0x6000002e4900> (
[0] Temp {
temp = -2.89;
}
);
}
最佳答案
如果我正确理解你的问题,你想从每个模型中获取属性。
如果是这样的话,你就快成功了。 localWeather
就像 Realm 世界中的数组(例如 Results<WeatherData>
的类型)。
您可以像普通 swift 的数组/对象一样访问它:
let firstWeather = localWeather[0]
let name = firstWeather.city_name
let temp = firstWeather.tempList[0].temp
// do what you want with 'name' and 'temp', e.g. key-value
print("\(name) - \(temp)")
关于iOS-RealmSwift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42466536/
我正在使用 RealmSwift 为我正在构建的 iOS 应用程序创建个人识别码对象。我已经创建了一个构造函数和一些基本函数来检查 pin、输入新 pin 等。我可以使用在 RealmSwift 中创
我已经使用 Realmsvift 在我的应用程序中创建了数据库。这是控制台中的输出。请告诉我,如何在应用程序中从中读取数据?例如,我想显示键值对:Oslo - 2.89。感谢您的帮助。 class V
我正在尝试从我的领域数据库中查询 token 和user_id,然后传递给我的 private var token 和userId,但是我一直抛出此错误 void函数中非预期的非无效返回值 在retu
假设我有很多城市对象。所以,城市 ID 将是我的主键,因为它们不能重复。将会有相同的城市名称,但是,不同的 ID 和不同的 ShopAddress。这是我的 json 结果这是来 self 的后端 {
当我使用 RealmSwift 时,它第一次工作并存储数据。然后,我使用 RealmBrowser 打开它。使用RealmSwift用Realm Browser打开Realm文件后,项目就解散了,错误
我有一个 Report 类,例如: class Report: Object{ @objc dynamic var id : String? = nil @objc dynamic var
这是我第一次在 Swift 上使用 Realm,尽管我通读了整个 Realm 文档,但我似乎无法理解一些简单而基本的概念。 当您在 Realm 中创建一个 Object 类并创建该类的实例时,它会自动
我一直在尝试安装新版本的 realm 0.92.3。我已按照教程中的每一步操作,但仍然不断收到错误消息。 btplpinoudaynpddpsugjevklbvh/Build/Products/Deb
我有这个模型: import Foundation import RealmSwift class Event: Object { dynamic var id
我已经在版本 0.98.2 中安装了 RealmSwift 的动态框架。(CocoaPods 不工作。) 我收到以下错误: module-includes>:1:9: note: in file in
let selectedConsoles = ["Xbox", "Playstation 4"] let players = realm.objects(Person).filter("console
我有一个带有一些字符串大小写的枚举 public enum UserPermission: String, Decodable { case userManagement = "USER_MA
我在理解避免将数据重复写入 Realm 数据库方面遇到了一些问题。我有以下对象模型 Person.swift class Person: Object { let id = RealmOpti
我不知道如何根据用户选择组合谓词。这是我的数据概览。 Person.swift class Person: Object { let id = RealmOptional() dynami
我如何知道特定交易何时完成? 我想在交易完成后运行一段特定的代码。我该怎么做? 我在下面的 war 中执行写入 - do { try realm.write({ realm.add()
我是编程新手,我想知道如何使用 RealmSwift 将数据存储在列表中。 考虑以下模型: import RealmSwift class ScanResults: Object{ dynamic v
我正在为我的项目使用 RealmSwift。但是,我不确定如何解决以下问题: RMLException: Attempting to modify object outside of a write
我有一些从 Realm 中获取的 item: let items = realm.objects(ShoppingListItem.self) print("\(items.count) items"
我有两个类(class): 第一个: class GameObject: Object { @objc dynamic var gameOutcome: String? = nil @
使用 RealmSwift 执行此操作的正确方法是什么,它曾经是 RLMobject var stream:Results stream = Realm().objects(streams) 第一个作
我是一名优秀的程序员,十分优秀!