{"id":12189,"date":"2015-02-06T05:05:17","date_gmt":"2015-02-05T18:05:17","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=12189"},"modified":"2019-10-04T19:48:02","modified_gmt":"2019-10-04T09:48:02","slug":"swift-ios-webview-mobile-application-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/swift-ios-webview-mobile-application-primer-tutorial\/","title":{"rendered":"Swift Xcode iOS UIWebView Mobile Application Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/RhopalicSentence\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Swift Xcode iOS WebView Mobile Application Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/RhopalicSentence\/rhopalic_sentence_ios.jpg\" title=\"Swift Xcode iOS WebView Mobile Application Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Swift Xcode iOS WebView Mobile Application Primer Tutorial<\/p><\/div>\n<p>Yesterday we prepared a web application for mobile friendliness with <a target=_blank title='PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial' href='#prlsgmft'>PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial<\/a> as shown below and today we build on the knowledge of <a target=_blank title='Swift Hello World Primer Tutorial' href='#shwpt'>Swift Hello World Primer Tutorial<\/a> as shown way below to be on a Mac laptop as we build an Xcode Swift iOS  mobile application for our Rhopalic Letter Sentence game.  We deal with the <i>&#8220;middle game&#8221;<\/i> aspects of this Xcode Swift iOS project for today.<\/p>\n<p>The <a target=_blank href='https:\/\/developer.apple.com\/library\/ios\/documentation\/UIKit\/Reference\/UIWebView_Class\/index.html' title='UIWebView information from Apple'>UIWebView<\/a> we use today does not rely on a Main.<a target=_blank title='Storyboard information from Apple' href='https:\/\/developer.apple.com\/library\/ios\/recipes\/xcode_help-IB_storyboard\/_index.html'>Storyboard<\/a> but rather loads programmatically from within the ViewController.swift code as shown below.  The two main Swift programming source code files of interest are &#8230;<\/p>\n<ul>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/RhopalicSentence\/AppDelegate.swift_GETME\" title='AppDelegate.swift'>AppDelegate.swift<\/a><\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/RhopalicSentence\/ViewController.swift_GETME\" title='ViewController.swift'>ViewController.swift<\/a><\/li>\n<\/ul>\n<p>Today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/RhopalicSentence\/\" title='Click picture'>tutorial<\/a> shows the mobile application being tested on an iPhone 6 simulator and a real iPad device, showing the <i>Universal<\/i> nature of the default Xcode Swift iOS project settings, and the power of the Xcode IDE to get you so far along with mobile software development in a short amount of time.   Cute, huh?!<\/p>\n<p>Would really like to thank the writers of this <a target=_blank href='http:\/\/sourcefreeze.com\/uiwebview-example-using-swift-in-ios\/' title='Useful link'>link<\/a> for their excellent information.<\/p>\n<hr \/>\n<p id='prlsgmft'>Previous relevant <a target=_blank title='PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=12145'>PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rhopalic_letter_sentence.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rhopalic_letter_sentence.gif\" title=\"PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial\"    \/><\/a><p class=\"wp-caption-text\">PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial<\/p><\/div>\n<p>To make a web application more mobile device friendly, there is the look and the usability to consider.  When you consider the look you should try to take into account, very small device widths, as would be applicable for a lot of smartphones.  As far as usability goes, one thing we&#8217;ve found is that keyboard entry is less friendly than for your laptop, or desktop computer.<\/p>\n<p>This is a huge topic area, but put the spotlight on a tutorial web application from a few days back to see some of the issues &#8230; do you remember <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=12084'>PHP Rhopalic Letter Sentence Game Primer Tutorial<\/a>?  As a first look through for mobile friendliness, we touched on &#8230;<\/p>\n<ul>\n<li>add functionality so that the choice is there for less keyboard initializing taking place &#8230; if all keyboard can happen in one or two places that is better than for lots of textbox places, on mobile devices<\/li>\n<li>make <i>input type=&#8221;text&#8221;<\/i> tiny bit wider<\/li>\n<li>if down the track you think this will be the innards of a WebView of a mobile application, stop any navigation that takes you to another webpage, else accompany any WebView with <i>&#8220;back&#8221;<\/i> and <i>&#8220;forward&#8221;<\/i> buttons (whose functionality is most likely neatly encapsulated by easy measures you can take within the IDE you are using)<\/li>\n<li>use a PHP <a target=_blank title='PHP mail function' href='http:\/\/php.net\/manual\/en\/function.mail.php'>mail<\/a> (server-side) method of emailing rather than using an HTML <i>a<\/i> tag <a target=_blank title='mailto information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tryit.asp?filename=tryhtml_link_mailto'><i>mailto:<\/i><\/a> <a target=_blank title='HTML a tag information from w3schools' href='http:\/\/www.w3schools.com\/tags\/tag_a.asp'><i>href<\/i><\/a> value (client-side method, that relies on an email client program) &#8230; this is only an issue, if down the line, this may become the innards of a WebView in a mobile application<\/li>\n<li>at the client (and this is perhaps the better, but not the only (ie. if PHP server-side is involved, <a target=_blank title='Some PHP research and development ideas regarding mobile device detection could start here ... thanks' href='http:\/\/stackoverflow.com\/questions\/4117555\/simplest-way-to-detect-a-mobile-device'>it can be done there too<\/a>, but not the same way &#8230; doh!), place to test for it), with Javascript, use a test like &#8230;<br \/>\n<code><br \/>\nif (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n  \/\/ it is a mobile device<br \/>\n}<br \/>\n<\/code><br \/>\n &#8230; great thanks to this <a target=_blank title='Great cross-platform advice' href='http:\/\/www.abeautifulsite.net\/detecting-mobile-devices-with-javascript\/'>link<\/a> for this advice and idea\n<\/li>\n<li>use meta tag like &#8230;<br \/>\n<code><br \/>\n&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=yes\" \/&gt;<br \/>\n<\/code><br \/>\n&#8230; between &lt;head&gt; and &lt;\/head&gt; &#8230; as you can imagine, there are huge variations in requirements here, and if you want a start at some more R&#038;D, have a read of a Firefox  (after all, this is a cross-browser, as well as cross-platform, issue) <a target=_blank title='Firefox take (after all, this is a cross-browser, as well as cross-platform, issue) on viewport meta tag regarding mobile devices' href='https:\/\/developer.mozilla.org\/en\/docs\/Mozilla\/Mobile\/Viewport_meta_tag'>webpage<\/a> talking about the viewport meta tag regarding mobile devices<\/li>\n<\/ul>\n<p>&#8230; to, hopefully, improve it as a mobile web application, and hopefully, as a web application generally.<\/p>\n<p>Please tee up a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rhopalic_letter_sentence.php\" title='Click picture'>live run<\/a> with the PHP programming source code <a target=_blank  download=\"rhopalic_letter_sentence.php\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/rhopalic_letter_sentence.php-GETME\" title='rhopalic_letter_sentence.php'>rhopalic_letter_sentence.php<\/a> (changed from a few days ago, to make it more mobile friendly, as per <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/rhopalic_letter_sentence.php-GETME\" title='rhopalic_letter_sentence.php'>rhopalic_letter_sentence.php<\/a>).<\/p>\n<hr \/>\n<p id='shwpt'>Previous relevant <a target=_blank title='Swift Hello World Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10998'>Swift Hello World Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/HelloWorld\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Swift Hello World Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/HelloWorld\/Swift_HelloWorld-95of.jpg\" title=\"Swift Hello World Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Swift Hello World Primer Tutorial<\/p><\/div>\n<p>The last (and only) time we talked about Apple&#8217;s new programming language for iOS development, <a target=_blank title='Swift' href='https:\/\/developer.apple.com\/swift\/'>Swift<\/a>, was in terms of learning a bit about the similar Rust language when we presented <a target=_blank href='#rpt' title='Rust Primer Tutorial'>Rust Primer Tutorial<\/a> as shown below, mainly because it was hard, then, at least for us, to track down much about the Swift language.<\/p>\n<p>Things have moved on since, and with iOS 8.1 you can develop Swift based mobile applications totally with Swift, instead of Objective-C, and as with recent times of Objective-C iOS work the Storyboard has taken over as the default GUI arrangement in preference to the use of XIB files.<\/p>\n<p>Today&#8217;s project is a Hello World project, so it is very simple, and, perhaps, unless you are well into Swift already, it is best to start simple and build up.  With this in mind we model the Hello World project on the advice from <a target=_blank href='http:\/\/www.makemegeek.com\/hello-world-example-swift\/' title='Hello World Example in Swift'>Hello World Example in Swift<\/a> (thanks) but please bear in mind that it ended up to be simpler in iOS 8.1 because we can pick a &#8220;Single View iOS Application&#8221; and use Storyboards, and lots of the AppDelegate.swift advice is no longer required to achieve, now, in iOS 8.1, with regard to what that tutorial sets out to achieve &#8230; and all that we aim to achieve today with the application Run today on an iPhone simulator and a real iPad device.<\/p>\n<p>Don&#8217;t like to give up on Objective-C, but have to say, that by the end of a day of struggle, I can see and feel that there could be some good streamlinings lately in the organization of these Xcode iOS mobile projects in Swift &#8230; maybe Swift by name, and &#8220;pretty fast&#8221; by nature &#8230; chortle, chortle.<\/p>\n<p>If you think &#8220;control drag&#8221; is no longer needed, though, think again &#8230; Mac laptop keyboard &#8220;control drag&#8221; was used to create the blue line links on <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/HelloWorld\/Swift_HelloWorld-87of.jpg\">this tutorial slide<\/a> &#8230; &#8220;practice makes perfect&#8221;.<\/p>\n<p>Here are two parts of the Swift code for our Hello World application you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/HelloWorld\/AppDelegate.swift_GETME\" title=\"AppDelegate.swift\">AppDelegate.swift<\/a> and <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/iOS8\/Swift\/HelloWorld\/ViewController.swift_GETME\" title=\"ViewController.swift\">ViewController.swift<\/a><\/p>\n<p>Hope you enjoy using Swift.<\/p>\n<hr \/>\n<p id='rpt'>Previous relevant <a target=_blank href='http:\/\/www.rjmprogramming.com.au.wordpress\/?p=7932' title='Rust Primer Tutorial'>Rust Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Rust\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Rust Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Rust\/Rust_Primer-39of.jpg\" title=\"Rust Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Rust Primer Tutorial<\/p><\/div>\n<p>The <a target=_blank href='http:\/\/taocurrents.files.wordpress.com\/2011\/12\/mp13a.jpg?w=529&#038;h=576' title='Thanks for this.'>wind<\/a> is still blowing.  And they (that being a really tiny proportion of the populace, at large) are still calling the wind <a target=_blank href='http:\/\/www.youtube.com\/watch?v=3DrOqRQQ9mg' title='They call the wind Mariah'>Mariah<\/a>.  Do you see those exhausted butterflies in Brazil flapping (a bit less than) faster?<\/p>\n<p>Today we try out the programming language Rust, mainly because it has a lot in common with the upcoming iOS language Swift, and because Rust looks very powerful.   Rust is an open source language that relies on a few prerequisites for installation.   As we had these pre-requisites here, luckily, on this Mac laptop we did not have to wrestle with these issues (personally, I like the <strike>abominable stretch<\/strike> abdominal stretch (by <a target=_blank title='Mario Milano' href='https:\/\/www.google.com.au\/search?q=%22mario+milano%22+%22abdominal+stretch%22&#038;tbm=isch&#038;source=lnms&#038;sa=X&#038;ei=oumPU5GIIY26lQX88ICYDQ&#038;ved=0CAYQ_AUoAQ&#038;biw=1061&#038;bih=553#facrc=_&#038;imgdii=_&#038;imgrc=FFuILecN5eGfmM%253A%3B63-Knp066fwUJM%3Bhttp%253A%252F%252Fwww.onlineworldofwrestling.com%252Fpictures%252F11%252Farionlewin.jpg%3Bhttp%253A%252F%252Fforums.leagueunlimited.com%252Fshowthread.php%253Fp%253D6295319%3B602%3B494'>Mario Milano<\/a>) regarding &#8220;best techniques&#8221; here).  Below are what this hugely useful <a target=_blank title='Rust prerequisites' href='http:\/\/doc.rust-lang.org\/tutorial.html#getting-started'>link<\/a> explains are the prerequisites for Rust usage:<\/p>\n<ul>\n<li>g++ 4.7 or clang++ 3.x<\/li>\n<li>python 2.6 or later (but not 3.x)<\/li>\n<li>perl 5.0 or later<\/li>\n<li>gnu make 3.81 or later<\/li>\n<li>curl<\/li>\n<\/ul>\n<p>So, today, we try a Hello World scenario in Rust.  The motivation here is learning and preparation for future use of Swift for Xcode iOS 8 programming, perhaps.  As they say in the boy scouts &#8220;be prepared&#8221;.<\/p>\n<p>Here is the Rust programming source code used here, which you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Rust\/hellofromrjm.rs_GETME\" title='hellofromrjm.rs'>hellofromrjm.rs<\/a><\/p>\n<p>Here is a link to a <a target=_blank title='Rust home page' href='http:\/\/www.rust-lang.org\/'>Rust<\/a> home page.<\/p>\n<p>Hope you get something out of today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Rust\/\" title='Click picture.'>tutorial<\/a>.   We give thanks to the information of some of the links on this <a target=_blank href='https:\/\/www.google.com.au\/?gfe_rd=ctrl&#038;ei=3s4rU6TsBsHC8gfOtYHAAw&#038;gws_rd=cr#q=%22Swift%22+%22iOS%22' title='Thanks'>Google search<\/a> for the leads here.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#7932' onclick='var dv=document.getElementById(\"d7932\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=iOS\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7932' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#10998' onclick='var dv=document.getElementById(\"d10998\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=iOS\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10998' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d12145' onclick='var dv=document.getElementById(\"d12145\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=mobile\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d12145' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#12189' onclick='var dv=document.getElementById(\"d12189\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Swift\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d12189' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday we prepared a web application for mobile friendliness with PHP Rhopalic Letter Sentence Game Mobile Friendly Tutorial as shown below and today we build on the knowledge of Swift Hello World Primer Tutorial as shown way below to be &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/swift-ios-webview-mobile-application-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,20,37,40],"tags":[91,585,626,630,631,633,723,791,795,796,798,997,999,1144,1166,1168,1204,1227,1319,1329,1473],"class_list":["post-12189","post","type-post","status-publish","format-standard","hentry","category-elearning","category-ios","category-tutorials","category-xcode","tag-apple","tag-ide","tag-ios","tag-ipad","tag-iphone","tag-iphone-6","tag-mac","tag-middle-game","tag-mobile","tag-mobile-app","tag-mobile-friendly","tag-programming","tag-project","tag-simulator","tag-software-2","tag-software-integration","tag-storyboard","tag-swift","tag-tutorial","tag-uiwebview","tag-xcode"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/12189"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=12189"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/12189\/revisions"}],"predecessor-version":[{"id":46655,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/12189\/revisions\/46655"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=12189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=12189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=12189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}