Cannot convert expression type "StaticString" to type "StringLiteralConvertible" (Swift)

Generics in a programming language that works on iOS? Shut up and take my money!

Here is my experimental code (this works on the playground):

class Foo<GenericType1> {
    var value:GenericType1?
    init(value:GenericType1) {
        self.value = value;
    }
}

class Foo2<GenericType2> : Foo<GenericType2> {
    override init(value:GenericType2) {
        super.init(value:value);
    }
}

extension Foo {
    class func floop<T>(value: T) -> Foo2<T> {
        return Foo2<T>(value:value)
    }
}

The following are:

var foo = Foo.floop("test")

The last part gives an error message:

Cannot convert the expression type 'StaticString' to type 'StringLiteralConvertible'

I can’t understand for life why. Any help would be greatly appreciated.

+4
source share
1 answer

, , , , , , - :

var foo = Foo<String>.floop("test")  //or,
var foo = Foo<Int>.floop("test")

, .

, !

+1

All Articles