emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.59k stars 418 forks source link

Does not Compile with Xcode 13 #381

Closed honkmaster closed 2 years ago

honkmaster commented 3 years ago

The following code

@available(OSX 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
case closed(URLSessionWebSocketTask.CloseCode)

within CocoaMQTTTypes.swift produces an error:

Enum cases with associated values cannot be marked potentially unavailable with '@available'

The error was reported to Apple via Feedback Assistant and Forum. However it is not fixed yet (Beta 3). It seems like it is here to stay...

justdan0227 commented 3 years ago

Any thoughts on when this might work with Xcode 13?

honkmaster commented 3 years ago

The solution (at least for us) was quite simple. Increase the swift-tools-version to 5.3 and iOS version to iOS 14 in Package.swift as well as removing the @available macro. However, as this limits the target platforms, I can understand that this is not a solution for everyone. That is also why I did not create a pull request.

n-ravichandran commented 2 years ago

Looks like it's the expected behavior https://bugs.swift.org/browse/SR-14878.

Any ETA on the fix or a workaround?

leeway1208 commented 2 years ago

CocoaMQTTWebSocket.zip You can try to overwrite these two files (CocoaMQTTTypes.swift and CocoaMQTTWebSocket.swift)

n-ravichandran commented 2 years ago

@leeway1208 Thanks, I've done something similar on my end as a temporary workaround, which works for our use case. But I'll try to create a PR with a proper fix when I find time.

KarinBerg commented 2 years ago

I created a pull request with a possible solution. Feedback highly welcome ☺️

391

DerekK19 commented 2 years ago

I don't know if this is something I'm doing wrong, but this package no longer builds in Xcode. I'm running Xcode 13.1 and the package does not compile (git tag : 2.0.0, commit : "57e87704505b01e9e7d355b1b5b952e255db4998". I get a compile error:

error: cannot find type 'NSObject' in scope
public class MqttAuthProperties: NSObject {
                                 ^~~~~~~~

The file MqttAuthProperties.swift begins:

//
//  MqttAuthProperties.swift
//  CocoaMQTT
//
//  Created by liwei wang on 1/9/2021.
//

public class MqttAuthProperties: NSObject {

I found that importing Foundation before the public class definition fixed the error:

//
//  MqttAuthProperties.swift
//  CocoaMQTT
//
//  Created by liwei wang on 1/9/2021.
//

import Foundation

public class MqttAuthProperties: NSObject {
leeway1208 commented 2 years ago

@DerekK19 hi, I test the project and do not happen this problem πŸ˜‚. But I will fix this to prevent it from happening again. thanks

DerekK19 commented 2 years ago

Maybe it's Xcode 13.1, or maybe it's my computer - I tried a separate test class and got the same behaviour

class x : NSObject { }

gives an error if there is no import Foundation before

leeway1208 commented 2 years ago

@DerekK19 Thanks πŸ˜€πŸ˜€