Skip to content

Commit

Permalink
Update to Swift 5.9 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
codyrobb authored Jan 5, 2024
1 parent 53353ef commit b1c8b5e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
17 changes: 16 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "Phrase"
name: "Phrase",
products: [
.library(
name: "Phrase",
targets: ["Phrase"]),
],
targets: [
.target(
name: "Phrase",
dependencies: []),
.testTarget(
name: "PhraseTests",
dependencies: ["Phrase"]),
]
)
7 changes: 3 additions & 4 deletions Phrase.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Pod::Spec.new do |spec|
spec.name = 'Phrase'
spec.version = '2.0.0'
spec.version = '3.0.0'
spec.license = { :type => 'Apache License, Version 2.0' }
spec.homepage = 'https://github.com/codyrobb/Phrase'
spec.authors = { 'Cody Robertson' => '[email protected]' }
spec.summary = 'A Swift templating library.'
spec.source = { :git => 'https://github.com/codyrobb/Phrase.git', :tag => '2.0.0' }
spec.source = { :git => 'https://github.com/codyrobb/Phrase.git', :tag => '3.0.0' }
spec.source_files = 'Sources/*'

spec.ios.deployment_target = '9.0'
spec.osx.deployment_target = '10.10'
spec.ios.deployment_target = '14.0'
end
37 changes: 16 additions & 21 deletions Sources/Phrase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@

import Foundation


final public class Phrase {

// MARK: -
// MARK: Properties

/**
The template we will attempt to replace tokens of.
*/
/// The template we will attempt to replace tokens of.
private let template: String

/**
The set of token replacements to be replaced in the template.
*/
private var replacements: [String: String] = [:]
/// The set of token replacements to be replaced in the template.
private var replacements: [String : String] = [:]

// MARK: -
// MARK: Initialization
Expand All @@ -35,22 +30,22 @@ final public class Phrase {
// MARK: Public

/**
Adds a record to replace the tokenized key with the given value in the template.

- Parameters:
- key: The key you want to replace.
- value: The value to replace the key with.
- Returns: Returns itself for easy chaining.
* Adds a record to replace the tokenized key with the given value in the template.
*
* - Parameters:
* - key: The key you want to replace.
* - value: The value to replace the key with.
*/
@discardableResult
public func put(key: String, value: CustomStringConvertible) -> Phrase {
replacements[key] = value.description
return self
}

/**
Returns a formatted string by attempting to replace all tokens with their respective values.

- Returns: A formatted string with all current replacements.
* Returns a formatted string by attempting to replace all tokens with their respective values.
*
* - Returns: A formatted string with all current replacements.
*/
public func format() -> String {
var formatted = template
Expand All @@ -66,10 +61,10 @@ final public class Phrase {
// MARK: Private

/**
Tokenizes the given key.

- Parameter key: The key you want to tokenize.
- Returns: A tokenized version of the key.
* Tokenizes the given key.
*
* - Parameter key: The key you want to tokenize.
* - Returns: A tokenized version of the key.
*/
private func tokenize(key: String) -> String {
return "{" + key + "}"
Expand Down

0 comments on commit b1c8b5e

Please sign in to comment.