Skip to content

Package with lightweight resources models for code generation

License

Notifications You must be signed in to change notification settings

CaptureContext/swift-package-resources

Repository files navigation

swift-package-resources

CI

Package with lightweight resources models for code generation.

Tip

Default codegen for this package is capturecontext/package-resources-cli

Table of contents

Products

PackageResources

Product with the primary API, declares accessors for each resource type and some helpers. Unlike generated accessors, this module can be shared across multiple packages or targets without causing any ambiguity.

Basically provides static factories for avaliable resource types.

Color.resource(_:PackageResources.Color)
UIColor.resource(_:PackageResources.Color)
NSColor.resource(_:PackageResources.Color)
Image.resource(_:PackageResources.Image)
UIImage.resource(_:PackageResources.Image)
NSImage.resource(_:PackageResources.Image)
Font.resource(_:PackageResources.Font)
UIFont.resource(_:PackageResources.Font)
NSFont.resource(_:PackageResources.Font)
UIStoryboard.resource(_:PackageResources.Storyboard)
NSStoryboard.resource(_:PackageResources.Storyboard)

Note

Currently no custom Nib loading is available, but you can access name and bundle properties of NibResource to load your custom nib

PackageResourcesCore

Product with resource model declarations.

  • Accessors might be redundant for module with generated boilerplate. The only boilerplate that needs to be generated are factories for asset models, API can be provided statically, that is why this module doesn't declare any helpers for initializing objects like UIImage.
  • Default API provided with PackageResources product are redundant if you want to build your own API over generated boilerplate.
Available resource declarations
Type Alias
_ColorResource PackageResources.Color
_FontResource PackageResources.Font
_ImageResource PackageResources.Image
_StoryboardResource PackageResources.Storyboard
_SCNSceneResource PackageResources.SCNScene

Note

Base types are declared with underscores to avoid ambiguity with system types, for example you may choose to use xcasset catalog out-of-the box boilerplate generation for some asset types

Installation

Basic

You can add PackageResources to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter "https://github.com/capturecontext/swift-package-resources.git" into the package repository URL text field
  3. Choose products you need to link them to your project.

Recommended

If you use SwiftPM for your project, you can add PackageResources to your package file.

.package(
  url: "https://github.com/capturecontext/swift-package-resources.git", 
  .upToNextMinor(from: "4.0.0")
)

Do not forget about target dependencies:

.product(
  name: "PackageResources",
  package: "swift-package-resources"
)

License

This library is released under the MIT license. See LICENSE for details.