LoginSignup
0
0

More than 5 years have passed since last update.

swiftでAnyObjectに、Realmを個別にぶっこむ

Last updated at Posted at 2016-09-06

CollectionViewのデータを好きなようにソートしたくて、
AnyObject型にRealmを入れたり、空データを入れたりした時の例、
普通にRealmで初期データ作った方が大幅に楽でしたが。汗

swift
var cellList = [AnyObject]()
swift

        // ソート用にrealmを内包した配列を用意
        for i in 0..<100 {

            if self.result?.filter("id ==" + String(i)).count > 0 {
                let data = self.result?.filter("id ==" + String(i)).last!
                cellList.append(data!)
            }else{

                // 空用のデータを用意
                let data = myData()
                data.scanDate = NSDate()
                data.id = i
                data.status = 0

                cellList.append(data)

            }
        }

        println("cellList \(cellList)")

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0