gpt4 book ai didi

ios - RLMArray 不支持快速枚举 NSFastEnumerationIterator?

转载 作者:行者123 更新时间:2023-11-29 00:06:01 25 4
gpt4 key购买 nike

强制 RLMArray 支持 NSFastEnumerationIterator 的最佳方式是什么?

internal override func buildEntryFromResultObject(_ object: RLMObject, x: Double) -> ChartDataEntry
{
let value = object[_yValueField!]
let entry: BarChartDataEntry

if value is RLMArray<AnyObject>
{
var values = [Double]()
var iterator = NSFastEnumerationIterator(value as! RLMArray)
while let val = iterator.next()
{
values.append((val as! RLMObject)[_stackValueField!] as! Double)
}
entry = BarChartDataEntry(x: _xValueField == nil ? x : object[_xValueField!] as! Double, yValues: values)
}
else
{
entry = BarChartDataEntry(x: _xValueField == nil ? x : object[_xValueField!] as! Double, y: value as! Double)
}

return entry
}

最佳答案

从你的问题来看,你似乎对如何使 RLMArray 在 Swift 中可迭代更感兴趣,而不是专门将它与 NSFastEnumerationIterator 一起使用。

Realm's documentation有这样的话:

We recommend you compile the Swift/RLMSupport.swift file (which is also available in our release zip). This file adds Sequence conformance to Realm Objective‑C collection types and re-exposes Objective‑C methods that aren’t natively accessible from Swift like methods including variadic arguments.

Realm Objective‑C doesn’t include this file by default, because that would force all users of Realm Objective‑C to include the hefty Swift dynamic libraries regardless of whether or not they use Swift in their app!

关于ios - RLMArray 不支持快速枚举 NSFastEnumerationIterator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48055737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com