{"id":25,"date":"2018-10-03T18:13:13","date_gmt":"2018-10-03T18:13:13","guid":{"rendered":"https:\/\/r0b3rt.com\/andr-web\/?p=25"},"modified":"2018-10-03T18:13:13","modified_gmt":"2018-10-03T18:13:13","slug":"swift-2-code-examples","status":"publish","type":"post","link":"http:\/\/r0b3rt.com\/andr-web\/swift-2-code-examples\/","title":{"rendered":"Swift 2 &#8211; Code Examples"},"content":{"rendered":"<p><a href=\"https:\/\/developer.apple.com\/library\/ios\/navigation\/#section=Resource%20Types&#038;topic=Sample%20Code\">CLICK HERE<\/a> for the Apple xCode Project Examples Developer Library, or just type <strong>http:\/\/tinyurl.com\/xcodelibrary<\/strong> if you are not on this page.<\/p>\n<hr>\n<p><strong><strong>USEFUL SYNTAX(es) AND CODE EXAMPLES<\/strong><\/p>\n<hr \/>\n<p><strong>IF STATEMENT<\/strong><\/p>\n<p>var myString = String()<br \/>\nif X == array_Name.indexOf(myCharacters) {<br \/>\nmyString = &#8220;Statement One&#8221;<br \/>\n}<br \/>\nelse if X = Y {<br \/>\nMyString = &#8220;Second Statement&#8221;<br \/>\n}<br \/>\nelse {<br \/>\nMyString = &#8220;This is the default&#8221;<br \/>\n}<br \/>\n\/\/ endIf is not necessary in Swift<\/p>\n<hr \/>\n<p><strong>HOW TO DEFINE AN ARRAY OF STRINGS<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>HOW TO CREATE AN ARRAY FROM ONE LONG STRING<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>HOW TO CREATE AN ARRAY OF NUMBERS<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>HOW TO GET THE VALUE OF AN ARRAY MEMBER<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>HOW TO GET THE POSITION OF A LETTER WITHIN AN ARRAY<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>REPEAT &#8211; WHILE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>DO &#8211; WHILE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>FOR &#8211; NEXT<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>LOOP<\/strong><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>DO &#8211; CATCH<\/strong><\/p>\n<p>do {<br \/>\nlet contents = try&#8230;<br \/>\n\/\/ OK let run<br \/>\n} catch {<br \/>\n\/\/ error<br \/>\n}<\/p>\n<hr \/>\n<p><strong>OPENING AND CLOSING A FILE<\/strong><\/p>\n<p>let file = openfile()<\/p>\n<p>close file (file)<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p><strong>DEFER &#8211; DO THIS WHEN FUNCTION EXITS<\/strong><\/p>\n<p>defer { whatever }<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>PASSING DATA FROM ONE VIEW CONTROLLER TO ANOTHER<\/strong><\/p>\n<p>This was very complex, so I am posting it to it&#8217;s own page.  CLICK HERE TO ACCESS IT or use the navigation bar to the right.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CLICK HERE for the Apple xCode Project Examples Developer Library, or just type http:\/\/tinyurl.com\/xcodelibrary if you are not on this page. USEFUL SYNTAX(es) AND CODE EXAMPLES IF STATEMENT var myString = String() if X == array_Name.indexOf(myCharacters) { myString = &#8220;Statement One&#8221; } else if X = Y { MyString = &#8220;Second Statement&#8221; } else { &hellip; <a href=\"http:\/\/r0b3rt.com\/andr-web\/swift-2-code-examples\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Swift 2 &#8211; Code Examples&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-writing-code"],"_links":{"self":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":1,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":26,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts\/25\/revisions\/26"}],"wp:attachment":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}