fork download
  1. // we read standard input line by line
  2. while let line = readLine() {
  3. // we write the line to the standard output
  4. print(line)
  5. }
Success #stdin #stdout 0.01s 7400KB
stdin
swift import UIKit class ToDoViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var toDoList = [Buy milk, Call friend] let tableView = UITableView() override func viewDidLoad() { super.viewDidLoad() setupTableView() setupAddButton() title = To-Do List } func setupTableView() { tableView.frame = view.bounds tableView.delegate = self tableView.dataSource = self tableView.register(UITableViewCell.self, forCellReuseIdentifier: cell) view.addSubview(tableView) } func setupAddButton() { let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTask)) navigationItem.rightBarButtonItem = addButton } @objc func addTask() { let alert = UIAlertController(title: New Task, message: Enter task name, preferredStyle: .alert) alert.addTextField { textField in textField.placeholder = Task } let addAction = UIAlertAction(title: Add, style: .default) { _ in if let task = alert.textFields?.first?.text, !task.isEmpty { self.toDoList.append(task) self.tableView.reloadData() } } alert.addAction(addAction) alert.addAction(UIAlertAction(title: Cancel, style: .cancel)) present(alert, animated: true) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return toDoList.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: cell, for: indexPath) cell.textLabel?.text = toDoList[indexPath.row] return cell } 
stdout
swift import UIKit class ToDoViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var toDoList = [Buy milk, Call friend] let tableView = UITableView() override func viewDidLoad() { super.viewDidLoad() setupTableView() setupAddButton() title = To-Do List } func setupTableView() { tableView.frame = view.bounds tableView.delegate = self tableView.dataSource = self tableView.register(UITableViewCell.self, forCellReuseIdentifier: cell) view.addSubview(tableView) } func setupAddButton() { let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTask)) navigationItem.rightBarButtonItem = addButton } @objc func addTask() { let alert = UIAlertController(title: New Task, message: Enter task name, preferredStyle: .alert) alert.addTextField { textField in textField.placeholder = Task } let addAction = UIAlertAction(title: Add, style: .default) { _ in if let task = alert.textFields?.first?.text, !task.isEmpty { self.toDoList.append(task) self.tableView.reloadData() } } alert.addAction(addAction) alert.addAction(UIAlertAction(title: Cancel, style: .cancel)) present(alert, animated: true) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return toDoList.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: cell, for: indexPath) cell.textLabel?.text = toDoList[indexPath.row] return cell }