|
I was trying to do the mini challenge of creating an extension on FileManager based on the Bundle one from Project 8. I've been trying to do it, but I'm getting more confused as i continue. Right now i have this but Im getting an error ("Generic parameter 'T' could not be inferred") when i try to use it, but i suspect i don't even know how to use this extension on the "onTapGesture"...
|
|
The code you provided seems to be an extension on the To fix the error ("Generic parameter 'T' could not be inferred"), you need to explicitly specify the type you want to
In the updated code, we explicitly specify Please note that you should be cautious when force unwrapping and using |
|
First of all i need to share some thoughts about generics -
So now we look at the code you have used here
this funtion will be able to perform action on any type that is decodable but the input parameter being passed has to be string , also it will be able to return any type that is decodable. Now the error come as you did not mention the type of what you are dealing with in regard to this funciton, it could be any where you might have missed. So generics provide us the ability to not use a concrete type when defining a function , instead that concrete type like string can be used when we use this funciton, then we only have to be sure that it is in sync if it were be a function with concrete types. Ofcourse the error messages you get will keep mentioning generics but that is natural. |
|
Thank you both for the explanation. Cleaned my code a bit and specified the type on the onTapGesture. It's working fine now.
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.