Swiftpack.co - VakhoKontridze/VCore as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by VakhoKontridze.
VakhoKontridze/VCore 6.0.1
VCore is a Swift collection containing objects, functions, and extensions that I use in my projects
⭐️ 46
🕓 6 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/VakhoKontridze/VCore.git", from: "6.0.1")

VCore

Table of Contents

Description

VCore is a Swift collection containing objects, functions, and extensions that I use for my projects.

Structure

Package files are grouped as:

  • Services and Managers. Services, managers, and controllers. For instance, MultiPartFormDataBuilder.

  • Views. Views, UIViews, and UIViewControllers. For instance, SwiftUIBaseButton.

  • Models. Models. For instance, GenericStates and GenericStateModels.

  • Helpers. Helper objects and methods. For instance, architectural pattern helpers.

  • Extensions. Extensions.

  • Global Functions. Global functions. For instance, FIXME(_:) and TODO(_:).

  • Macros. Macros. For instance, url(_:).

  • API. Objects used for interfacing from you app/package with VCore. For instance, VCoreLocalizationManager.

Package incudes folder Extra, which contains:

  • XCode Templates. Templates that can be used for accelerating workflow. Currently, templates cover scenes and gateways. For additional info, refer to documentation folder.

Project includes folder Documentation, which contains:

  • Swift style guide

  • Documentation and example apps of various SwiftUI/UIKit architectures

  • Documentation of networking

Showcase

Multipart/Form-Data Builder

MultipartFormDataBuilder with a Dictionary-based file API:

let json: [String: Any?] = [
    "key": "value"
]

let files: [String: (some AnyMultipartFormDataFile)?] = [
    "profile": MultipartFormDataFile(
        mimeType: "image/jpeg",
        data: profileImage?.jpegData(compressionQuality: 0.25)
    ),

    "gallery": galleryImages?.enumerated().compactMap { (index, image) in
        MultipartFormDataFile(
            filename: "IMG_\(index).jpg",
            mimeType: "image/jpeg",
            data: image?.jpegData(compressionQuality: 0.25)
        )
    }
]

let (boundary, httpData): (String, Data) = try MultipartFormDataBuilder().build(
    json: json,
    files: files
)

let url: URL = #url("https://somewebsite.com/api/some_endpoint")

var request: URLRequest = .init(url: url)
request.httpMethod = "POST"
try request.addHTTPHeaderFields(object: MultipartFormDataAuthorizedRequestHeaderFields(
    boundary: boundary,
    token: "token"
))
request.httpBody = httpData.nonEmpty

let (data, response): (Data, URLResponse) = try await URLSession.shared.data(for: request)

...

Localization Manager

LocalizationManager that manages localizations without interacting with raw Strings:

extension Locale {
    static var english: Self { .init(identifier: "en") }
    static var english_uk: Self { .init(identifier: "en-GB") }
    static var spanish: Self { .init(identifier: "es") }
}

LocalizationManager.shared.addLocales([.english, .english_uk, .spanish])
LocalizationManager.shared.setDefaultLocale(to: .english)
LocalizationManager.shared.setCurrentLocale(to: .english)
let lhs: Locale = .init(identifier: "en")
let rhs: Locale = .init(identifier: "en-US")

lhs == rhs // false

lhs.isEquivalent(to: rhs) // true, if `Locale.current.regionCode` is "US"

Keychain Service

KeychainService that supports custom queries, and has a dedicated property wrapper:

KeychainService.default.get(key: "SomeKey")
KeychainService.default.set(key: "SomeKey", data: data)
KeychainService.default.delete(key: "SomeKey")
@KeychainStorage("AccessToken") var accessToken: String?

Various Services and Managers

DigitalTimeFormatter with various configurations:

let formatter: DigitalTimeFormatter = .init()
formatter.string(from: 905048) // "10:11:24:08"

Various SwiftUI Views

AlignedGridLayout that justifies collection of views with an alignment:

private let strings: [String] = [
    "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday",
    "Sunday"
]

var body: some View {
    AlignedGridLayout(alignment: .center, spacing: 5).callAsFunction({
        ForEach(strings, id: \.self, content: { string in
            Text(string)
                .background(content: { Color.accentColor.opacity(0.5) })
        })
    })
    .padding()
}

Various UIKit UIViews/UIViewControllers

KeyboardResponsiveUIViewController that handles keyboard notifications:

final class ViewController: KeyboardResponsiveUIViewController {
    private let textField: UITextField = ...

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addsupview(textField)

        NSLayoutConstraint.activate([
            ...
        ])
    }

    override func keyboardWillShow(_ systemKeyboardInfo: SystemKeyboardInfo) {
        super.keyboardWillShow(systemKeyboardInfo)

        UIView.animateKeyboardResponsiveness(
            systemKeyboardInfo: systemKeyboardInfo,
            animations: { [weak self] in
                guard let self else { return }
                
                guard let systemKeyboardHeight: CGFloat = systemKeyboardInfo.frame?.size.height else { return }

                view.bounds.origin.y = systemKeyboardHeight
                view.superview?.layoutIfNeeded()
            }
        )
    }

    override func keyboardWillHide(_ systemKeyboardInfo: SystemKeyboardInfo) {
        super.keyboardWillHide(systemKeyboardInfo)

        UIView.animateKeyboardResponsiveness(
            systemKeyboardInfo: systemKeyboardInfo,
            animations: { [weak self] in
                guard let self else { return }

                view.bounds.origin.y = 0
                view.superview?.layoutIfNeeded()
            }
        )
    }
}

Various Declarations

KeyPathInitializableEnumeration that allows for initialization of an enum with a KeyPath:

enum SomeEnum: KeyPathInitializableEnumeration {
    case first
    case second

    var someProperty: Int {
        switch self {
        case .first: 1
        case .second: 2
        }
    }
}

let value: SomeEnum? = .aCase(key: \.someProperty, value: 2)

Various Extensions

Retrieving CGSize form View:

@State private var size: CGSize = .zero

var body: some View {
    VStack(content: {
        Color.accentColor
            .getSize({ size = $0 })
    })
}

Global Functions

Function that calls fatalError because feature is not implemented:

func didTapContinueButton() {
    TODO()
}

Various Macros

Macro that adds CodingKeys to a declaration:

@CodingKeysGeneration
struct GetPostEntity: Decodable {
    @CKGCodingKey("id") let id: Int
    @CKGCodingKey("userId") let userID: Int
    @CKGCodingKey("title") let title: String
    @CKGCodingKey("body") let body: String
    
    @CKGCodingKeyIgnored var attributes: [String: Any?] = [:]
}

// Generates
internal enum CodingKeys: String, CodingKey {
    case id = "id"
    case userID = "userId"
    case title = "title"
    case body = "body"
}

Installation

Swift Package Manager

Add https://github.com/VakhoKontridze/VCore as a Swift Package in Xcode and follow the instructions.

Compatibility

Platform and Version Support

Package provides limited macOS, tvOS, watchOS, and visionOS support.

Versions with different majors are not directly compatible. When a new major is released, deprecated symbols are removed.

Versioning

Major. Major changes, such as big overhauls

Minor. Minor changes, such as new objects, functions, and extensions

Patch. Bug fixes and improvements

History

Version Release Date Swift SDK Comment
6.0 2024 02 18 5.10
(6.0.1 - 6.x.x)
5.9
(6.0.0)
iOS 15.0
macOS 12.0
tvOS 15.0
watchOS 8.0
visionOS 1.0
visionOS support.
API changes.
5.0 2023 10 08 5.9 iOS 15.0
macOS 12.0
tvOS 15.0
watchOS 8.0
New SDK.
API changes.
4.0 2022 09 14 5.8
(4.7.0 - 4.x.x)
5.7
(4.0.0 - 4.6.1)
iOS 13.0
macOS 10.15
tvOS 13.0
watchOS 6.0
API changes.
3.0 2022 05 17 5.6 iOS 13.0
macOS 10.15
tvOS 13.0
watchOS 6.0
Multiplatform support.
SPM support.
2.0 2021 12 28 5.3 iOS 13.0 iOS 13.0 support.
1.0 2021 10 07 5.3 iOS 14.0 -

For additional info, refer to the CHANGELOG.

Contact

e-mail: [email protected]

GitHub

link
Stars: 46
Last commit: 18 minutes ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

6.0.1
6 weeks ago

Refer to the CHANGELOG.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics