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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mac-cain13/R.swift.Library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: interfacebuilder/R.swift.Library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 6, 2018

  1. Copy the full SHA
    9de2c94 View commit details
  2. Copy the full SHA
    267afd4 View commit details

Commits on Apr 7, 2018

  1. Copy the full SHA
    2ddf4bd View commit details
Showing with 38 additions and 6 deletions.
  1. +30 −6 Library/Core/ImageResource.swift
  2. +8 −0 R.swift.Library.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
36 changes: 30 additions & 6 deletions Library/Core/ImageResource.swift
Original file line number Diff line number Diff line change
@@ -10,24 +10,48 @@
import Foundation

public protocol ImageResourceType {

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

/// Name of the image
var name: String { get }
}

public struct ImageResource: ImageResourceType {

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

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

public init(bundle: Bundle, name: String) {
self.bundle = bundle
self.name = name
self.name = ImageResource.existsImageResource(forImageNamed: name)
}

// 画像名-Locale.current.languageCode のフォーマットで画像があるかどうかを確認。
// 画像がなければ引数を返し、あればそちらを使う
static func existsImageResource(forImageNamed name: String) -> String {

let languageCode = Locale.current.languageCode ?? ""
let localedName = "\(name)-\(languageCode)"

let fileManager = FileManager.default
let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0]
let url = cacheDirectory.appendingPathComponent("\(localedName).png")
let path = url.path

guard fileManager.fileExists(atPath: path) else {
guard let image = UIImage(named: localedName), let data = UIImagePNGRepresentation(image) else {
return name
}
fileManager.createFile(atPath: path, contents: data, attributes: nil)
return localedName
}
return localedName
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>