RACMutableCollectionProperty 0.1.3

RACMutableCollectionProperty 0.1.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年4月
SPM支持SPM

Pedro PiñeraAndy Kogut维护。



  • @pepibumur

RAC-MutableCollectionProperty

针对ReactiveCocoa (Swift)实现的MutableCollectionProperty的概念

@pepibumur实现

功能

  • Swift 2.0
  • 细粒度报告集合更改(自定义事件)
  • 它公开了Swift数组集合方法
  • 受到NSFetchedResultsController的启发
  • ReactiveCocoa 4.XX

如何安装

  1. 获取Carthage,执行brew update carthage
  2. github "gitdoapp/RAC-MutableCollectionProperty"行添加到您的Cartfile
  3. 执行carthage update
  4. 按照这里提供的步骤,将Carthage生成的框架添加到您的项目中。

如何使用它

  1. 创建类型为MutableCollectionProperty的属性
let property: MutableCollectionProperty<String> = MutableCollectionProperty(["test1", "test2"])
  1. 使用属性可用的订阅者
property.producer.startWithNext { newCollection in
  // Do whatever you want with the new collection
  // e.g. tableView.reloadData()
}
property.flatChanges.startWithNext { change in
  switch change {
    case Remove(Int, T)
    case Insert(Int, T)
    case Composite([CollectionChange])
  }
}

:warning:在处理深层集合时不要依赖.flatChanges.flatChangesSignal),它不会通知深层数据的变化,尽管它与平面集合相比提供了更多类型检查。使用.changes.changesSignal)处理深层集合。

深层集合

具有类型为MutableCollectionSection值的集合允许改变深层元素并跟踪这些变化。

let table: MutableCollectionProperty<MutableCollectionSection<String>> =
    MutableCollectionProperty([
        MutableCollectionSection(["test1", "test2"]),
        MutableCollectionSection(["test3", "test4"])
    ])

table.changes.startWithNext { change in
    switch change {
        case Remove([Int], Any)      // [Int] — index path
        case Insert([Int], Any)      // [Int] — index path
        case Composite([CollectionChange])
    } 
}

table.removeAtIndexPath([1, 1]) // will remove "test4"

您可以子类化MutableCollectionSection以适应您的需求

class UITableViewSectionData: MutableCollectionSection<NSManagedObject> {
    let name: String?
    let indexTitle: String?
    init(objects: [NSManagedObject], sectionName name: String?, indexTitle: String?) {
        self.name = name
        self.indexTitle = indexTitle
        super.init(objects)
    }
}

真实世界例子

查看RACFRC的源代码。

开发者

  • 如果您有任何问题,请联系[email protected]
  • 您还可以在仓库中向您关注的问题、问题、想法。
  • 如果您想为本组件做出贡献,请记得添加测试以测试您的新功能。

许可证

The MIT License (MIT)

Copyright (c) 2015 GitDo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.