Wait for input; Console.ReadLine analogue

I need some analogue of Console.ReadLine() in C# because as soon as I build and run a project, command prompt pops-up and dissapears immediatelly. So, I can’t even see the results. I’ve found a way to do it in vailla swift

let stdIn = NSFileHandle.fileHandleWithStandardInput()

but I receive "Error (E46) Unknown identifier “NSFileHandle” in silver. I assume there is another way to do it.

NSFileHandle should work fine. do you have Foundation in gather import section?

Nope, I don’t have. Where can I find it? I can’t do “import Foundation” because it couldn’t be found.

Hmm, what platform is your project for? Cocoa, i assume? of course Foundation and NSFileHandle only exist on Cocoa. on .NET, you could do Console.ReadLine, fore example.

Sorry, but I’m confused a little bit. I’m toying around with Swift-like language in .NET project. I just want to write swift on windows. So, yes, I don’t have Cocoa, but .NET. How can I achieve “wait for input” behaviour in .NET project using Silver?

Look at how its done in C#, then use the same types and calls in Silver/Swift. Silver doesn’t include any Cocoa libraries, you have to use libraries from the platform you’re targeting.

1 Like

“Swift” is the language, “Cocoa” vs “Java” vs “.NET” is the platform. If you are working on .NET, you will need to use .NET APIs (same as you would use form C#), if you work on Cocoa, you will use Cocoa APIs (same as from Objective-C). Foundation and NSFileHandle are Cocoa APIs, so they are not available on .NET, only on Cocoa.

The .NET API for this is Console.ReadLine().

1 Like

Finally I got it. Thank you guys!

1 Like