Create AppConfig module and AppLocations.

This commit is contained in:
Brent Simmons 2024-06-26 23:10:59 -07:00
parent 89e16f5fdd
commit aaf8268bbd
4 changed files with 89 additions and 0 deletions

8
AppConfig/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

23
AppConfig/Package.swift Normal file
View File

@ -0,0 +1,23 @@
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
name: "AppConfig",
products: [
.library(
name: "AppConfig",
targets: ["AppConfig"]),
],
targets: [
.target(
name: "AppConfig",
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "AppConfigTests",
dependencies: ["AppConfig"]),
]
)

View File

@ -0,0 +1,46 @@
//
// AppLocations.swift
// NetNewsWire
//
// Created by Brent Simmons on 6/26/24.
// Copyright © 2024 Ranchero Software. All rights reserved.
//
import Foundation
@MainActor public final class AppLocations {
private static var cacheFolder: URL = {
let folderURL: URL
if let userCacheFolder = try? FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true) {
folderURL = userCacheFolder
} else {
let bundleIdentifier = (Bundle.main.infoDictionary!["CFBundleIdentifier"]! as! String)
let tempFolder = (NSTemporaryDirectory() as NSString).appendingPathComponent(bundleIdentifier)
folderURL = URL(fileURLWithPath: tempFolder, isDirectory: true)
try! FileManager.default.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil)
}
return folderURL
}()
public static var faviconsFolder: URL = {
return createSubfolder(named: "Favicons", in: cacheFolder)
}()
public static var imagesFolder: URL = {
return createSubfolder(named: "Images", in: cacheFolder)
}()
}
private extension AppLocations {
static func createSubfolder(named subfolderName: String, in folderURL: URL) -> URL {
let folder = folderURL.appendingPathComponent(subfolderName, isDirectory: true)
try! FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true, attributes: nil)
return folder
}
}

View File

@ -0,0 +1,12 @@
import XCTest
@testable import AppConfig
final class AppConfigTests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest
// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
}