13

I am defining my viewModels in a separate files as structs, when i am trying to create an instance of this struct in another file the autocomplete of the memberwise initializer is not showing..

This problem wasn't before(i.e Xcode 9) is it a bug in Xcode 10?

I have seen similar questions like Xcode does not autocomplete memberwise initializer of a Struct

but it's old and the problem was in Xcode 7 or 8 maybe.

However if i place my struct in the file i am attempting to use it, the autocomplete will be shown, so what's the problem ?

I Also tried .init after the struct name with no luck.

Here's my ViewModels :

struct ProfileModels {

    struct ViewModels {


        struct profile{
            let name : URL?
            let positionAndCountry : String?
            let briefDescription : String?
            let hotelInfo : HotelInfo?

        }

        struct HotelInfo{
            let hotelName : String?
            let roomClasification : String?
            let checkInDate : String?
            let checkOutDate : String?
            let isCheckInEarly : String?
            let isCheckInLate : String?
        }

    }
}

enter image description here

Update:

As mentioned in the comments that it works fine if the init method called, however sometimes the autocomplete isn't showing with calling the init method...

Anyway for anybody who wants a quick workaround until this bug solved is to use the following:

  • Create an empty struct (don't worry about the error for now)

    example : ProfileModels.viewModels.profile()

  • In a new line, call the struct and the autocomplete will be shown!, now you can delete the first one.

I don't know why this happened but maybe the compiler after the first line will recognize that this struct missing arguments, so they will appear when the same struct used later...

mojtaba al moussawi
  • 1,360
  • 1
  • 13
  • 21
  • Case sensitive mismatch: `profile` vs `Profile` – vadian Sep 26 '18 at 18:39
  • @vadian, sry for the typo, no it was `profile` but when i posted the question i realize that the `p` is small so i change it to capital letter without updating the screenshot. – mojtaba al moussawi Sep 26 '18 at 18:41
  • Having the same issue. This worked perfectly before. – Nailer Oct 22 '18 at 12:33
  • facing same issue.But it works fine for me when you call its init method.Like: ProfileModels.ViewModels.profile().init.... – Sakshi Nov 23 '18 at 09:54
  • @Sakshi, i hope so, but sometimes isn't working... check my updated question if the problem is still exist with you even with calling the init method... – mojtaba al moussawi Nov 23 '18 at 10:50
  • Basically Xcode just sucks and does this a lot. In a huge project, you're lucky when autocomplete works. – Jacob Jan 06 '19 at 07:42
  • @mojtabaalmoussawi I have just made the test with Xcode 10.1 and it worked perfect. Did you try to update to the latest Xcode version? Regards. – Jordi Gámez Feb 22 '19 at 09:45

1 Answers1

0

There has been a bug in Xcode for a while where autocompletion for structs would be finicky. Classes have never had this issue, but I was able to fix the autocompletion by typing .init after the struct name, triggering the autocompletion, and then deleting the .init after. Hope this helps

Ken Mueller
  • 3,659
  • 3
  • 21
  • 33