var format = "%7B%22sign%22%3Anull%2C%22company%22%3A%22%E5%85%84%E5%BC%9F%E6%B5%B7%E6%B4%8B%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%22%2C%22businessNo%22%3Anull%2C%22scene%22%3Anull%2C%22interviewCode%22%3A%22767676%22%7D" let message = withVaList([]) { args in let msg = NSString(format: format, arguments: args) print(msg) }
On all versions of iOS 18?
If so, I don’t think there’s much point filing a bug about this. What you’re doing is very worrying from a binary compatibility perspective. If you’d noticed this during the iOS 18.0 beta cycle then it would be reasonable to file a bug about this that’s focused on this binary compatibility issue. However, the iOS 18 ship sailed many months ago, so the time for that has past. It’s now time to fix your code.
You didn’t give us a lot of details about your code but the code you did post is very concerning. Using varargs from Swift is challenging at the best of times — it’s hard using varags correctly from C, and Swift doesn’t make it any easier! — and the snippet you posted is clearly incorrect.
Consider this tiny test project:
import Foundation func main() { var format = "%7B%22s\n" withVaList([]) { args in let msg = NSString(format: format, arguments: args) print(msg) } } main()
On my Mac it prints:
7B(null)
That’s because %22s
is treated as a conversion specifier, namely for a 22 character wide C string. You’re not passing it a C string, and thus it gets an undefined value. It just so happens that this value is NULL
, and hence the (null)
is the output. However, it could just as easily be some other random value that causes a memory access exception.
If you post more info about your high-level goal here, I should be able to offer more insight into how to proceed.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"