Skip to content

Commit

Permalink
removed plistTitle from SFCategory and fixed mac tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rspoon3 committed Mar 22, 2023
1 parent 917f7f9 commit fbec199
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 46 deletions.
28 changes: 22 additions & 6 deletions SFSymbolsDemo/SFSymbolsDemo/Models/ContentViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import SFSymbols
class ContentViewModel: ObservableObject{
@Published var categories = [SFCategory]()

var symbols = [SFSymbol]()
private(set) var symbols = [SFSymbol]()
private var categoriesPlistDict: [String: String] = [:]
private let decoder = PropertyListDecoder()
private let bundle = Bundle.main

Expand Down Expand Up @@ -69,8 +70,10 @@ class ContentViewModel: ObservableObject{

private func createStaticVarFile(for categories: [SFCategory]) throws {
let staticVars = categories.map { category in
"""
public static let \(category.plistTitle.lowercased()) = SFCategory(icon: "\(category.icon)", title: "\(category.title)", plistTitle: "\(category.plistTitle)")
let plistTitle = categoriesPlistDict[category.title]!

return """
public static let \(plistTitle.lowercased()) = SFCategory(icon: "\(category.icon)", title: "\(category.title)", plistTitle: "\(plistTitle)")
"""
}.joined(separator: "\n")

Expand Down Expand Up @@ -133,7 +136,7 @@ class ContentViewModel: ObservableObject{
var categoriesOptionalString = "nil"
var searchTermsOptionalString = "nil"

if var categoriesString = symbol.categories?.map(\.plistTitle).map({".\($0)"}).joined(separator: ", "){
if var categoriesString = symbol.categories?.map({ categoriesPlistDict[$0.title] }).map({".\($0!)"}).joined(separator: ", "){
let i = categoriesString.index(categoriesString.startIndex, offsetBy: 0)
categoriesString.insert("[", at: i)
categoriesString.append(contentsOf: "]")
Expand Down Expand Up @@ -194,6 +197,12 @@ class ContentViewModel: ObservableObject{
let data = try! Data(contentsOf: url)

categories = try decoder.decode([SFCategory].self, from: data)

let plists = try decoder.decode([Plist].self, from: data)

for plist in plists {
categoriesPlistDict[plist.label] = plist.key
}
}

private func loadSymbols() throws {
Expand All @@ -216,9 +225,9 @@ class ContentViewModel: ObservableObject{
}

for string in categoriesStringArray {
let category = categories.first(where: {$0.plistTitle == string})!
let category = categories.first(where: {categoriesPlistDict[$0.title] == string})!

if symbols[index].categories == nil{
if symbols[index].categories == nil {
symbols[index].categories = [category]
} else {
symbols[index].categories?.append(category)
Expand Down Expand Up @@ -247,3 +256,10 @@ class ContentViewModel: ObservableObject{
}
}
}



fileprivate struct Plist: Decodable {
let key: String
let label: String
}
62 changes: 30 additions & 32 deletions Sources/SFSymbols/Models/SFCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public struct SFCategory: Identifiable, Codable, Equatable, Hashable {
public let icon: String
public let title: String
public var id: String { title }
public let plistTitle: String

public var symbols: [SFSymbol]{
if self == .all {
Expand All @@ -25,40 +24,39 @@ public struct SFCategory: Identifiable, Codable, Equatable, Hashable {
enum CodingKeys: String, CodingKey {
case icon
case title = "label"
case plistTitle = "key"
}

//MARK: Static Data
public static let all = SFCategory(icon: "square.grid.2x2", title: "All", plistTitle: "all")
public static let whatsnew = SFCategory(icon: "sparkles", title: "What’s New", plistTitle: "whatsnew")
public static let multicolor = SFCategory(icon: "paintpalette", title: "Multicolor", plistTitle: "multicolor")
public static let variablecolor = SFCategory(icon: "slider.horizontal.below.square.and.square.filled", title: "Variable Color", plistTitle: "variablecolor")
public static let communication = SFCategory(icon: "message", title: "Communication", plistTitle: "communication")
public static let weather = SFCategory(icon: "cloud.sun", title: "Weather", plistTitle: "weather")
public static let objectsandtools = SFCategory(icon: "folder", title: "Objects & Tools", plistTitle: "objectsandtools")
public static let devices = SFCategory(icon: "desktopcomputer", title: "Devices", plistTitle: "devices")
public static let cameraandphotos = SFCategory(icon: "camera", title: "Camera & Photos", plistTitle: "cameraandphotos")
public static let gaming = SFCategory(icon: "gamecontroller", title: "Gaming", plistTitle: "gaming")
public static let connectivity = SFCategory(icon: "antenna.radiowaves.left.and.right", title: "Connectivity", plistTitle: "connectivity")
public static let transportation = SFCategory(icon: "car.fill", title: "Transportation", plistTitle: "transportation")
public static let automotive = SFCategory(icon: "steeringwheel", title: "Automotive", plistTitle: "automotive")
public static let accessibility = SFCategory(icon: "figure.roll.runningpace", title: "Accessibility", plistTitle: "accessibility")
public static let privacyandsecurity = SFCategory(icon: "lock", title: "Privacy & Security", plistTitle: "privacyandsecurity")
public static let human = SFCategory(icon: "person.crop.circle", title: "Human", plistTitle: "human")
public static let home = SFCategory(icon: "house", title: "Home", plistTitle: "home")
public static let fitness = SFCategory(icon: "figure.run", title: "Fitness", plistTitle: "fitness")
public static let nature = SFCategory(icon: "leaf", title: "Nature", plistTitle: "nature")
public static let editing = SFCategory(icon: "slider.horizontal.3", title: "Editing", plistTitle: "editing")
public static let textformatting = SFCategory(icon: "textformat", title: "Text Formatting", plistTitle: "textformatting")
public static let media = SFCategory(icon: "playpause", title: "Media", plistTitle: "media")
public static let keyboard = SFCategory(icon: "command", title: "Keyboard", plistTitle: "keyboard")
public static let commerce = SFCategory(icon: "cart", title: "Commerce", plistTitle: "commerce")
public static let time = SFCategory(icon: "timer", title: "Time", plistTitle: "time")
public static let health = SFCategory(icon: "heart", title: "Health", plistTitle: "health")
public static let shapes = SFCategory(icon: "square.on.circle", title: "Shapes", plistTitle: "shapes")
public static let arrows = SFCategory(icon: "arrow.forward", title: "Arrows", plistTitle: "arrows")
public static let indices = SFCategory(icon: "a.circle", title: "Indices", plistTitle: "indices")
public static let math = SFCategory(icon: "x.squareroot", title: "Math", plistTitle: "math")
public static let all = SFCategory(icon: "square.grid.2x2", title: "All")
public static let whatsnew = SFCategory(icon: "sparkles", title: "What’s New")
public static let multicolor = SFCategory(icon: "paintpalette", title: "Multicolor")
public static let variablecolor = SFCategory(icon: "slider.horizontal.below.square.and.square.filled", title: "Variable Color")
public static let communication = SFCategory(icon: "message", title: "Communication")
public static let weather = SFCategory(icon: "cloud.sun", title: "Weather")
public static let objectsandtools = SFCategory(icon: "folder", title: "Objects & Tools")
public static let devices = SFCategory(icon: "desktopcomputer", title: "Devices")
public static let cameraandphotos = SFCategory(icon: "camera", title: "Camera & Photos")
public static let gaming = SFCategory(icon: "gamecontroller", title: "Gaming")
public static let connectivity = SFCategory(icon: "antenna.radiowaves.left.and.right", title: "Connectivity")
public static let transportation = SFCategory(icon: "car.fill", title: "Transportation")
public static let automotive = SFCategory(icon: "steeringwheel", title: "Automotive")
public static let accessibility = SFCategory(icon: "figure.roll.runningpace", title: "Accessibility")
public static let privacyandsecurity = SFCategory(icon: "lock", title: "Privacy & Security")
public static let human = SFCategory(icon: "person.crop.circle", title: "Human")
public static let home = SFCategory(icon: "house", title: "Home")
public static let fitness = SFCategory(icon: "figure.run", title: "Fitness")
public static let nature = SFCategory(icon: "leaf", title: "Nature")
public static let editing = SFCategory(icon: "slider.horizontal.3", title: "Editing")
public static let textformatting = SFCategory(icon: "textformat", title: "Text Formatting")
public static let media = SFCategory(icon: "playpause", title: "Media")
public static let keyboard = SFCategory(icon: "command", title: "Keyboard")
public static let commerce = SFCategory(icon: "cart", title: "Commerce")
public static let time = SFCategory(icon: "timer", title: "Time")
public static let health = SFCategory(icon: "heart", title: "Health")
public static let shapes = SFCategory(icon: "square.on.circle", title: "Shapes")
public static let arrows = SFCategory(icon: "arrow.forward", title: "Arrows")
public static let indices = SFCategory(icon: "a.circle", title: "Indices")
public static let math = SFCategory(icon: "x.squareroot", title: "Math")

public static var allCategories: [SFCategory] {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ public extension SFSymbol {
searchTerms: ["passkey", "password", "people", "privacyandsecurity", "user"],
releaseInfo: ReleaseInfo(iOS: 15.4, macOS: 12.3, tvOS: 15.4, watchOS: 8.5)
)
}
}
16 changes: 9 additions & 7 deletions Tests/SFSymbolsTests/SFSymbolsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import SwiftUI
@testable import SFSymbols

final class SFSymbolsTests: XCTestCase {
#if canImport(UIKit)
func testAllSymbolsExist() {
for symbol in SFSymbol.allSymbols {
let image = UIImage(systemName: symbol.title)
XCTAssert(image != nil, "\(symbol.title) does not exist!")
}
}
#endif

func testAllSymbolsAreUnique(){
let regularArray = SFSymbol.allSymbols
Expand All @@ -33,31 +35,31 @@ final class SFSymbolsTests: XCTestCase {
XCTAssertEqual(SFSymbol.allSymbols14P2.count, 96)
}

if #available(iOS 14.5, *) {
if #available(iOS 14.5, macOS 11.3, *) {
XCTAssertEqual(SFSymbol.allSymbols14P5.count, 31)
}

if #available(iOS 15.0, *) {
if #available(iOS 15.0, macOS 12.0, *) {
XCTAssertEqual(SFSymbol.allSymbols15.count, 835)
}

if #available(iOS 15.1, *) {
if #available(iOS 15.1, macOS 12.0, *) {
XCTAssertEqual(SFSymbol.allSymbols15P1.count, 13)
}

if #available(iOS 15.2, *) {
if #available(iOS 15.2, macOS 12.1, *) {
XCTAssertEqual(SFSymbol.allSymbols15P2.count, 15)
}

if #available(iOS 15.4, *) {
if #available(iOS 15.4, macOS 12.3, *) {
XCTAssertEqual(SFSymbol.allSymbols15P4.count, 7)
}

if #available(iOS 16.0, *) {
if #available(iOS 16.0, macOS 13.0, *) {
XCTAssertEqual(SFSymbol.allSymbols16.count, 932)
}

if #available(iOS 16.1, *) {
if #available(iOS 16.1, macOS 13.0, *) {
XCTAssertEqual(SFSymbol.allSymbols16P1.count, 373)
}
}
Expand Down

0 comments on commit fbec199

Please sign in to comment.