what is the usage of "~>" in cocoapods
Solution 1:
~>
(the optimistic operator) is used when you want to specify a version 'up to next major | minor | patch'. For example:
~> 0.1.2
will get you a version up to 0.2 (but not including 0.2 and higher)
~> 0.1
will get you a version up to 1.0 (but not including 1.0 and higher)
~> 0
will get you a version of 0 and higher (same as if it was omitted)
where 0.1.2
would mean 'I want this exact version'
Here is some more info on this
Solution 2:
~> 6.0
will get you the latest version before the next version which is7.0
but not including the7.0
version.~> 6.0.0
will get you the latest version before the next version which is6.1.0
but not including the6.1.0
version.
🎉
Solution 3:
While most of the above answers are correct, they answer the question using examples rather than actually explaining what is going on, making it difficult to understand the concept. The key thing to know in order to understand how the optimistic operator works is that cocoapods looks to see how specific the version number is to determine how it will interpret the optimistic operator.
A version number's syntax conveys info re. the type of update a developer is releasing. That syntax, from left to right, refers to Major.Minor.Patch updates.
Cocoapods looks to see what is the most specific element in the version number to determine how it will interpret the optimistic operator. So if the version number contains info about patch updates - i.e it looks something like this: ~> 1.1.2
- then patch updates are what cocoapods focuses on when implementing the optimistic operator. Likewise, if the version number is only as specific as minor updates - i.e it looks something like this: ~> 1.2
- then cocoapods will focus only on updates that are either minor OR patch updates when implementing the optimistic operator.
A version number of ~> 1.0.1
tells cocoapods to install the most recent version update, so long as that update is a PATCH update; Major or Minor updates should be ignored.
A version number of ~> 1.1
tells Cocoapods to install the most recent updates that are available, so long as those updates are either PATCH or MINOR updates, and it should ignore any Major updates.