I have issue with following code:
func generic1(name : String){
}
func generic2(name : String){
generic1(name)
}
So far, my personal best practise used @orkhan-alikhanov 's answer. Today, when looking at SwiftUI and how .modifier()
and the ViewModifier
is implemented, I found another way (or is it more a workaround?)
Simply wrap the second function into a struct
.
If this one gives you the "Cannot explicitly specialize a generic function"
func generic2(name: String){
generic1(name)
}
This one might help. Wrap the declaration of generic1
into a struct
:
struct Generic1Struct {
func generic1(name: String) {## do, whatever it needs with T ##}
}
and call it with:
func generic2(name : String){
Generic1Struct().generic1(name: name)
}
struct
is a good example. The workaround here has not a bit more information - but passes the compiler. Same information, but different results? Then something is wrong. If it is a compiler-bug it can get fixed.