Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Int' and 'String' cannot be multiplied #1179

Open
overlookart opened this issue Mar 25, 2024 · 1 comment
Open

'Int' and 'String' cannot be multiplied #1179

overlookart opened this issue Mar 25, 2024 · 1 comment

Comments

@overlookart
Copy link

//error: Cannot convert value of type 'Int' to specified type 'String'
let str =  'bar' * 5

参考了原生 String API 文档

// Swift.String
 @inlinable public static func + (lhs: String, rhs: String) -> String

SwifterSwift 中对 String 扩展的相关方法

// SwifterSwift/StringExtensions.swift

static func * (lhs: String, rhs: Int) -> String

static func * (lhs: Int, rhs: String) -> String

建议 String 与 Int 相乘的方法前增加 @inlinable

@guykogus
Copy link
Contributor

guykogus commented Apr 3, 2024

Apple usually doesn't recommend using @inlinable unless there's a reason for it. Have you run any tests that make you think it would run faster with that keyword?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants