Type 'Float' has no member 'random'

I’m try to make a app from this book, but then i copy and paste, i got this here error: “Type ‘Float’ has no member ‘random’”

Page 65

I’m useing: Xcode Version 9.1 (9B55)

Hi @007fred50 , I believe random function is defined in Float+Extensions.swift file which is included in GameUtils folder. Have you included that folder in your project?

i have inlcude but still does not work.

I see @007fred50. Could you check if the Float extension and the random function are both defined public in your Float extension file?

sorry, i don’t understand that you say.

did you mean this here?

That looks fine. I think it should work. Just to check if your compilation error is due to something else what you can do is copy the Float extension defined in Float extension file and paste it on top of the file where you are getting the compilation error. Also you need to comment the extension defined here in order to avoid duplication. The compilation error for random function should go away with that.

Hello, i have recorded a video,

Hi, Does the problem go away if you copy & paste the Float extension in your GameViewController class where you are getting compilation error?

i get new errror now.

Ok. I think the problem could be the way you added GameUtils folder into your project. So when you dragged and dropped the GameUtils folder into your project, did you choose Copy items if needed as well as create groups option? One option would be to delete the reference of that folder from your project and try to add again with options selected: Copy items if needed and create groups.

stil same error.

In your video it shows that while dropping the GameUtils folder into your project you had selected Copy items if needed and Create folder references. What happens if you choose options: 1. Copy items if needed 2. Create groups.

Thanks it works now !

result of the problem.

This topic was automatically closed after 166 days. New replies are no longer allowed.