GithubHelp home page GithubHelp logo

faerae-inspira / gluten Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wilbertliu/gluten

0.0 0.0 0.0 20 KB

Micro library to unify XIB and its code.

License: MIT License

Ruby 10.26% Objective-C 10.43% Swift 79.31%

gluten's Introduction

Gluten

Carthage compatible Build Status Coverage Status

Unify XIB with its code.

Background

We always try to generalize some views that would be used in different places throughout the app. And one approach that we usually do is to make XIB along with its code.

But as we know, the XIB and its code don't automatically connected. And we tend do these things to make them connected :

  1. Instantiate the NIB.
  2. Add the loaded NIB as a subview.
  3. Setting frame or constraints needed.

Always doing those things for every view that we make, I think there's a better way. What we have to do is calling one function inside our view's code. Yes, just that! Follow the steps below to see how it goes.

Installation

Carthage

github "wilbertliu/Gluten"

CocoaPods

Add the following line into the Podfile :

pod 'Gluten'

After that, run the following command :

$ pod install

Usage

Because Gluten was created in extension, we don't need to import anything. Just call glueSourceAndView() function inside our view's code. Here's an example :

import UIKit

class ReusedView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        glueSourceAndView()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        glueSourceAndView()
    }

    init() {
        super.init(frame: CGRect.zero)
        glueSourceAndView()
    }
}

Note that when we have a class named ReusedView, the XIB name must be the same. When you're not doing so, Gluten would leave those XIB and code unconnected.

Support

If you have any feedbacks, feel free to submit a PR! And I'm more than happy to answer your questions, or maybe just some hi?! To do that, shoot me a DM or tweet @wilbertliu

License

MIT © Wilbert Liu

gluten's People

Contributors

faerae avatar readmecritic avatar wilbertliu avatar

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.