1
votes

I'm using the following code but getting an error 'Cannot invoke initializer for type 'String' with an argument list of type '(CGFloat)'. I've tried to modify both String(height) & String(width) with no luck. Any ideas will be much appreciated!

let width = self.view.frame.size.width
let height = width/320 * 180

let videoEmbedString = "<html><head><style type=\"text/css\">body {background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><iframe frameBorder=\"0\" height=\"" + String(height) + "\" width=\"" + String(width) + "\" src=\"http://www.youtube.com/embed/" + vid.videoId + "?showinfo=0&modestbranding=1&frameborder=0&rel=0\"></iframe></body></html>"
2

2 Answers

1
votes

Try "\(width)" instead of String(width)

i.e., replace String(width) with "\(width)"

0
votes

In Swift String struct doesn't have an initializer that takes CGFloat as an argument. However, CGFloat (or rather Double) has a property that returns its String representation - description

let width = self.view.frame.size.width
let widthString = width.description
let height = width/320 * 180
let heightString = height.description