Giter Club home page Giter Club logo

brick's Introduction

Brick

CI Status Version Carthage Compatible License Platform Documentation Swift

Description

Brick Icon

Brick is a generic view model for both basic and complex scenarios. Mapping a basic table view cells is as easy as pie, if you have more properties, you can use the meta dictionary to add all additional properties that you might need. It also supports relations so that you can nest view models inside of view models.

public struct Item: Mappable {
  public var index = 0
  public var title = ""
  public var subtitle = ""
  public var text = ""
  public var image = ""
  public var kind = ""
  public var action: String?
  public var size = CGSize(width: 0, height: 0)
  public var meta = [String : AnyObject]()
}
  • .index Calculated value to determine the index it has inside of the component.
  • .title The headline for your data, in a UITableViewCell it is normally used for textLabel.text but you are free to use it as you like.
  • .subtitle Same as for the title, in a UITableViewCell it is normally used for detailTextLabel.text.
  • .text This is an optional property that can be used for larger amount of text needed to describe your Item
  • .image Can be either a URL string or a local string, you can easily determine if it should use a local or remote asset in your view.
  • .kind Is used for the reuseIdentifier of your UITableViewCell or UICollectionViewCell.
  • .action Action identifier for you to parse and process when a user taps on a list item. We recommend Compass as centralized navigation system.
  • .size Can either inherit from the UITableViewCell/UICollectionViewCell, or be manually set by the height calculations inside of your view.
  • .meta This is used for extra data that you might need access to inside of your view, it can be a hex color, a unique identifer or additional images for your view.

Usage

let item = Item(
  title: "John Hyperseed",
  subtitle: "Build machine",
  meta: [
    "operatingSystem" : "OS X",
    "xcodeVersion" : 7.3
])

print(item.meta("operatingSystem", "")) // prints "OS X"
print(item.meta("xcodeVersion", 0.0)) // prints 7.3

Installation

Brick is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Brick'

Brick is also available through Carthage. To install just write into your Cartfile:

github "hyperoslo/Brick"

Author

Hyper Interaktiv AS, [email protected]

Contributing

We would love you to contribute to Brick, check the CONTRIBUTING file for more info.

License

Brick is available under the MIT license. See the LICENSE file for more info.

brick's People

Contributors

aashishdhawan avatar onmyway133 avatar ramongilabert avatar vadymmarkov avatar zenangst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

brick's Issues

Meta properties generator

Would be nice to implement a script that goes through your models and generates a code for the each property on it:

import Brick

extension ViewModel {

  var metaId: Int? {
    set(value) {
      meta["id"] = value
    }
    get {
      return meta("id", type: Int.self)
    }
  }

  func metaId(value: Int) -> Int {
    return meta("id", value)
  }

  ///...
}

Then instead of "magic strings" you would use:

viewModel.id = 11
viewModel.id(0) // => value to 0 by default
viewModel.id // optional value

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.