Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <~~ mean in swift?

Tags:

json

ios

swift

While checking a parser of a JSON in swift, I found the following code:

description = "desc" <~~ json

I suppose that it is similar to use the following:

description = json["desc"]

Is it correct? if no, what does this operator mean?

Thanks

like image 829
Alberto García Avatar asked Jul 06 '18 08:07

Alberto García


People also ask

What does ~= mean in Swift?

Simply use a shortcut to "range": you can construct a range and "~=" means "contains". (

What does _: mean in Swift documentation?

The underscore indicates that there is no external parameter name for the function. Apple's Swift Documentation talks about this concept in terms of when you're writing your own functions.

What does let _ mean in Swift?

In swift, we use the let keyword to declare a constant variable, a constant is a variable that once declared, the value can not be changed.

What Does a colon mean in Swift?

The colon in the declaration means “…of type…,” so the code above can be read as: “Declare a variable called welcomeMessage that's of type String .” The phrase “of type String ” means “can store any String value.” Think of it as meaning “the type of thing” (or “the kind of thing”) that can be stored.


1 Answers

You are right. But it would be wrong to assume that's what it is set out to do in Swift.

I think the parser that was being used was Gloss, and it seems that they have written an operator overload specifically to mean description = json["desc"] (and or or some other stuff under the hood to make the parsing easier) . The operator does not have a meaning per se in Swift. But it's invented by the framework to do the parsing.

You can read about operator overloading here

EDIT

I always have incorrectly used the terms operator overloading and defining custom operator interchangeably. Operator Overloading is extending the implementation of the existing operators which is different than defining your own custom operators. Thank you SO MUCH for pointing this out, @Giacomo Alzetta!

like image 183
avismara Avatar answered Oct 03 '22 21:10

avismara