This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1,2,3,4,5] | |
let doubleArray = array.map { $0 * 2 } | |
print(doubleArray) // returns [2,4,6,8,10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let players = ["Gerrard", "Dalglish", "Barnes"] | |
let playersUpper = players.map { $0.uppercased() } | |
print(playersUpper) // returns ["GERRARD", "DALGLISH", "BARNES"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let players = ["Gerrard", "Dalglish", "Barnes"] | |
var playersUppercased = [String]() | |
for player in players { | |
playersUppercased.append(player.uppercased()) | |
} | |
print(playersUppercased) // returns ["GERRARD", "DALGLISH", "BARNES"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let allPlayers = players.flatMap{ $0.uppercased() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let players = ["Gerrard", "Dalglish", "Barnes"] | |
players.map { $0.uppercased() } //produces ["GERRARD", "DALGLISH", "BARNES"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// map function | |
let array = [1,2,3,4,5] | |
let doubleArray = array.map { $0 * 2 } //produces [2,4,6,8,10] | |
let players = ["Gerrard", "Dalglish", "Barnes"] | |
//Create a function upper which takes a String and returns an uppercased String | |
func upper(name: String) -> String { | |
return name.uppercased() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
let css = "body { background-color : #ff0000 }" | |
let js = "var style = document.createElement('style'); style.innerHTML = '\(css)'; document.head.appendChild(style);" | |
webView.evaluateJavaScript(js, completionHandler: nil) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
@IBAction func buttonTapped(_ sender: Any) { | |
performSegue(withIdentifier: "showWebView", sender: sender) | |
} | |
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import WebKit | |
class WebViewController: UIViewController, WKNavigationDelegate { | |
var webView: WKWebView! | |
var colour: String? | |
override func loadView() { | |
webView = WKWebView() |
NewerOlder