mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-01 19:46:56 +01:00
Create AppConfig module and AppLocations.
This commit is contained in:
parent
89e16f5fdd
commit
aaf8268bbd
8
AppConfig/.gitignore
vendored
Normal file
8
AppConfig/.gitignore
vendored
Normal 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
23
AppConfig/Package.swift
Normal 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"]),
|
||||
]
|
||||
)
|
46
AppConfig/Sources/AppConfig/AppLocations.swift
Normal file
46
AppConfig/Sources/AppConfig/AppLocations.swift
Normal 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
|
||||
}
|
||||
}
|
12
AppConfig/Tests/AppConfigTests/AppConfigTests.swift
Normal file
12
AppConfig/Tests/AppConfigTests/AppConfigTests.swift
Normal 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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user