Create a class called Swift.

I need to call my class is , but when I try to do this:

 class is { } 

I get an error message:

Expected identifier in class declaration

Is there any way around this error and calling my is class? I do not want to call it is or iss or iis , but is .

+1
source share
1 answer

I would not recommend this - it will certainly make your code much less readable, and there are simple alternatives (for example, just using a reserved word).

But if you really want it, you can write it as `is` . Evacuation from backticks allows you to use reserved words / keywords as identifiers. You will need to use inverse elements wherever you want to use the class name:

 class `is` { } let obj = `is`() let objs: [`is`] = [] 

More information can be found in the Swift programming language .

+6
source

Source: https://habr.com/ru/post/1258553/


All Articles