

{"id":118596,"date":"2023-10-31T18:00:30","date_gmt":"2023-10-31T12:30:30","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=118596"},"modified":"2023-10-31T18:20:04","modified_gmt":"2023-10-31T12:50:04","slug":"swift-operators","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/swift-operators\/","title":{"rendered":"Swift Operators with Examples"},"content":{"rendered":"<p>In programming, operators play a fundamental role in performing various operations on data. Swift provides a rich set of operators to handle arithmetic, comparison, logical, and other operations. In this article, we will explore Swift operators, their kind and types, and how they contribute to creating efficient and expressive code.<\/p>\n<h2>What are Swift Operators?<\/h2>\n<p>Swift operators are symbols or special characters used to perform operations on data. Operations such as addition, subtraction, comparison, and more. They act upon one or two operands and produce a result, making it easier to manipulate data in different ways.<\/p>\n<h3>Types of Swift Operators<\/h3>\n<p>We categorize operators based on the type of operations they perform. Following are the different types of operators.<\/p>\n<h4>Arithmetic Operators<\/h4>\n<p>Arithmetic operators manage mathematical operations. The below table depicts the arithmetic operators.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Addition<\/span><\/td>\n<td><span style=\"font-weight: 400\">+<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Subtraction<\/span><\/td>\n<td><span style=\"font-weight: 400\">&#8211;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Multiplication<\/span><\/td>\n<td><span style=\"font-weight: 400\">*<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Division<\/span><\/td>\n<td><span style=\"font-weight: 400\">\/<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Modulo (Remainder)<\/span><\/td>\n<td><span style=\"font-weight: 400\">%<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var num1 = 8\r\nvar num2 = 5\r\n\r\nvar additionExample = num1 + num2\r\nvar subtractionExample = num1 - num2\r\nvar multiplicationExample = num1 * num2\r\nvar divisionExample = num1 \/ num2\r\nvar moduloExample = num1 % num2\r\n\r\nprint(\"Addition:\", additionExample)\r\nprint(\"Subtraction:\", subtractionExample)\r\nprint(\"Multiplication:\", multiplicationExample)\r\nprint(\"Division:\", divisionExample)\r\nprint(\"Modulo:\", moduloExample)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Addition: 13<br \/>\nSubtraction: 3<br \/>\nMultiplication: 40<br \/>\nDivision: 1<br \/>\nModulo: 3<\/p>\n<h4>Assignment Operators<\/h4>\n<p>Assignment Operators assign values to identifiers like variables and constants.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">=<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let example = 2023\t\t\/\/2023 value assigned to example.\r\nprint(example)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>2023<\/p>\n<h4>Compound Assignment Operators<\/h4>\n<p>When an arithmetic operator is combined with an assignment operator, it forms a compound assignment operator.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Addition Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">+=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Subtraction Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">-=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Multiplication Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">*=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Division Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">\/=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Modulo Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">%=<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var  num1 = 8\r\nvar num2 = 5\r\n\r\nnum1 += num2\r\nprint(\"Addition Assignment:\", num1)\r\nnum1 -= num2\r\nprint(\"Subtraction Assignment:\", num1)\r\nnum1 *= num2\r\nprint(\"Multiplication Assignment:\", num1)\r\nnum1 \/= num2\r\nprint(\"Division Assignment:\", num1)\r\nnum1 %= num2\r\nprint(\"Modulo Assignment:\", num1)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Addition Assignment: 13<br \/>\nSubtraction Assignment: 8<br \/>\nMultiplication Assignment: 40<br \/>\nDivision Assignment: 8<br \/>\nModulo Assignment: 3<\/p>\n<h4>Bitwise Operators<\/h4>\n<p>Bitwise operators perform operations on each individual bit.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Binary AND<\/span><\/td>\n<td><span style=\"font-weight: 400\">&amp;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Binary OR<\/span><\/td>\n<td><span style=\"font-weight: 400\">|<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Binary XOR<\/span><\/td>\n<td><span style=\"font-weight: 400\">^<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Binary NOT<\/span><\/td>\n<td><span style=\"font-weight: 400\">~<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Binary Shift Right<\/span><\/td>\n<td><span style=\"font-weight: 400\">&gt;&gt;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Binary Shift Left<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt;&lt;<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var num1 = 2\r\nvar num2 = 3\r\nvar binaryAnd = num1 &amp; num2\r\nvar binaryOr = num1 | num2\r\nvar binaryXor = num1 ^ num2\r\nvar binaryNot = ~num1\r\nvar binaryShiftRight = num1 &gt;&gt; 2\r\nvar binaryShiftLeft = num1 &lt;&lt; 2\r\nprint(\"AND:\", binaryAnd)\r\nprint(\"OR:\", binaryOr)\r\nprint(\"XOR:\", binaryXor)\r\nprint(\"NOT:\", binaryNot)\r\nprint(\"Shift Right:\", binaryShiftRight)\r\nprint(\"Shift Left:\", binaryShiftLeft)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>AND: 2<br \/>\nOR: 3<br \/>\nXOR: 1<br \/>\nNOT: -3<br \/>\nShift Right: 0<br \/>\nShift Left: 8<\/p>\n<h4>Shift Operators<\/h4>\n<p>Shift operators shift the bits of a number in its binary representation. In Swift, there are two shift operators: Left Shift (&lt;&lt;) and Right Shift (&gt;&gt;) operators.<\/p>\n<p><strong>Left Shift Operator<\/strong><\/p>\n<p>The left shift operator shifts the bits of a number to the left by the given number of positions. It multiplies the number by 2 to the power of the number of shifts.<\/p>\n<p>Here, a is the number, and b is the number of bits to be shifted.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let originalValue: Int = 3\r\nlet leftShiftedValue: Int = originalValue &lt;&lt; 2\r\nprint(leftShiftedValue)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>12<\/p>\n<p><strong>Right Shift Operator<\/strong><\/p>\n<p>The right shift operator shifts the bits of a number to the right by the given number of positions. It divides the number by 2 to the power of the number of shifts.<\/p>\n<p>Here, a is the number, and b is the number of bits to be shifted.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let originalValue: Int = 12\r\nlet rightShiftedValue: Int = originalValue &gt;&gt; 2\r\nprint(rightShiftedValue)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>3<\/p>\n<h4>Comparison Operators<\/h4>\n<p>Comparison Operators compare two values and return Boolean values.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">==<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Not Equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">!=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Greater than<\/span><\/td>\n<td><span style=\"font-weight: 400\">&gt;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Less than<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Greater than or Equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">&gt;=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Less than or Equal to<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt;=<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let num1 = 2\r\nlet num2 = 3\r\nlet isEqual = (num1 == num2)\r\nlet isNotEqual = (num1 != num2)\r\nlet isGreater = (num1 &gt; num2)\r\nlet isLess = (num1 &lt; num2)\r\nlet isGreaterOrEqual = (num1 &gt;= num2)\r\nlet isLessOrEqual = (num1 &lt;= num2)\r\n\r\nprint(\"Equal to:\", isEqual)\r\nprint(\"Not Equal to:\", isNotEqual)\r\nprint(\"Greater than:\", isGreater)\r\nprint(\"Less than:\", isLess)\r\nprint(\"Greater than or Equal to:\", isGreaterOrEqual)\r\nprint(\"Less than or Equal to:\", isLessOrEqual)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Equal to false<br \/>\nNot Equal to true<br \/>\nGreater than false<br \/>\nLess than true<br \/>\nGreater than or Equal to false<br \/>\nLess than or Equal to true<\/p>\n<h4>Logical Operators<\/h4>\n<p>Logical Operators return boolean values depending on the operand&#8217;s value and the operator used.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Logical AND<\/span><\/td>\n<td><span style=\"font-weight: 400\">&amp;&amp;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Logical OR<\/span><\/td>\n<td><span style=\"font-weight: 400\">||<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Logical NOT<\/span><\/td>\n<td><span style=\"font-weight: 400\">!<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let value1 = true\r\nlet value2 = false\r\n\r\nlet andValue = value1 &amp;&amp; value2\r\nlet orValue = value1 || value2\r\nlet notValue = !value1\r\nprint(\"AND:\", andValue)\r\nprint(\"OR:\", orValue)\r\nprint(\"NOT:\", notValue)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>AND: false<br \/>\nOR: true<br \/>\nNOT: false<\/p>\n<h4>Range Operators<\/h4>\n<p>Range Operators run values based on the given range of numbers.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Closed Range<\/span><\/td>\n<td><span style=\"font-weight: 400\">(a\u2026b)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Half-Open Range<\/span><\/td>\n<td><span style=\"font-weight: 400\">(a..&lt;b)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">One-Sided Range<\/span><\/td>\n<td><span style=\"font-weight: 400\">[a\u2026]<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">for i in 1...5{\t\t\t\t\/\/Closed Range\r\n    print(i, terminator: \" \")\t\t\r\n}\r\nprint()\r\nfor i in 1..&lt;5{\t\t\t\t\/\/Half-Open Range\r\n    print(i, terminator: \" \")\r\n}\r\nprint()\r\nlet array = [3,5,7,9,10,24]\r\nfor i in array[0...]{\t\t\t\/\/One-sided Range\r\n     print(i, terminator: \" \")\r\n}\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>1 2 3 4 5<br \/>\n1 2 3 4<br \/>\n3 5 7 9 10 24<\/p>\n<h3>Miscellaneous Operators<\/h3>\n<h4>Nil Coalescing Operator<\/h4>\n<p>The absence of value is dealt with using the Nil Coalescing Operator. It provides a convenient way to handle optional. It provides a default value in case the optional is nil.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let optionalExampleName: String? = nil\r\nlet name = optionalExampleName ?? \"Anonymous\"\r\nprint(\"Hi, \\(name) here.\") \r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Hi, Anonymous here.<\/p>\n<h3>Kinds of Swift Operators<\/h3>\n<p>In Swift, operators can be classified into three kinds. They are categorized based on the number of operands they act upon. The three kinds are unary, binary, and ternary operators.<\/p>\n<h4>Unary Operator<\/h4>\n<p>Unary operators perform operations on a single operand. <strong>For example,<\/strong><\/p>\n<p>1. Logical NOT (!) is a unary operator. It inverts the Boolean value of an identifier.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var isTrue = true\r\nvar isFalse = !isTrue\r\n<\/pre>\n<p>2. Unary plus (+) is a unary operator. It represents a positive value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var number = +2023\r\n<\/pre>\n<p>Note that it doesn&#8217;t change the operand&#8217;s value. But it can be used to clarify the positive sign when needed.<\/p>\n<p>3. Unary minus (-) is a unary operator. It represents a negation of a value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var number = -2023\r\n<\/pre>\n<p>Note that it changes a positive value to a negative value and vice versa.<\/p>\n<h4>Binary Operator<\/h4>\n<p>Binary operators operate on two operands. One on the left and the other on the right side of the operator. Swift supports several binary operators such as arithmetic, comparison, logical, etc.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var num1 = 3\r\nvar num2 = 2\r\nvar sum = (num1 + num2)\t\t\\\\ + is a binary operator.\r\n<\/pre>\n<h4>Ternary Operator<\/h4>\n<p>The ternary operator is a special conditional operator. It operates on 3 operands: a condition, a true result and a false result. If the condition is true, then it returns the true result. If the condition is false, it returns a false result.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let year = 2023\r\nlet trueOutput = (year == 2023) ? \"DataFlair\" : \"Not DataFlair\"\r\nprint(trueOutput)\r\n\r\nlet falseOutput = (year != 2023) ? \"DataFlair\" : \"Not DataFlair\"\r\nprint(falseOutput)\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>DataFlair<br \/>\nNot DataFlair<\/p>\n<h3>Operator Precedence<\/h3>\n<p>The order in which we evaluate operators when we have multiple operators in one expression is known as Operator Precedence. In the table below, precedence decreases as we go down the table.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Operator Name<\/b><\/td>\n<td><b>Operator Symbol<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Bitwise Shift<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt;&lt;, &gt;&gt;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Multiplicative<\/span><\/td>\n<td><span style=\"font-weight: 400\">%, *, \/<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Additive<\/span><\/td>\n<td><span style=\"font-weight: 400\">|, &#8211; , +, -, ^<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Range<\/span><\/td>\n<td><span style=\"font-weight: 400\">..&lt;, \u2026<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Nil-Coalescing\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">??<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Comparison<\/span><\/td>\n<td><span style=\"font-weight: 400\">&lt;, &gt;, &lt;=, &gt;=, ==. !=<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Logical<\/span><\/td>\n<td><span style=\"font-weight: 400\">&amp;&amp;, ||<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Ternary<\/span><\/td>\n<td><span style=\"font-weight: 400\">?:<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Assignment<\/span><\/td>\n<td><span style=\"font-weight: 400\">%=, \/=, *=, +=, -=<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let precedenceExample = 2 + 3 * 5       \/\/Based on operator precedence, first multiplication is done and then addition is done.\r\nprint(precedenceExample)\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>17<\/p>\n<h3>Conclusion<\/h3>\n<p>To wrap up, Swift&#8217;s operators are key tools for handling different data operations. They include arithmetic for math, assignments for giving values, comparisons for checking values, and more. By using these symbols, we can perform tasks like addition, subtraction, and comparisons in our code. These swift operators also have priorities based on their precedence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In programming, operators play a fundamental role in performing various operations on data. Swift provides a rich set of operators to handle arithmetic, comparison, logical, and other operations. In this article, we will explore&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":118598,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27789],"tags":[28410,28409,28411],"class_list":["post-118596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift-tutorials","tag-operators-in-swift","tag-swift-operators","tag-swift-operators-with-examples"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Swift Operators with Examples - DataFlair<\/title>\n<meta name=\"description\" content=\"Swift operators are symbols used to perform operations on data. Operations such as addition, subtraction, comparison, and more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/swift-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift Operators with Examples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Swift operators are symbols used to perform operations on data. Operations such as addition, subtraction, comparison, and more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/swift-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-31T12:30:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-31T12:50:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/08\/swift-operators.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift Operators with Examples - DataFlair","description":"Swift operators are symbols used to perform operations on data. Operations such as addition, subtraction, comparison, and more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/swift-operators\/","og_locale":"en_US","og_type":"article","og_title":"Swift Operators with Examples - DataFlair","og_description":"Swift operators are symbols used to perform operations on data. Operations such as addition, subtraction, comparison, and more.","og_url":"https:\/\/data-flair.training\/blogs\/swift-operators\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-10-31T12:30:30+00:00","article_modified_time":"2023-10-31T12:50:04+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/08\/swift-operators.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Swift Operators with Examples","datePublished":"2023-10-31T12:30:30+00:00","dateModified":"2023-10-31T12:50:04+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/"},"wordCount":882,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/08\/swift-operators.webp","keywords":["operators in swift","swift operators","swift operators with examples"],"articleSection":["Swift Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/swift-operators\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/","url":"https:\/\/data-flair.training\/blogs\/swift-operators\/","name":"Swift Operators with Examples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/08\/swift-operators.webp","datePublished":"2023-10-31T12:30:30+00:00","dateModified":"2023-10-31T12:50:04+00:00","description":"Swift operators are symbols used to perform operations on data. Operations such as addition, subtraction, comparison, and more.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/swift-operators\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/08\/swift-operators.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/08\/swift-operators.webp","width":1200,"height":628,"caption":"swift operators"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/swift-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Swift Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/swift-tutorials\/"},{"@type":"ListItem","position":3,"name":"Swift Operators with Examples"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/118596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=118596"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/118596\/revisions"}],"predecessor-version":[{"id":123198,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/118596\/revisions\/123198"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/118598"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=118596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=118596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=118596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}