Skip to content

Commit

Permalink
SwiftHelpers v0.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
leoho0722 committed Apr 19, 2024
1 parent 1897549 commit d6c0c22
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 288 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
"../../build-documentation.sh"
],
resources: [
.copy("Sources/SwiftHelpers/PrivacyInfo/PrivacyInfo.xcprivacy")
.copy("./PrivacyInfo.xcprivacy")
],
linkerSettings: [
.linkedFramework("SwiftUI"),
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Use Swift to create some amazing things!

## Package Development Environment

* macOS Sonoma 14.3 (23D56)
* Xcode 15.2 (15C500b)
* macOS Sonoma 14.4.1 (23E224)
* Xcode 15.3 (15E204a)
* Swift 5.9.2 (5.9.2.2.56)

## Install
Expand All @@ -37,12 +37,12 @@ import Foundation
import SwiftHelpers

func createURLRequest<E>(with url: URL,
method: HTTP.HTTPMethod,
method: HTTP.Method,
parameters: E) -> URLRequest where E: Encodable {
var request = URLRequest(url: url)
request.httpMethod = method.rawValue
request.allHTTPHeaderFields = [
HTTP.HTTPHeaderFields.contentType.rawValue : HTTP.HTTPContentType.json.rawValue
HTTP.HeaderFields.contentType.rawValue : HTTP.ContentType.json.rawValue
]

if method != .get {
Expand Down
23 changes: 0 additions & 23 deletions Sources/SwiftHelpers/Extensions/SwiftUI/Image+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,5 @@ public extension Image {

public extension Image {

/// Use ``SFSymbols`` to initialize `Image`
@available(
*,
deprecated,
renamed: "init(symbols:)",
message: "Deprecated since version 0.0.9, renamed to init(symbols:) and will be removed in a future version"
)
init(systemIcon: SFSymbols) {
self.init(systemName: systemIcon.rawValue)
}

/// Use ``SFSymbols`` to initialize `Image`
///
/// This initializer is available in iOS 16.0 and macOS 13.0 or above
@available(iOS 16.0, macOS 13.0, *)
@available(
*,
deprecated,
renamed: "init(symbols:variableValue:)",
message: "Deprecated since version 0.0.9, renamed to init(symbols:variableValue:) and will be removed in a future version"
)
init(systemIcon: SFSymbols, variableValue: Double?) {
self.init(systemName: systemIcon.rawValue, variableValue: variableValue)
}
}
20 changes: 0 additions & 20 deletions Sources/SwiftHelpers/Extensions/SwiftUI/Label+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,5 @@ public extension Label where Title == Text, Icon == Image {

public extension Label where Title == Text, Icon == Image {

/// Use ``SFSymbols`` and `LocalizedStringKey` to initialize `Label`
@available(
*,
deprecated,
renamed: "init(_:symbols:)",
message: "Deprecated since version 0.0.9, renamed to init(symbols:) and will be removed in a future version"
)
init(_ titleKey: LocalizedStringKey, systemIcon name: SFSymbols) {
self.init(titleKey, systemImage: name.rawValue)
}

/// Use ``SFSymbols`` and `String` to initialize `Label`
@available(
*,
deprecated,
renamed: "init(_:symbols:)",
message: "Deprecated since version 0.0.9, renamed to init(symbols:) and will be removed in a future version"
)
init<S>(_ title: S, systemIcon name: SFSymbols) where S : StringProtocol {
self.init(title, systemImage: name.rawValue)
}
}
11 changes: 1 addition & 10 deletions Sources/SwiftHelpers/Extensions/UIKit/UIImage+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ public extension UIImage {

public extension UIImage {

/// Use ``SFSymbols`` to initialize `UIImage`
@available(
*,
deprecated,
renamed: "init(symbols:)",
message: "Deprecated since version 0.0.9, renamed to init(symbols:) and will be removed in a future version"
)
convenience init?(systemIcon: SFSymbols) {
self.init(systemName: systemIcon.rawValue)
}

}
#endif
38 changes: 38 additions & 0 deletions Sources/SwiftHelpers/Network/HTTP/ContentType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ContentType.swift
// SwiftHelpers/Network
//
// Created by Leo Ho on 2023/6/14.
//

import Foundation

public extension HTTP {

/// Define the HTTP Content-Type of the HTTP Request
enum ContentType: String, CustomStringConvertible {

/// HTTP Request body Content-Type,JSON
case json = "application/json"

/// HTTP Request body Content-Type,XML
case xml = "application/xml"

/// HTTP Request body Content-Type,text/plain
case textPlain = "text/plain"

/// HTTP Request body Content-Type,x-www-form-urlencoded
case x_www_form_urlencoded = "application/x-www-form-urlencoded"

/// HTTP Request body Content-Type,multipart/form-data
case formData = "multipart/form-data"

/// HTTP Request body Content-Type,application/octet-stream
case octetStream = "application/octet-stream"

public var description: String {
let base = "[HTTP Content-Type] "
return base + self.rawValue
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import Foundation
public extension HTTP {

/// Define the HTTP Header Fields of the HTTP Request request
enum HTTPHeaderFields: String, CustomStringConvertible {
enum HeaderFields: String, CustomStringConvertible {

/// HTTP Request's HeaderFields,Authorization
/// HTTP Request HeaderFields,Authorization
case authentication = "Authorization"

/// HTTP Request's HeaderFields, Content-Type
/// HTTP Request HeaderFields, Content-Type
case contentType = "Content-Type"

/// HTTP Request's HeaderFields,Accept
/// HTTP Request HeaderFields,Accept
case acceptType = "Accept"

/// HTTP Request's HeaderFields,Accept-Encoding
/// HTTP Request HeaderFields,Accept-Encoding
case acceptEncoding = "Accept-Encoding"

/// HTTP Request's HeaderFields,User-Key
/// HTTP Request HeaderFields,User-Key
case userKey = "User-Key"

/// HTTP Request's HeaderFields,Cookie
/// HTTP Request HeaderFields,Cookie
case cookie = "Cookie"

public var description: String {
let base = "HTTP Header Fields: "
let base = "[HTTP Header Fields] "
return base + self.rawValue
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
public extension HTTP {

/// Define the HTTP Method of the HTTP Request request
enum HTTPMethod: String, CustomStringConvertible {
enum Method: String, CustomStringConvertible {

/// HTTP Method - GET
case `get` = "GET"
Expand Down Expand Up @@ -40,7 +40,7 @@ public extension HTTP {
case patch = "PATCH"

public var description: String {
let base = "HTTP Method: "
let base = "[HTTP Method] "
return base + self.rawValue
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Status.swift
// StatusCode.swift
// SwiftHelpers/Network
//
// Created by Leo Ho on 2023/6/13.
Expand All @@ -9,74 +9,74 @@ import Foundation

public extension HTTP {

/// Define HTTP Status of HTTP Response
enum HTTPStatus: Int, LocalizedError, CustomNSError {
/// Define HTTP StatusCode of HTTP Response
enum StatusCode: Int, LocalizedError, CustomNSError {

// MARK: Initializer

public init?(rawValue: Int) {
switch rawValue {
case HTTPStatus.continue.rawValue: self = .continue
case HTTPStatus.switchingProtocols.rawValue: self = .switchingProtocols
case HTTPStatus.processing.rawValue: self = .processing
case HTTPStatus.earlyHints.rawValue: self = .earlyHints
case HTTPStatus.ok.rawValue: self = .ok
case HTTPStatus.created.rawValue: self = .created
case HTTPStatus.accepted.rawValue: self = .accepted
case HTTPStatus.nonAuthoritativeInformation.rawValue: self = .nonAuthoritativeInformation
case HTTPStatus.noContent.rawValue: self = .noContent
case HTTPStatus.resetContent.rawValue: self = .resetContent
case HTTPStatus.partialContent.rawValue: self = .partialContent
case HTTPStatus.multiStatus.rawValue: self = .multiStatus
case HTTPStatus.alreadyReported.rawValue: self = .alreadyReported
case HTTPStatus.imUsed.rawValue: self = .imUsed
case HTTPStatus.multipleChoices.rawValue: self = .multipleChoices
case HTTPStatus.movedPermanently.rawValue: self = .movedPermanently
case HTTPStatus.found.rawValue: self = .found
case HTTPStatus.seeOther.rawValue: self = .seeOther
case HTTPStatus.notModified.rawValue: self = .notModified
case HTTPStatus.temporaryRedirect.rawValue: self = .temporaryRedirect
case HTTPStatus.permanentRedirect.rawValue: self = .permanentRedirect
case HTTPStatus.badRequest.rawValue: self = .badRequest
case HTTPStatus.unauthorized.rawValue: self = .unauthorized
case HTTPStatus.paymentRequired.rawValue: self = .paymentRequired
case HTTPStatus.forbidden.rawValue: self = .forbidden
case HTTPStatus.notFound.rawValue: self = .notFound
case HTTPStatus.methodNotAllowed.rawValue: self = .methodNotAllowed
case HTTPStatus.notAcceptable.rawValue: self = .notAcceptable
case HTTPStatus.proxyAuthenticationRequired.rawValue: self = .proxyAuthenticationRequired
case HTTPStatus.requestTimeout.rawValue: self = .requestTimeout
case HTTPStatus.conflict.rawValue: self = .conflict
case HTTPStatus.gone.rawValue: self = .gone
case HTTPStatus.lengthRequired.rawValue: self = .lengthRequired
case HTTPStatus.preconditionFailed.rawValue: self = .preconditionFailed
case HTTPStatus.contentTooLarge.rawValue: self = .contentTooLarge
case HTTPStatus.uriTooLong.rawValue: self = .uriTooLong
case HTTPStatus.unsupportedMediaType.rawValue: self = .unsupportedMediaType
case HTTPStatus.rangeNotSatisfiable.rawValue: self = .rangeNotSatisfiable
case HTTPStatus.expectationFailed.rawValue: self = .expectationFailed
case HTTPStatus.iMaTeapot.rawValue: self = .iMaTeapot
case HTTPStatus.misdirectedRequest.rawValue: self = .misdirectedRequest
case HTTPStatus.unprocessableContent.rawValue: self = .unprocessableContent
case HTTPStatus.locked.rawValue: self = .locked
case HTTPStatus.failedDependency.rawValue: self = .failedDependency
case HTTPStatus.tooEarly.rawValue: self = .tooEarly
case HTTPStatus.upgradeRequired.rawValue: self = .upgradeRequired
case HTTPStatus.preconditionRequired.rawValue: self = .preconditionRequired
case HTTPStatus.tooManyRequests.rawValue: self = .tooManyRequests
case HTTPStatus.requestHeaderFieldsTooLarge.rawValue: self = .requestHeaderFieldsTooLarge
case HTTPStatus.unavailableForLegalReasons.rawValue: self = .unavailableForLegalReasons
case HTTPStatus.internalServerError.rawValue: self = .internalServerError
case HTTPStatus.notImplemented.rawValue: self = .notImplemented
case HTTPStatus.badGateway.rawValue: self = .badGateway
case HTTPStatus.serviceUnavailable.rawValue: self = .serviceUnavailable
case HTTPStatus.gatewayTimeout.rawValue: self = .gatewayTimeout
case HTTPStatus.httpVersionNotSupported.rawValue: self = .httpVersionNotSupported
case HTTPStatus.variantAlsoNegotiates.rawValue: self = .variantAlsoNegotiates
case HTTPStatus.insufficientStorage.rawValue: self = .insufficientStorage
case HTTPStatus.loopDetected.rawValue: self = .loopDetected
case HTTPStatus.notExtended.rawValue: self = .notExtended
case HTTPStatus.networkAuthenticationRequired.rawValue: self = .networkAuthenticationRequired
case StatusCode.continue.rawValue: self = .continue
case StatusCode.switchingProtocols.rawValue: self = .switchingProtocols
case StatusCode.processing.rawValue: self = .processing
case StatusCode.earlyHints.rawValue: self = .earlyHints
case StatusCode.ok.rawValue: self = .ok
case StatusCode.created.rawValue: self = .created
case StatusCode.accepted.rawValue: self = .accepted
case StatusCode.nonAuthoritativeInformation.rawValue: self = .nonAuthoritativeInformation
case StatusCode.noContent.rawValue: self = .noContent
case StatusCode.resetContent.rawValue: self = .resetContent
case StatusCode.partialContent.rawValue: self = .partialContent
case StatusCode.multiStatus.rawValue: self = .multiStatus
case StatusCode.alreadyReported.rawValue: self = .alreadyReported
case StatusCode.imUsed.rawValue: self = .imUsed
case StatusCode.multipleChoices.rawValue: self = .multipleChoices
case StatusCode.movedPermanently.rawValue: self = .movedPermanently
case StatusCode.found.rawValue: self = .found
case StatusCode.seeOther.rawValue: self = .seeOther
case StatusCode.notModified.rawValue: self = .notModified
case StatusCode.temporaryRedirect.rawValue: self = .temporaryRedirect
case StatusCode.permanentRedirect.rawValue: self = .permanentRedirect
case StatusCode.badRequest.rawValue: self = .badRequest
case StatusCode.unauthorized.rawValue: self = .unauthorized
case StatusCode.paymentRequired.rawValue: self = .paymentRequired
case StatusCode.forbidden.rawValue: self = .forbidden
case StatusCode.notFound.rawValue: self = .notFound
case StatusCode.methodNotAllowed.rawValue: self = .methodNotAllowed
case StatusCode.notAcceptable.rawValue: self = .notAcceptable
case StatusCode.proxyAuthenticationRequired.rawValue: self = .proxyAuthenticationRequired
case StatusCode.requestTimeout.rawValue: self = .requestTimeout
case StatusCode.conflict.rawValue: self = .conflict
case StatusCode.gone.rawValue: self = .gone
case StatusCode.lengthRequired.rawValue: self = .lengthRequired
case StatusCode.preconditionFailed.rawValue: self = .preconditionFailed
case StatusCode.contentTooLarge.rawValue: self = .contentTooLarge
case StatusCode.uriTooLong.rawValue: self = .uriTooLong
case StatusCode.unsupportedMediaType.rawValue: self = .unsupportedMediaType
case StatusCode.rangeNotSatisfiable.rawValue: self = .rangeNotSatisfiable
case StatusCode.expectationFailed.rawValue: self = .expectationFailed
case StatusCode.iMaTeapot.rawValue: self = .iMaTeapot
case StatusCode.misdirectedRequest.rawValue: self = .misdirectedRequest
case StatusCode.unprocessableContent.rawValue: self = .unprocessableContent
case StatusCode.locked.rawValue: self = .locked
case StatusCode.failedDependency.rawValue: self = .failedDependency
case StatusCode.tooEarly.rawValue: self = .tooEarly
case StatusCode.upgradeRequired.rawValue: self = .upgradeRequired
case StatusCode.preconditionRequired.rawValue: self = .preconditionRequired
case StatusCode.tooManyRequests.rawValue: self = .tooManyRequests
case StatusCode.requestHeaderFieldsTooLarge.rawValue: self = .requestHeaderFieldsTooLarge
case StatusCode.unavailableForLegalReasons.rawValue: self = .unavailableForLegalReasons
case StatusCode.internalServerError.rawValue: self = .internalServerError
case StatusCode.notImplemented.rawValue: self = .notImplemented
case StatusCode.badGateway.rawValue: self = .badGateway
case StatusCode.serviceUnavailable.rawValue: self = .serviceUnavailable
case StatusCode.gatewayTimeout.rawValue: self = .gatewayTimeout
case StatusCode.httpVersionNotSupported.rawValue: self = .httpVersionNotSupported
case StatusCode.variantAlsoNegotiates.rawValue: self = .variantAlsoNegotiates
case StatusCode.insufficientStorage.rawValue: self = .insufficientStorage
case StatusCode.loopDetected.rawValue: self = .loopDetected
case StatusCode.notExtended.rawValue: self = .notExtended
case StatusCode.networkAuthenticationRequired.rawValue: self = .networkAuthenticationRequired
default: self = .unknown
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public extension HTTP {
// MARK: - Implementation LocalizedError

public var errorDescription: String {
let base = "HTTP Status Code: \(self.rawValue) "
let base = "[HTTP Status Code] \(self.rawValue) "
switch self {
case .unknown:
return base + "Unknown Status Code"
Expand Down
32 changes: 0 additions & 32 deletions Sources/SwiftHelpers/Network/Http/ContentType.swift

This file was deleted.

Loading

0 comments on commit d6c0c22

Please sign in to comment.