Skip to content

trungfinity/ios-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.1.0"

Manual

  • Drag and drop Classes folder into your project.

Usage

#import "Spread.h"

Create a class sub class SModel

class Model: SModel {

  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: SModelEvent.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

When the shit hit the fan, it will be spread all over.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors