Git Product home page Git Product logo

instantiate's Introduction

Instantiate

Build Status Carthage compatible

Type-safe and constructor injectable InterfaceBuilder protocols.

Summary

Storyboard and Nib is not type safe, if you use UIStoryboard or UINib, your code would be get some gloom. Instantiate take type-safe protocols for Storyboard and Nib. Lets' improve our code with type-safe protocols!

as is

let storyboard = UIStoryboard(name: "ViewController", bundle: Bundle.main)
let vc = storyboard.instantiateInitialViewController() as! ViewController
vc.inject([1, 2, 3])

to be

import Instantiate
import InstantiateStandard
extension ViewController: StoryboardInstantiatable {}
let vc = ViewController(with: [1, 2, 3])

Protocols

StoryboardInstantiatable

Supports using viewController with Storyboard. Implement StoryboardInstantiatable at your viewController class, then you can use ViewController(with: Dependency).

NibInstantiatable

Supports using view with Nib. Implement NibInstantiatable at your view class, then you can use View(with: Dependency).

NibInstantiatableWrapper

Supports using view implements NibInstantiatable in other InterfaceBuilder. NibInstantiatableWrapper supports workaround. Make new UIView subclass, and implement NibInstantiatableWrapper, call loadView on init(coder:) and prepareForInterfaceBuilder. http://stackoverflow.com/questions/27807951/how-to-embed-a-custom-view-xib-in-a-storyboard-scene

Reusable

Supports UITableViewCell / UICollectionViewCell reuse features. Implement Reusable, then you can dequeue cell using Cell.dequeue(from: Parent, for: IndexPath, with: Dependency).

InstantiateStandard

StoryboardType and NibType required static var storyboard or static var nib. You need to write these values on own class, it is troublesome... Many developer define StoryboardName is same of ClassName, and if you are also, you can use InstantiateStandard. This libraly add default implementation of StoryboardType, NibType, and Reusable.

Instalation

Carthage

github "tarunon/Instantiate"

Pods

pod 'Instantiate'

Swift Package Manager

Select Xcode menu File > Swift Packages > Add Package Dependency... and enter repository URL with GUI.

Repository: https://github.com/tarunon/tarunon/Instantiate

Requirement

Platform Version
iOS 9.0+
macOS 10.11+
tvOS 9.0+
Swift 4.0+

instantiate's People

Contributors

hiragram avatar mtfum avatar ostk0069 avatar tarunon avatar ya-s-u 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  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

instantiate's Issues

Package Resolution Failed

When I try to add package of Instantiate via SPM, I get the following error:

because Instantiate >=2.1.0 contains incompatible tools version and root depends on Instantiate 4.0.0..<5.0.0, version solving failed.

environment: Xcode 12.2

So is there a workaround?
Thank you.

スクリーンショット 2020-12-16 10 23 20

Question about Test cases

Just one question.
If need to test UI. I need to set public/internal for the class members which are UI Control.
Because I need to compare dependency value(mock data) with the value in UI.

I used to set private/fileprivate to prevent UI member from changing by outside.
How to use dependency but still keep members safe.

Thanks

How to call ViewController in a Storyboard?

I use Instantiate in my project.
Thank you as always.

I want to write source code as below

let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
firstViewController = storyboard.instantiateViewController(withIdentifier: FirstViewController.nameOfClass)

I think can in Instantiate.
However, I don't know how to use in Instantiate.

Could you tell me how to use?

Could not fetch v4.0.0 from Cocoapods

Hi @tarunon 👋
I want to use v4.0.0 but could not download with specifying version as pod 'Instantiate', '~> 4.0' and then pod update.

Result:

[!] CocoaPods could not find compatible versions for pod "Instantiate":
  In Podfile:
    Instantiate (~> 4.0)

None of your spec sources contain a spec satisfying the dependency: `Instantiate (~> 4.0)`.

You have either:
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.

I think you forgot to release in Cocoapods because it said v3.0.0 was the latest.

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.