what is the usage of "~>" in cocoapods

IosCocoapodsPodfilePodfile Lock

Ios Problem Overview


I want to know what the "~>" is used for,cause I find they are the same below:

pod 'AFNetworking','~> 2.0.3'

pod 'AFNetworking','2.0.3'

Ios Solutions


Solution 1 - Ios

~> (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 - Ios

  • ~> 6.0 will get you the latest version before the next version which is 7.0 but not including the 7.0 version.

  • ~> 6.0.0 will get you the latest version before the next version which is 6.1.0 but not including the 6.1.0 version.

Solution 3 - Ios

optimistic operator ~>:

'~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher
'~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher
'~> 0' Version 0 and higher, this is basically the same as not having it.
For more information, regarding versioning policy, [see][1]:

Solution 4 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMil0R3View Question on Stackoverflow
Solution 1 - IosAlladinianView Answer on Stackoverflow
Solution 2 - IosAtefView Answer on Stackoverflow
Solution 3 - IosAdnan AftabView Answer on Stackoverflow
Solution 4 - Iosthecloud_of_unknowingView Answer on Stackoverflow