Skip to content

Commit

Permalink
refactor: emojiVersion in EmojiManager and minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
htmlprogrammist committed Jan 26, 2023
1 parent 3c1e4fe commit 14f626f
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 389 deletions.
2 changes: 1 addition & 1 deletion EmojiPicker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'EmojiPicker'
s.version = '3.0.4'
s.version = '3.0.7'
s.license = 'MIT'
s.summary = 'Emoji picker for iOS like on MacOS'
s.homepage = 'https://github.com/htmlprogrammist/EmojiPicker'
Expand Down
Binary file not shown.
6 changes: 3 additions & 3 deletions Example App/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- EmojiPicker (3.0.4)
- EmojiPicker/Tests (3.0.4)
- EmojiPicker (3.0.7)
- EmojiPicker/Tests (3.0.7)

DEPENDENCIES:
- EmojiPicker (from `../`)
Expand All @@ -11,7 +11,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
EmojiPicker: a21d785c95a64a0284b0d1472150d90c4348d5e3
EmojiPicker: 296cacb36c0eb34fe978d5411eaa06a67cd6da4b

PODFILE CHECKSUM: e686a8fbd8a5367eac0bf7fb77e0bbddf18a2353

Expand Down
4 changes: 2 additions & 2 deletions Example App/Pods/Local Podspecs/EmojiPicker.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example App/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

672 changes: 338 additions & 334 deletions Example App/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 28 additions & 35 deletions Sources/EmojiPicker/Services/EmojiManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import UIKit.UIDevice
import UIKit

/// An abstraction over entity that provides emoji set.
protocol EmojiManagerProtocol {

/// Operating System version of a device.
var deviceVersion: Double { get }

/// Gets version of iOS for current device.
///
/// - Returns: Array of emoji categories (and array of emojis inside them).
Expand All @@ -37,21 +34,41 @@ final class EmojiManager: EmojiManagerProtocol {

// MARK: - Private Properties

/// An object that decodes instances of a data type from JSON objects.
private let decoder = JSONDecoder()

/// Version of emoji set.
///
/// - Note: The value is `5` by default.
private var emojiVersion = "5"

// MARK: - Internal
private var emojiVersion: String {
switch deviceVersion {
case 12.1...13.1:
return "11"

case 13.2...14.1:
return "12.1"

case 14.2...14.4:
return "13"

case 14.5...15.3:
return "13.1"

case 15.4...:
return "14"

default:
return "5"
}
}

var deviceVersion: Double {
private var deviceVersion: Double {
return (UIDevice.current.systemVersion as NSString).doubleValue
}

// MARK: - Internal Methods

func provideEmojis() -> EmojiSet {
setEmojiVersion()

guard let path = Bundle.module.path(forResource: emojiVersion, ofType: "json"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path))
else {
Expand All @@ -65,28 +82,4 @@ final class EmojiManager: EmojiManagerProtocol {

return emojiSet
}

// MARK: - Private Methods

private func setEmojiVersion() {
switch deviceVersion {
case 12.1...13.1:
emojiVersion = "11"

case 13.2...14.1:
emojiVersion = "12.1"

case 14.2...14.4:
emojiVersion = "13"

case 14.5...15.3:
emojiVersion = "13.1"

case 15.4...:
emojiVersion = "14"

default:
emojiVersion = "5"
}
}
}
9 changes: 0 additions & 9 deletions Tests/EmojiPickerTests/EmojiManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,4 @@ class EmojiManagerTests: XCTestCase {
XCTAssertGreaterThan(result.categories.count, 0)
XCTAssertGreaterThan(result.aliases.count, 0)
}

/**
Tests that device version are identical.
*/
func testDeterminingDeviceVersion() throws {
let expectedVersion = (UIDevice.current.systemVersion as NSString).doubleValue

XCTAssertEqual(emojiManager.deviceVersion, expectedVersion)
}
}

0 comments on commit 14f626f

Please sign in to comment.