LoginSignup
1
0

More than 5 years have passed since last update.

[Swifty]計算済みプロパティの追加

Posted at

かなり無理をしている状態になってきたが、それだけ、試行錯誤しないといけないので、得るものはある。

今回は、計算済みプロパティの追加だ。今回も、無理がありそう!

やはり、これは無理。

protocol SourceType: UITableViewDataSource {
    //var dataObject: DataType {get set}
    //var conditionForAdding: Bool {get}
}

Model(Dataコントローラ)に計算済みプロパティを追加することに変更。

class Document: NSObject {
    private var dataObject: DataType = Hand()
    
    var conditionForAdding: Bool {
        return dataObject.numberOfItems < 5
    }
}

すると、こうなる。

class DataSource: NSObject, UITableViewDataSource, SourceType {
    private var document = Document.sharedInstance
    
    func addItemTo(tableView: UITableView) {
        if document.conditionForAdding {
            document.addNewItem(at: 0)
            insertTopRowIn(tableView: tableView)
        }
    }
}

条件判定はプロパティになっている。

ソースコード
GitHubからどうぞ。

https://github.com/murakami/workbook/tree/master/ios/Hand - GitHub

関連情報
文化を調和させる

【Cocoa練習帳】
http://www.bitz.co.jp/weblog/

http://ameblo.jp/bitz/(ミラー・サイト)

1
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
1
0