Giter VIP home page Giter VIP logo

jvcontenttype's Introduction

JVContentType

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 11.0 > and Swift 4.2 >

Description

Create reusabele components throughout your app.

Do you ever write code and notice you constantly are writing duplicate code? Do you create e.g. labels in your Storyboard and constantly setting the same font?

What happens when you want to change your font? Color? Size?

JVContentType to the rescue!

To tackle the problem described above, do the following:

  1. Create an enum with all the types you are using in your app:

public enum LabelType { case header, body, title }

  1. Make it initializable by a String expression by writing :String behind your enum (CaseIterable should be added aswell): public enum LabelType: String { case header, body, title }

  2. Subclass ContentType, make it a final class and add your properties. Example:

import JVContentType

public final class ContentTypeLabel: ContentType { public static var allTypes = Set()

public var contentTypeId: String? public var font: UIFont public var color: UIColor

public init(contentTypeId: String?, font: UIFont, color: UIColor) { self.contentTypeId = contentTypeId self.font = font self.color = color } }

  1. Add the following String extension to provide an easy contentType getter:

var contentTypeLabel: ContentTypeLabel { return ContentTypeLabel.getContentType(contentTypeId: self) }

  1. Add the following variable to your enum:

var contentType: ContentTypeLabel { return rawValue.contentTypeLabel }

  1. Now somewhere when your app start, loop through all the cases of your enum and make sure every rawValue has a contentType associated with it. You can now create a convenience initializer for e.g. the UILabel that only takes a contentType as parameter.

Installation

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

pod 'JVContentType'

Author

Jasperav, [email protected]

License

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

jvcontenttype's People

Contributors

jasperav avatar

Watchers

 avatar  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.