devicekit / DeviceKit

DeviceKit is a value-type replacement of UIDevice.
MIT License
4.4k stars 425 forks source link

Carthage: Type 'Device' has no member 'current' #316

Closed pepas-everly closed 2 years ago

pepas-everly commented 2 years ago

Something strange seems to be going on with my Carthage installation of DeviceKit.

I've tried both

github "devicekit/DeviceKit" == 4.6.0

as well as

github "devicekit/DeviceKit" ~> 4.0

Usage:

import DeviceKit

...

    print(Device.current.safeDescription)

This results in a build error:

Type 'Device' has no member 'current'

If I skip Carthage and instead just manually pull in a copy of Device.generated.swift directly into my project, everything works as expected.

Through a bit of experimentation, I found that using the framework in a different way appears to work (with Carthage):

import DeviceKit

...

        print(Device().description)

I then tried print(Device.allPhones) and got this:

[iPhone 4, iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPhone 6, iPhone 6 Plus, iPhone 6s, iPhone 6s Plus, iPhone 7, iPhone 7 Plus, iPhone SE, iPhone 8, iPhone 8 Plus, iPhone X, iPhone Xs, iPhone Xs Max, iPhone Xr]

So it's like an older version of the framework is somehow being used.

If I open up Carthage/Checkouts/DeviceKit/Source/Device.generated.swift, I see this:

    /// All iPhones
    public static var allPhones: [Device] {
      return [.iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR, .iPhone11, .iPhone11Pro, .iPhone11ProMax, .iPhoneSE2, .iPhone12, .iPhone12Mini, .iPhone12Pro, .iPhone12ProMax, .iPhone13, .iPhone13Mini, .iPhone13Pro, .iPhone13ProMax, .iPhoneSE3]
    }

I have no idea how this could possibly be happening. This just doesn't make any sense. I've never installed DeviceKit anywhere on this laptop prior to this, so I don't understand where an older version could possibly be coming from.

I'm using Xcode 13.3, macOS 12.4.

pepas-everly commented 2 years ago

Hmm, here's a clue.

I noticed there are two copies of Device.generated.swift:

$ find . | grep DeviceKit | grep Device.generated.swift
./Carthage/Checkouts/DeviceKit/Source/Device.generated.swift
./Carthage/Checkouts/DeviceKit/CocoaPodsVerification/Pods/DeviceKit/Source/Device.generated.swift

If I open up Carthage/Checkouts/DeviceKit/CocoaPodsVerification/Pods/DeviceKit/Source/Device.generated.swift, I see:

    /// All iPhones
    public static var allPhones: [Device] {
      return [.iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhoneSE, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXs, .iPhoneXsMax, .iPhoneXr]
    }

So somehow the wrong copy of Device.generated.swift is getting used?

pepas-everly commented 2 years ago

Aha, that's it.

*** Building scheme "DeviceKit" in CocoaPodsVerification.xcworkspace
pepas-everly commented 2 years ago

A work-around seems to be to split the carthage command into two parts (fetch, then build), and simply remove the CocoaPodsVerification directory from the checkout before building.

carthage update --no-build
rm -rf Carthage/Checkouts/DeviceKit/CocoaPodsVerification
carthage build --use-xcframeworks --platform iOS --no-use-binaries --cache-builds
Zandor300 commented 2 years ago

@pepas-everly Yes, there is still an open PR to remove the CocoapodsVerification project (https://github.com/devicekit/DeviceKit/pull/288) but that is yet to be merged. I will see if I have time to update it and getting it merged.

pepas-everly commented 2 years ago

Thanks!