RLMResults' does not have a member named 'Generator
http://qiita.com/jtemplej/items/1c1b7204341ac01e561e
上記のサイトを参考にRealm
を使い始めたのですが、for realmBook in Book.allObjects()
の行で'RLMResults' does not have a member named 'Generator'
というエラーが表示されます。何か初歩的なことが間違っているような気がするのですが、どこが間違っているのでしょうか?下記に現在のコードを記しますので、どなたか分かる方がいれば教えていただきたいです。すみませんが、よろしくお願いします。
Book.swift
import Foundation
import Realm
class Book : RLMObject {
dynamic var isbn = ""
dynamic var name = ""
dynamic var price = 0
}
ViewController.swift
import UIKit
import Realm
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
stockData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func stockData() {
let realm = RLMRealm.defaultRealm()
// Bookオブジェクト生成.
let book = Book()
book.isbn = "999999"
book.name = "realm sample"
book.price = 100
// Bookオブジェクトを保存.
realm.beginWriteTransaction()
realm.addObject(book)
realm.commitWriteTransaction()
// 先ほどのBookオブジェクトを取得
// Class.allObjectsで全オブジェクト取得.
for realmBook in Book.allObjects() {
// book name:realm sample
println("book name:\((realmBook as Book).name)")
}
let book2 = Book()
book2.isbn = "999998"
book2.name = "realm tutorial 1"
book2.price = 1000
// Blockでの保存の仕方.
realm.transactionWithBlock() {
realm.addObject(book2)
}
for realmBook in Book.allObjects() {
// book name:realm sample
// book name:realm tutorial 1
println("book name:\((realmBook as Book).name)")
}
}
}