Method in Date extension not found in one class while works in another

I've a small extension for the Date type with some simple helper methods like

    func dateByAdding(components: DateComponents) -> Date?
    {
        return Calendar.current.date(byAdding: components, to: self)
    }

Now there's one class where Xcode 13.0 beta 2 keeps telling me Type 'Date' has no member 'dateByAdding' while in another class the extension works as expected.

All files are 100% swift and all relevant files have a Target Membership of the same target.

I've tried the usual things like removing the Derived Data folder, but without success. Any ideas what could cause this?

Replies

Did you do the option-clean build folder ?

Where is the extension defined ? In which file ? Is in in the another class the extension works as expected

If so, try to define outside of any class.

If I press ⌥, "Clean Build Folder" becomes disabled. Is there still a difference in current Xcode versions?

The extension is defined in its own file.

Exact, I did not notice option-clean was now disabled. Just use Clean Build Folder.

Could you show the 2 class definitions and post a screen copy of the Identity and type Inspector info for the files of the 2 classes ?

This seems to be an issue with Xcode 12 beta 2. I opened the project in Xcode 12.5.1 and was able to use the methods in the Date Extension without any problem and compile the project.

Now also in Xcode 13 beta 2 the Date Extension is found in this class and I can use the methods from it.

  • May be opening the project in 12.5 did correct some issue. And then reopening in 13.0 worked ?

Add a Comment