Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Bundle resources support #42

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make all reference to Bundle type optional
  • Loading branch information
Ivan Zezyulya committed May 27, 2021
commit 313a6402d1ffec4e647c06a11c8b48607b967b12
6 changes: 3 additions & 3 deletions Library/Core/ColorResource.swift
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import Foundation
public protocol ColorResourceType {

/// Bundle this color is in
var bundle: Bundle { get }
var bundle: Bundle? { get }

/// Name of the color
var name: String { get }
@@ -21,12 +21,12 @@ public protocol ColorResourceType {
public struct ColorResource: ColorResourceType {

/// Bundle this color is in
public let bundle: Bundle
public let bundle: Bundle?

/// Name of the color
public let name: String

public init(bundle: Bundle, name: String) {
public init(bundle: Bundle?, name: String) {
self.bundle = bundle
self.name = name
}
10 changes: 5 additions & 5 deletions Library/Core/FileResource.swift
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import Foundation
public protocol FileResourceType {

/// Bundle this file is in
var bundle: Bundle { get }
var bundle: Bundle? { get }

/// Name of the file file on disk
var name: String { get }
@@ -33,7 +33,7 @@ public extension FileResourceType {
- returns: The full pathname for this resource or nil if the file could not be located.
*/
func path() -> String? {
return bundle.path(forResource: self)
return bundle?.path(forResource: self)
}

/**
@@ -42,21 +42,21 @@ public extension FileResourceType {
- returns: The file URL for this resource or nil if the file could not be located.
*/
func url() -> URL? {
return bundle.url(forResource: self)
return bundle?.url(forResource: self)
}
}

public struct FileResource: FileResourceType {
/// Bundle this file is in
public let bundle: Bundle
public let bundle: Bundle?

/// Name of the file on disk, without the pathExtension
public let name: String

/// Extension of the file on disk
public let pathExtension: String

public init(bundle: Bundle, name: String, pathExtension: String) {
public init(bundle: Bundle?, name: String, pathExtension: String) {
self.bundle = bundle
self.name = name
self.pathExtension = pathExtension
6 changes: 3 additions & 3 deletions Library/Core/ImageResource.swift
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import Foundation
public protocol ImageResourceType {

/// Bundle this image is in
var bundle: Bundle { get }
var bundle: Bundle? { get }

/// Name of the image
var name: String { get }
@@ -21,12 +21,12 @@ public protocol ImageResourceType {
public struct ImageResource: ImageResourceType {

/// Bundle this image is in
public let bundle: Bundle
public let bundle: Bundle?

/// Name of the image
public let name: String

public init(bundle: Bundle, name: String) {
public init(bundle: Bundle?, name: String) {
self.bundle = bundle
self.name = name
}
2 changes: 1 addition & 1 deletion Library/Core/NibResource.swift
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import Foundation
public protocol NibResourceType {

/// Bundle this nib is in or nil for main bundle
var bundle: Bundle { get }
var bundle: Bundle? { get }

/// Name of the nib file on disk
var name: String { get }
2 changes: 1 addition & 1 deletion Library/Core/StoryboardResource.swift
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import Foundation
public protocol StoryboardResourceType {

/// Bundle this storyboard is in
var bundle: Bundle { get }
var bundle: Bundle? { get }

/// Name of the storyboard file on disk
var name: String { get }
6 changes: 3 additions & 3 deletions Library/Core/StringResource.swift
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public protocol StringResourceType {
var tableName: String { get }

/// Bundle this string is in
var bundle: Bundle { get }
var bundle: Bundle? { get }

/// Locales of the a localizable string
var locales: [String] { get }
@@ -36,15 +36,15 @@ public struct StringResource: StringResourceType {
public let tableName: String

/// Bundle this string is in
public let bundle: Bundle
public let bundle: Bundle?

/// Locales of the a localizable string
public let locales: [String]

/// Comment directly before and/or after the string, if any
public let comment: String?

public init(key: String, tableName: String, bundle: Bundle, locales: [String], comment: String?) {
public init(key: String, tableName: String, bundle: Bundle?, locales: [String], comment: String?) {
self.key = key
self.tableName = tableName
self.bundle = bundle