Defining Swift functions that operate on Types instead of values -


In Swift, ? takes the operator instead of the type as the parameter:

  var z = 42? // an alternate & lt; Int & gt; And var z will not compile: int? = 42 //? Takes int and an alternate & lt; Int & gt;   

How can I do my job, or the operators who work on type instead of values?

What you want to achieve is not possible.

Although there is a workaround: you can create a custom operator that is given a lexical or variable, converts it into optional Swift custom operators in ? does not allow the use of the character, I am selecting a random combination, but do not hesitate to use your own:

  Postfix Operator>! {} Postfix Funk & gt; & Lt; T & gt; (Value: T) - & gt; T? {Return value as T? }   

Once done, you can use it as follows (Production from Playground):

  10> // {some 10} Test "& gt; // {some "test"}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -