This file contains hidden or 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 urlString = "https://myiosapp.com" | |
let result = try! validateUrl(urlString: urlString) | |
// the result is always true or valid url |
This file contains hidden or 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 urlString = "" | |
// converting value to nil, if it error | |
let result = try? validateUrl(urlString: urlString) | |
// handle optional value | |
if result != nil { | |
print("the url is valid") | |
} else { | |
print("the url is not valid") |
This file contains hidden or 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
// Step 3 use do try catch | |
let urlString = "" | |
do { | |
let result = try validateUrl(urlString: urlString) | |
// Step 5 continue the process if it success | |
print("is url valid? \(result)") | |
} | |
catch { | |
// Step 4 show error to users |
This file contains hidden or 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 | |
// Step 2 create enum for custom error | |
enum CustomError: Error { | |
case invalidUrl | |
case emptyUrl | |
case other | |
} |
This file contains hidden or 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
// | |
// ViewController.swift | |
// GettingStartedUITableView | |
// | |
// Created by Sigit on 13/11/20. | |
// | |
import UIKit | |
class ViewController: UIViewController { |
This file contains hidden or 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
// | |
// ViewController.swift | |
// GettingStartedUITableView | |
// | |
// Created by Sigit on 13/11/20. | |
// | |
import UIKit | |
class ViewController: UIViewController { |
This file contains hidden or 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
class ViewController: UIViewController { | |
// create property tableview | |
private let tableView: UITableView = { | |
let tableView = UITableView() | |
tableView.backgroundColor = .white | |
tableView.translatesAutoresizingMaskIntoConstraints = false | |
return tableView | |
}() |
This file contains hidden or 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 React, { Component } from 'react'; | |
class App extends Component { | |
state = { | |
number: 0, | |
update: true | |
} | |
componentWillMount () { | |
console.log('Component WILL MOUNT') |
This file contains hidden or 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 React from 'react' | |
import ReactDOM from 'react-dom' | |
import App from './components/app' | |
ReactDOM.render(<App />, document.querySelector('.container')) | |
// this will remove component from DOM after 10000 ms | |
setTimeout(() => { | |
ReactDOM.unmountComponentAtNode(document.querySelector('.container')) | |
}, 10000) |