seanhenry / SwiftMockGeneratorForXcode

An Xcode extension (plugin) to generate Swift test doubles automatically.
MIT License
751 stars 48 forks source link

Doesn't work on Xcode 10 #14

Closed andyboyd closed 6 years ago

andyboyd commented 6 years ago

When trying to generate a mock on Xcode 10, I just get the error message "Could not find a protocol on ", even though the protocol has been defined.

seanhenry commented 6 years ago

Hi @andyboyd

Thanks for raising this issue. It looks like from your error message that you are not using the latest version. Can you open the companion app and check that the version number is v0.16? If it is lower can you install the latest version and try again?

I haven't been able to reproduce this issue using v0.16 and Xcode 10 so far. Can you attach a simple project where it is reproducible if you still get the problem with v0.16?

andyboyd commented 6 years ago

I've updated to version 0.16 and I'm still seeing the same error (except now it says "Could not find a class or protocol"!)

I tried to reproduce it in a fresh project, and I did manage, but then I cleaned something up and the bug went away, and I haven't been able to reproduce it again. Our project has a ReplayKit Broadcast Upload Extension in it, and we have 2 copies of each target for live and dev builds. Only the Dev target is configured for testing.

The bug appeared when I tried to mirror that setup, but like I say, it went away when I changed something, but I'm not sure what it was I changed. Not sure if that information is helpful to you. I can't really go changing things on our real project, because it's set up the way we need it to be.

I'll investigate a bit more when I get time, unless the above info gives you a lightbulb moment!

seanhenry commented 6 years ago

Thanks for the info. The error essentially means that Source Kit could not resolve any inherited types to a protocol or class and the source kit implementation is very basic in this project. Source kit is given all the files in the project directory ignoring any different targets or modules which can lead to some problems. For example, if you have two types with the same name across two different modules then source kit cannot resolve to either because it has no knowledge of those modules.

So perhaps your project was set up in such a way which didn't allow for such a simple source kit implementation. I've been working on a way to support modules and third party frameworks but it's a little way off. I'll close this for now but please reopen if the problem returns. I would be really interesting in finding out what the problem was.

joshwoods commented 6 years ago

@seanhenry We are running into this issue on our end as well with Xcode 10. Not entirely sure what the cause is here, but for our target that is the host of our testing suite, we are also not getting autocomplete. I have a feeling that this may all be related to the mock generator not working as well but I haven't been able to reproduce in sample projects at all either.

seanhenry commented 6 years ago

Interesting... If you're not getting autocomplete then that says to me that source kit is not working for you project for some reason. Can you try cleaning the project directory, restarting Xcode, etc and seeing if you can get autocomplete to work? The rule of thumb is if you can resolve to the declaration in Xcode with cmd+click then you should be able to generate a mock. Although there are exceptions to that rule (see above comment).

If you can cmd+click to the declaration in Xcode and the generator still gives you an error let me know and perhaps we can work through this problem to figure out a solution.

seanhenry commented 5 years ago

@andyboyd @joshwoods

If you're still having issues I've released a new version which might help.

If it doesn't help then I have a couple of other things to try... See my comment in issue #16

andyboyd commented 5 years ago

New version works again, thanks!

seanhenry commented 5 years ago

Awesome! Thanks for letting me know :)