Skip to content

Commit

Permalink
Merge pull request #1 from boardbookit/release-2.1
Browse files Browse the repository at this point in the history
Release 2.1
  • Loading branch information
Rspoon3 authored Mar 20, 2022
2 parents c29af3c + 6825ae4 commit fdcd15b
Show file tree
Hide file tree
Showing 56 changed files with 19,214 additions and 22,636 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# Change Log
## Version 2.1 (3-20-2022)
### Additions
- Added UIAction extension
- Created a Mac app for the preview application
- Added better search support for preview app
- Small README updates

### Fixes
- Removed iOS 15 limitation for filter common name
- Now separating static vars into multiple files so Xcode doesn't crash from one giant file.

### Notes
- Simplified package updating process

-----
## Version 2.0.0 (1-14-2022)
### Additions
- Updated for SFSymbols App Version 3.2
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SFSymbols
[![Build Status](https://travis-ci.org/Nirma/SFSymbol.svg?branch=master)](https://travis-ci.org/Nirma/SFSymbol)
![Swift 5.5](https://img.shields.io/badge/Swift-5.5-orange.svg)
![Swift 5.6](https://img.shields.io/badge/Swift-5.6-orange.svg)
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-purple.svg)](https://github.com/apple/swift-package-manager)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)

Expand Down Expand Up @@ -45,7 +45,7 @@ public extension SFSymbol{
}
```

There are extensions for `UIImage`, `Image`, `Button`, and `Label` that enable easy use of any `SFSymbol`.
Additionally, there are extensions multiple extension including `UIImage`, `Image`, `Button`, `Label`, and `UIAction` that enable easy use of any `SFSymbol`.


### UIKit
Expand Down Expand Up @@ -85,21 +85,17 @@ VStack{
```
## About
SFSymbols are a real treat from apple. Apple's official list of Symbols that are available to use free of charge when writing software on any of Apple's recent platforms. There is one downfall however, it is a pain in the neck to look up exact symbol names, take for example:

`"square.and.line.vertical.and.square.fill"`

That is a long string to remember and digging through the catalog of SF Symbols to find in would be quite a waste of time.
[SFSymbols](https://developer.apple.com/sf-symbols/) are a real treat from Apple. The one downfall however, it is a pain in the neck to look up exact symbol names. Take for example: `"square.and.line.vertical.and.square.fill"`. That is a long string to remember and digging through the catalog of SF Symbols over and over gets tiresome.

Wouldn't it be easier if you could just use code completion?

![](https://media.giphy.com/media/jQ7lTLsv2poo2qLkUA/giphy.gif)

Thats what this super micro library aims to do.
Thats what this micro library aims to do. Additionally, this library includes relevant information on each symbol such as release info, category, and relevant search terms.

## Installation

### Swift Package Manager (Preferred)
### Swift Package Manager
Since Xcode integrated swift package manager natively into the IDE you can add SFSymbol simply by:

**`File`-> `Swift Packages` -> `Add Package Dependency...`**
Expand All @@ -119,10 +115,9 @@ Don't want that additional third party dependency? Then just simply copy over th
Thanks to [Nirma](https://github.com/Nirma) for the idea. This project was highly influence and based off of his [SFSymbol](https://github.com/Nirma/SFSymbol) package. I found that few things I would do differently and before I knew it, I had an offshoot of what he had already done that went in a different direction.

## Contributing to this project
**Contributions are highly welcome**

If there is something you wish to fix about the project, or wish to add any other kind of enhancements, propose to add to the project. Please feel free to send over a pull request
or open an issue for this project. Check out [SFSymbolsCreator](https://github.com/Rspoon3/SFSymbolCreator) for easily updating this project files.
or open an issue for this project.

## License

Expand Down
441 changes: 306 additions & 135 deletions SFSymbolsPreview/SFSymbolsPreview.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions SFSymbolsPreview/SFSymbolsPreview/Views/SymbolList.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ContentView: View {
}
#else
AppSidebarNavigation()
.frame(minWidth: 900, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity)
.frame(minWidth: 600, maxWidth: .infinity, minHeight: 400, maxHeight: .infinity)
#endif
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ class ContentViewModel: ObservableObject{
var symbols = [SFSymbol]()
private let decoder = PropertyListDecoder()
private let bundle = Bundle.main
private let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]


#if os(iOS)
private let directory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
#elseif os(macOS)
private var directory = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
#endif


//MARK: Initializer
init(){
Expand All @@ -25,57 +30,74 @@ class ContentViewModel: ObservableObject{
try loadSymbols()
try loadSymbolCategories()
try loadSearchTerms()
try createStaticVarFile()
try createMacFolder()

let symbols13 = symbols.filter({$0.releaseInfo.iOS == 13})
let symbols14 = symbols.filter({$0.releaseInfo.iOS == 14})
let symbols14P2 = symbols.filter({$0.releaseInfo.iOS == 14.2})
let symbols14P5 = symbols.filter({$0.releaseInfo.iOS == 14.5})
let symbols15 = symbols.filter({$0.releaseInfo.iOS == 15})
let symbols15P1 = symbols.filter({$0.releaseInfo.iOS == 15.1})
let symbols15P2 = symbols.filter({$0.releaseInfo.iOS == 15.2})

try createAllSymbolsFile(symbols: symbols13, extensionName: "All13", variableName: "allSymbols13", iOSVersion: 13)
try createAllSymbolsFile(symbols: symbols14, extensionName: "All14", variableName: "allSymbols14", iOSVersion: 14)
try createAllSymbolsFile(symbols: symbols14P2, extensionName: "All14P2", variableName: "allSymbols14P2", iOSVersion: 14.2)
try createAllSymbolsFile(symbols: symbols14P5, extensionName: "All14P5", variableName: "allSymbols14P5", iOSVersion: 14.5)
try createAllSymbolsFile(symbols: symbols15, extensionName: "All15", variableName: "allSymbols15", iOSVersion: 15)
try createAllSymbolsFile(symbols: symbols15P1, extensionName: "All15P1", variableName: "allSymbols15P1", iOSVersion: 15.1)
try createAllSymbolsFile(symbols: symbols15P2, extensionName: "All15P2", variableName: "allSymbols15P2", iOSVersion: 15.2)

let iOSVersions = Set(symbols.map(\.releaseInfo.iOS)).sorted()

for version in iOSVersions {
let symbols = symbols.filter{$0.releaseInfo.iOS == version}
var fileName = version.description.replacingOccurrences(of: ".0", with: "")
fileName = fileName.replacingOccurrences(of: ".", with: "P")

try createStaticVarFile(for: symbols, fileName: fileName)
try createAllSymbolsFile(for: symbols, fileName: fileName)
}

#if os(iOS)
print("Finished creating the swift files. They can be found in the `Files` app.")
#elseif os(macOS)
print("Finished creating the swift files. They can be found your downloads folder.")
#endif

print("Don't forget to update the package 'SFSymbol+All' files.")
} catch{
print("ERROR: \(error)")
}
}


//MARK: Private Helpers
private func createStaticVarFile() throws{
var staticVars = symbols.map({convertSymbolToStaticVar($0)}).joined(separator: "\n\n")
private func createMacFolder() throws{
#if os(macOS)
let appTitle = Bundle.main.infoDictionary![kCFBundleNameKey as String] as! String
directory = directory.appendingPathComponent(appTitle)
try FileManager.default.createDirectory(atPath: directory.path, withIntermediateDirectories: true)
#endif
}

private func createStaticVarFile(for symbols: [SFSymbol], fileName: String) throws{
let newestSymbol = symbols.first!
let header = """
import Foundation
@available(iOS \(newestSymbol.releaseInfo.iOS), macOS \(newestSymbol.releaseInfo.macOS), tvOS \(newestSymbol.releaseInfo.tvOS), watchOS \(newestSymbol.releaseInfo.watchOS), *)
public extension SFSymbol {
"""

var staticVars = symbols.map{convertSymbolToStaticVar($0)}.joined(separator: "\n\n")
let i = staticVars.index(staticVars.startIndex, offsetBy: 0)
staticVars.insert(contentsOf: "import Foundation\n\n\npublic extension SFSymbol {\n", at: i)
staticVars.insert(contentsOf: header, at: i)
staticVars.append("\n}")

let url = documentsDirectory.appendingPathComponent("SFSymbol+StaticVariables.swift")

let url = directory.appendingPathComponent("SFSymbol+StaticVariables\(fileName).swift")
try staticVars.write(to: url, atomically: true, encoding: .utf8)
}

private func createAllSymbolsFile(symbols: [SFSymbol], extensionName: String, variableName: String, iOSVersion: Double) throws{
private func createAllSymbolsFile(for symbols: [SFSymbol], fileName: String) throws{
let titles = symbols.map({convertTitleToCamelCased(string: $0.title)}).map({" .\($0)"}).joined(separator: ",\n")

var array = """
\n
static var \(variableName): [SFSymbol] {
static var allSymbols\(fileName): [SFSymbol] {
return [\n
"""

array.append(contentsOf: titles)
array.append(contentsOf: "\n ]")


let newestSymbol = symbols.first(where: {$0.releaseInfo.iOS == iOSVersion})!
let newestSymbol = symbols.first!
let header = """
import Foundation
Expand All @@ -86,18 +108,18 @@ class ContentViewModel: ObservableObject{
let i = titles.index(titles.startIndex, offsetBy: 0)
array.insert(contentsOf: header, at: i)
array.append("\n }\n}")
let url = documentsDirectory.appendingPathComponent("SFSymbol+\(extensionName).swift")

let url = directory.appendingPathComponent("SFSymbol+All\(fileName).swift")

try array.write(to: url, atomically: true, encoding: .utf8)
}

private func convertSymbolToStaticVar(_ symbol: SFSymbol) -> String{
let camelCased = convertTitleToCamelCased(string: symbol.title)

var categoriesOptionalString = "nil"
var searchTermsOptionalString = "nil"

if var categoriesString = symbol.categories?.map(\.title).map({".\($0)"}).joined(separator: ", "){
let i = categoriesString.index(categoriesString.startIndex, offsetBy: 0)
categoriesString.insert("[", at: i)
Expand All @@ -117,11 +139,10 @@ class ContentViewModel: ObservableObject{


let staticVar = """
@available(iOS \(symbol.releaseInfo.iOS), macOS \(symbol.releaseInfo.macOS), tvOS \(symbol.releaseInfo.tvOS), watchOS \(symbol.releaseInfo.watchOS), *)
static let \(camelCased) = SFSymbol(title: "\(symbol.title)",
categories: \(categoriesOptionalString),
searchTerms: \(searchTermsOptionalString),
releaseInfo: ReleaseInfo(iOS: \(symbol.releaseInfo.iOS), macOS: \(symbol.releaseInfo.macOS), tvOS: \(symbol.releaseInfo.tvOS), watchOS: \(symbol.releaseInfo.watchOS)))
categories: \(categoriesOptionalString),
searchTerms: \(searchTermsOptionalString),
releaseInfo: ReleaseInfo(iOS: \(symbol.releaseInfo.iOS), macOS: \(symbol.releaseInfo.macOS), tvOS: \(symbol.releaseInfo.tvOS), watchOS: \(symbol.releaseInfo.watchOS)))
"""

return staticVar
Expand Down Expand Up @@ -165,7 +186,7 @@ class ContentViewModel: ObservableObject{

symbols = localizedRemovedSymbols
}

private func loadSymbolCategories() throws{
let url = bundle.url(forResource: "symbol_categories", withExtension: "plist")!
let data = try Data(contentsOf: url)
Expand All @@ -178,7 +199,7 @@ class ContentViewModel: ObservableObject{

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

if symbols[index].categories == nil{
symbols[index].categories = [category]
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct CategoriesList: View {
}
}
.navigationTitle("Categories")
.searchable(text: $searchText)
.searchable(text: $searchText, placement: .sidebar)
.animation(.default, value: searchText)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ struct InitialDetailsView: View{
}
.textCase(nil)
}
.searchable(text: $searchText)
.searchable(text: $searchText, placement: .sidebar)
.navigationTitle("Symbols")
.animation(.default, value: searchText)
}
}

Expand Down
51 changes: 51 additions & 0 deletions SFSymbolsPreview/iOS/Views/SymbolList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SymbolList.swift
// SFSymbolsPreview
//
// Created by Richard Witherspoon on 11/18/21.
//

import SwiftUI
import SFSymbols


struct SymbolList: View{
let category: SFCategory
@State private var searchText = String()

init(category: SFCategory) {
self.category = SFCategory.allCategories.first(where: {$0.plistTitle == category.title})!
}

func searchResults()->[SFSymbol]{
if searchText.isEmpty{
return category.symbols
}

return category.symbols.filter({
$0.title.localizedCaseInsensitiveContains(searchText) ||
$0.searchTerms?.contains(where: {$0.localizedCaseInsensitiveContains(searchText)}) ?? false
})
}


var body: some View{
List(searchResults()){ symbol in
Label(symbol.title, systemImage: symbol.title)
}
.navigationTitle(category.title)
.animation(.default, value: searchText)
#if os(iOS)
.searchable(text: $searchText, placement: .navigationBarDrawer)
#elseif os(macOS)
.searchable(text: $searchText)
#endif
}
}


struct SymbolList_Previews: PreviewProvider {
static var previews: some View {
SymbolList(category: .whatsnew)
}
}
File renamed without changes.
5 changes: 5 additions & 0 deletions SFSymbolsPreview/macOS/SFSymbolsPreview--macOS--Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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/>
</plist>
10 changes: 10 additions & 0 deletions SFSymbolsPreview/macOS/macOS.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
</dict>
</plist>
Loading

0 comments on commit fdcd15b

Please sign in to comment.