b5i / YouTubeKit

A way to interact with YouTube's API in Swift (without any API key!)
https://swiftpackageindex.com/b5i/YouTubeKit
MIT License
74 stars 8 forks source link

Unable to create custom HeadersList #2

Closed adrianjagielak closed 1 year ago

adrianjagielak commented 1 year ago

The README may be outdated. The following code was directly copied from the README and it doesn't compile:

Zrzut ekranu 2023-09-5 o 20 17 57

Code:

let myCustomHeadersFunction: () -> HeadersList = {
    HeadersList(
        url: URL(string: "https://www.myrequesturl.com")!,
        method: .POST,
        headers: [
            .init(name: "Accept", content: "*/*"),
            .init(name: "Accept-Encoding", content: "gzip, deflate, br"),
            .init(name: "Accept-Language", content: "\(YTM.selectedLocale);q=0.9"),
        ],
        addQueryAfterParts: [
            .init(index: 0, encode: true)
        ],
        httpBody: [
            "my query is: ",
            " and it is really cool!"
        ]
    )
}

Errors:

Extra arguments at positions #1, #2, #3, #4, #5 in call
Missing argument for parameter 'from' in call
Cannot infer contextual base in reference to member 'POST'
'Any' cannot be constructed because it has no accessible initializers
'Any' cannot be constructed because it has no accessible initializers
'Any' cannot be constructed because it has no accessible initializers
'Any' cannot be constructed because it has no accessible initializers
b5i commented 1 year ago

Hello, thanks for pointing out this issue. It seems that all the structs of the package need their default initialiser explicitly declared to be used outside the package itself. I wasn't facing this issue before because the import of YouTubeKit was made with the @testable modifier like this @testable import YouTubeKit. I'm going to declare all those initialisers as soon as possible. Thanks again

b5i commented 1 year ago

Ok it should be fixed with the last commit, fac7c95. Tell me if you face any more issue 🚀

adrianjagielak commented 1 year ago

Thank you for the quick fix! I checked and it seems to be working fine now.