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

fix attempt for Realm support #1414

Merged
merged 1 commit into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ChartsRealm/Classes/Data/RealmBarDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ open class RealmBarDataSet: RealmBarLineScatterCandleBubbleDataSet, IBarChartDat
var values = [Double]()
for val in value as! RLMArray
{
values.append((val as! RLMObject)[_stackValueField!] as! Double)
values.append(val[_stackValueField!] as! Double)
}
entry = BarChartDataEntry(values: values, xIndex: _xIndexField == nil ? Int(atIndex) : object[_xIndexField!] as! Int)
}
Expand Down
2 changes: 1 addition & 1 deletion ChartsRealm/Classes/Data/RealmBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ open class RealmBaseDataSet: ChartBaseDataSet

for e in foundObjects
{
entries.append(buildEntryFromResultObject(e as! RLMObject, atIndex: UInt(x)))
entries.append(buildEntryFromResultObject(e, atIndex: UInt(x)))
}
}

Expand Down
42 changes: 31 additions & 11 deletions ChartsRealm/Classes/Utils/RealmChartUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class RealmChartUtils: NSObject

for object in results
{
let xVal = (object as! RLMObject)[xValueField] as! String!
let xVal = object[xValueField] as! String!
if !addedValues.contains(xVal!)
{
addedValues.add(xVal!)
Expand All @@ -35,19 +35,39 @@ open class RealmChartUtils: NSObject
return xVals
}
}
extension RLMObject {
// Swift query convenience functions
public class func objects(where predicateFormat: String, _ args: CVarArg...) -> RLMResults<RLMObject> {
return objects(with: NSPredicate(format: predicateFormat, arguments: getVaList(args)))
}

extension RLMResults: Sequence
{
open func makeIterator() -> NSFastEnumerationIterator
{
return NSFastEnumerationIterator(self)
public class func objects(in realm: RLMRealm,
where predicateFormat: String,
_ args: CVarArg...) -> RLMResults<RLMObject> {
return objects(in: realm, with: NSPredicate(format: predicateFormat, arguments: getVaList(args)))
}
}

extension RLMArray: Sequence
{
open func makeIterator() -> NSFastEnumerationIterator
{
return NSFastEnumerationIterator(self)
public final class RLMIterator: IteratorProtocol {
private let iteratorBase: NSFastEnumerationIterator

internal init(collection: RLMCollection) {
iteratorBase = NSFastEnumerationIterator(collection)
}

public func next() -> RLMObject? {
return iteratorBase.next() as! RLMObject?
}
}

// Sequence conformance for RLMArray and RLMResults is provided by RLMCollection's
// `makeIterator()` implementation.
extension RLMArray: Sequence {}
extension RLMResults: Sequence {}

extension RLMCollection {
// Support Sequence-style enumeration
public func makeIterator() -> RLMIterator {
return RLMIterator(collection: self)
}
}