I want to become a swifter

Hi,
I'm a swift beginner, since then I wrote objective-c code.
I bought the not so small book Swift 5 and run with the second snippet against the wall:

// playground
for x in 1...100
{
let y = sin(Double(x) / 10)
print("X=(x), y=(y) ")
}

I got the error : "Use of unresolved identifier 'sin"
The solution is a missing underscore (_sin), blame it to the book :laughing:

I hope you like to support me in the next future :laughing:
Uwe

2 Likes

sin(_:_:) is not part of the Standard Library. You need to import Foundation (or Darwin, Glibc, WinSDK, etc.) to get access to the C function.

The best practice would actually be use the swift-numerics package, but if you have just started and you are only working with a toy example anyway, you may as well just use the C function instead and put off learning about packages until you have more under your belt.

3 Likes
Terms of Service

Privacy Policy

Cookie Policy