parse-community / Parse-Swift

The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows)
https://parseplatform.org
MIT License
308 stars 69 forks source link

Module name, type name aliasing conflict #396

Closed ulitiy closed 2 years ago

ulitiy commented 2 years ago

New Issue Checklist

Issue Description

ParseSwift module is named the same as the ParseSwift class, that makes it impossible to write a fully qualified type in case of the naming conflict. And ParseSwift.Subscription already has a conflict with Combine.Subscription.

Steps to reproduce

This means I cannot even specify EnvironmentObject:

// 'Subscription' is ambiguous for type lookup in this context
// Cannot specialize non-generic type 'Subscription'
    @EnvironmentObject var lessons: Subscription<Lesson>
    var cancellables = [AnyCancellable]()
// 'Subscription' is not a member type of struct 'ParseSwift.ParseSwift'
    @EnvironmentObject var lessons: ParseSwift.Subscription<Lesson>
    var cancellables = [AnyCancellable]()

If the module name was different from the class name it could be possible to have Maybe another option is to have typealiases for conflicting names but it doesn't resolve conflicts with local project names.

AFAIK there's no tool like :: in Swift. The only way I see it can be fixed now by the library user is by importing and aliasing specific types from Combine, and never import Combine when I want to use Subscription. Like this:

typealias MyAnyCancellable = AnyCancellable

Actual Outcome

Errors

Expected Outcome

No errors

Environment

Client

Logs

n/a

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!

cbaker6 commented 2 years ago

What exactly are you trying to do? For example what code isn’t compiling and how does it differ from the many tests in the test suite? Heres an example using combine: https://github.com/parse-community/Parse-Swift/blob/a143c0f9786e4d605d3506caa8e624272892af6a/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift#L43-L69

Another using Subscription: https://github.com/netreconlab/SnapCat/blob/66bd9a2cecd4e665bc7bca13ce74690d2c613bb2/SnapCat/CustomViewModels/QueryImageViewModel.swift#L14-L340

ulitiy commented 2 years ago

I was trying to use an EnvironmentObject with a Subscription<Lesson> class to reuse the subscription in multiple nested components. It's impossible if Combine is imported because there's Combine.Subscription.

It fails anyways even if I use MyAnyCancellable with No ObservableObject of type Subscription<Lesson> found. somehow.

In your examples you do not use EnvironmentObject with Combine imported at the same time.

Anyways there's a reason why there's no Swift.Swift class (or similar) in the standard libraries – because there would be no way to call Swift.String not causing the error. I understand that many of the libraries conform to the same convention as ParseSwift but it's causing problems, lots of unresolved discussions: https://www.google.com/search?q=swift+module+and+class+name+collision

cbaker6 commented 2 years ago

Thanks for reporting and describing your issue. The linked PR should address the problem

ulitiy commented 2 years ago

Thank you for the quick response and for working on the library!