Swift as how to receive the inlet parameters like C language?

 

We all know that in the Swift language which is no longer the main function,You may understand C language or Java language students arrived at this point of deep discomfort。In short,Instead main.swift。

Swift language in which,The compiler does not go looking for main function as a program entry,But this "main.swift" file,According to the official explanation view,The contents of the document is under global scope,It will serve as the project's entrance,And other documents which are not directly written statements in addition to statements。

The main function disappeared

Then,Without this function,We get the parameters of the entrance from where? Argc and argv are familiar with where to go?

In fact, these two parameters Swift is still there - after all, Swift compatible C is not it?

We just need to extract them from the global variables which can be:

Get parameters

To obtain parameters,We just want to extract them among the global variable - Type is a String array:

Such,We will be able to get the passed parameters,of course,The default is still the first program in the current directory。

Original article written by LogStudio:R0uter's Blog » Swift as how to receive the inlet parameters like C language?

Reproduced Please keep the source and description link:https://www.logcg.com/archives/1029.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *