Skip to content

sonswift/Spread

 
 

Repository files navigation

Build StatusCocoaPods Version

Spread is a data flow control. It changes the way you manage your data.

Features

  • Create, mapping dictionary to model and model to dictionary, manage data model automatic.
  • Auto trigger event to all models in register pools.
  • React when model properties, pool change value.
  • Store and restore models in pools from local database.
  • Fetch/push data for model from internet.
  • Remote event manager with queue.

Installation

CocoaPods

pod "Spread", "~> 1.2.1"

Manual

  • Drag and drop Classes folder into your project.

Usage

#import "Spread.h"

Create a class sub class Mapper

class Model: Mapper {
  dynamic var objectId: String!
  dynamic var name: String!
}

Register class

Spread.registerClass(Model.classForCoder(), forPoolIdentifier:"PoolIdentifier")

Register pool event

Spread.registerEvent("TheEvent",
  poolIdentifiers:["PoolIdentifier"]) { (value, spool) -> Void in
  let objectId = (value as NSDictionary).valueForKey("objectId") as String
  let newName = (value as NSDictionary).valueForKey("name") as String
  let models = spool.filter({ (model) -> Bool in
    return (model as Model).objectId == objectId
  })
  for item in models {
    let model = item as Model
      model.name = newName
    }
  }

Add sample data model and setup reaction for property

let model = Spread.addObject(["name": "Some name", "objectId": "123"],
  toPool: self.pool1Identifier)

model.property("name", onEvent: .OnChange) { (oldValue, newValue) -> Void in
  aTextField.text = newValue as String
}

Perform an event

Spread.outEvent("TheEvent",
  value: ["name": "Change the name", "objectId": "123"])

Contact

If you use/enjoy Spread, let me know!

License

See the LICENSE file for more info.

About

Work hard, dream big

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 80.8%
  • Swift 18.6%
  • Ruby 0.6%