【Swift】チュートリアルNo.3 Beginning iOS13&Swift App Development

AmazonのKindle読み放題で「Beginning iOS13&Swift App Development」という本を見つけた。

英語で書かれた本だが、初心者向けの教科書になリます。

早速、内容を読みながらプログラム入力していきます。
Swift初期に学んだ内容が多いが、バージョンアップごとに
書式が変わっている。

Chapter 2: Quotes App Using TableView
を読みながら入力する。
iPadでkindleを表示しなが、MacBookProの
Xcodeでプログラムをコピーしていく。

残念ながら、ソースコードを公開していないので、困難なことが多い。
また、1箇所誤植があって、苦労しました。

ソースコードは、下記に掲載します。

//  QuotesTableViewController.swift

//  QuickQuotes
import UIKit
class QuotesTableViewController: UITableViewController {
    var quotes = [ “I love you the more”,“There is nothing permanent”, “You cannot shake hands… “,“Thank you for trying your best to answer the exercises in this material.It may be challenging so I understand the struggle.You can review the sentences below and try to come up with your own. When we meet next time. I will answer the questions first so you can listen to me and have an idea how to make your own sentences. See you..”]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    // MARK: – Table view data source
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return quotes.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = quotes[indexPath.row]
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let selectedQuote = quotes[indexPath.row]
        performSegue(withIdentifier: “moveToQuoteDetail”, sender: selectedQuote)
    }
    // MARK: – Navigation
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
        if let quoteViewController = segue.destination as? QuoteDetailViewController{
            if let selectedQuote = sender as? String {
                quoteViewController.quote = selectedQuote
            }
        }
    }
   
}

 QuoteDetailViewController.swift

//  QuickQuotes
//
import UIKit
class QuoteDetailViewController: UIViewController {
    
    var quote = “”
    
    @IBOutlet weak var quoteLabel: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        quoteLabel.text = quote
       
    }
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA