質問編集履歴
6
コードを修正しました
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -1,10 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ###前提・実現したいこと
         
     | 
| 
      
 2 
     | 
    
         
            +
            エラーを消したい。
         
     | 
| 
       2 
3 
     | 
    
         
             
            テーブルビューにイメージとテキストを表示したい。
         
     | 
| 
       3 
     | 
    
         
            -
            修正が必要な箇所を自分で探し出せるようになりたい。
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            ###発生している問題・エラーメッセージ
         
     | 
| 
       6 
6 
     | 
    
         
             
            ```
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            <ViewController.swift>
         
     | 
| 
      
 8 
     | 
    
         
            +
            cell.setCell(resultArrays: resultArray[indexPath.row], sResultArrays: sResultArray[indexPath.row])
         
     | 
| 
      
 9 
     | 
    
         
            +
            上記箇所で以下のエラーが出ています。
         
     | 
| 
      
 10 
     | 
    
         
            +
            Cannot convert value of type 'UIImage' to expected argument type 'String'
         
     | 
| 
       8 
11 
     | 
    
         | 
| 
       9 
12 
     | 
    
         
             
            ```
         
     | 
| 
       10 
13 
     | 
    
         | 
| 
         @@ -36,8 +39,6 @@ 
     | 
|
| 
       36 
39 
     | 
    
         
             
                       sResultArray = UserDefaults.standard.object(forKey: "sArray") as! [String]
         
     | 
| 
       37 
40 
     | 
    
         
             
                    }
         
     | 
| 
       38 
41 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                    
         
     | 
| 
       40 
     | 
    
         
            -
                    
         
     | 
| 
       41 
42 
     | 
    
         
             
                    if UserDefaults.standard.object(forKey: "douga") != nil {
         
     | 
| 
       42 
43 
     | 
    
         
             
                        newResultArray = UserDefaults.standard.object(forKey: "douga") as! [Data]
         
     | 
| 
       43 
44 
     | 
    
         
             
                        resultArray.removeAll()
         
     | 
| 
         @@ -50,8 +51,7 @@ 
     | 
|
| 
       50 
51 
     | 
    
         
             
                    }
         
     | 
| 
       51 
52 
     | 
    
         
             
                    tableView.reloadData()
         
     | 
| 
       52 
53 
     | 
    
         
             
                }
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                    
         
     | 
| 
      
 54 
     | 
    
         
            +
                 
         
     | 
| 
       55 
55 
     | 
    
         
             
                func numberOfSections(in tableView: UITableView) -> Int {
         
     | 
| 
       56 
56 
     | 
    
         
             
                    return 1
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
         @@ -63,15 +63,9 @@ 
     | 
|
| 
       63 
63 
     | 
    
         | 
| 
       64 
64 
     | 
    
         
             
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         
     | 
| 
       65 
65 
     | 
    
         
             
                    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for:indexPath) as! CustomTableViewCell
         
     | 
| 
       66 
     | 
    
         
            -
                    cell. 
     | 
| 
      
 66 
     | 
    
         
            +
                    cell.setCell(resultArrays: resultArray[indexPath.row], sResultArrays: sResultArray[indexPath.row])
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                    // let img = UIImage(named: resultArray[indexPath.row] as! String)
         
     | 
| 
       69 
     | 
    
         
            -
                    // let imageView = cell.viewWithTag(1) as! UIImageView
         
     | 
| 
       70 
     | 
    
         
            -
                    // imageView.image = img
         
     | 
| 
       71 
68 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
                    // let textView = cell.viewWithTag(2) as! UITextView
         
     | 
| 
       73 
     | 
    
         
            -
                    // textView.text = String(describing: sResultArray[indexPath.row])
         
     | 
| 
       74 
     | 
    
         
            -
                    
         
     | 
| 
       75 
69 
     | 
    
         
             
                    return cell
         
     | 
| 
       76 
70 
     | 
    
         
             
                }
         
     | 
| 
       77 
71 
     | 
    
         | 
| 
         @@ -80,8 +74,6 @@ 
     | 
|
| 
       80 
74 
     | 
    
         
             
                    super.didReceiveMemoryWarning()
         
     | 
| 
       81 
75 
     | 
    
         
             
                    // Dispose of any resources that can be recreated.
         
     | 
| 
       82 
76 
     | 
    
         
             
                }
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
77 
     | 
    
         
             
            }
         
     | 
| 
       86 
78 
     | 
    
         | 
| 
       87 
79 
     | 
    
         
             
            ```
         
     | 
| 
         @@ -107,99 +99,12 @@ 
     | 
|
| 
       107 
99 
     | 
    
         
             
                }
         
     | 
| 
       108 
100 
     | 
    
         | 
| 
       109 
101 
     | 
    
         
             
                /// 画像・タイトル・説明文を設定するメソッド
         
     | 
| 
       110 
     | 
    
         
            -
                func setCell( 
     | 
| 
      
 102 
     | 
    
         
            +
                func setCell(resultArrays: String, sResultArrays: String) {
         
     | 
| 
       111 
     | 
    
         
            -
                    myImageView.image =  
     | 
| 
      
 103 
     | 
    
         
            +
                    myImageView.image = UIImage(named: resultArrays)
         
     | 
| 
       112 
     | 
    
         
            -
                    myTextView.text =  
     | 
| 
      
 104 
     | 
    
         
            +
                    myTextView.text = sResultArrays
         
     | 
| 
       113 
105 
     | 
    
         
             
                }
         
     | 
| 
       114 
     | 
    
         
            -
                
         
     | 
| 
       115 
106 
     | 
    
         
             
            }
         
     | 
| 
       116 
107 
     | 
    
         
             
            ```
         
     | 
| 
       117 
     | 
    
         
            -
            ###
         
     | 
| 
       118 
     | 
    
         
            -
            ```
         
     | 
| 
       119 
     | 
    
         
            -
            import UIKit
         
     | 
| 
       120 
108 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
            class AddViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                @IBOutlet var imageView: UIImageView!
         
     | 
| 
       124 
     | 
    
         
            -
                @IBOutlet var textField: UITextField!
         
     | 
| 
       125 
     | 
    
         
            -
                
         
     | 
| 
       126 
     | 
    
         
            -
                var array = [UIImage]()
         
     | 
| 
       127 
     | 
    
         
            -
                var newArray = [Data]()
         
     | 
| 
       128 
     | 
    
         
            -
                var sArray = [String]()
         
     | 
| 
       129 
     | 
    
         
            -
                
         
     | 
| 
       130 
     | 
    
         
            -
                override func viewDidLoad() {
         
     | 
| 
       131 
     | 
    
         
            -
                    super.viewDidLoad()
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                    imageView.image = UIImage(named: "default.png")
         
     | 
| 
       134 
     | 
    
         
            -
                    
         
     | 
| 
       135 
     | 
    
         
            -
                }
         
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                override func didReceiveMemoryWarning() {
         
     | 
| 
       138 
     | 
    
         
            -
                    super.didReceiveMemoryWarning()
         
     | 
| 
       139 
     | 
    
         
            -
                    // Dispose of any resources that can be recreated.
         
     | 
| 
       140 
     | 
    
         
            -
                }
         
     | 
| 
       141 
     | 
    
         
            -
                
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                @IBAction func sentaku(_ sender: Any) {
         
     | 
| 
       144 
     | 
    
         
            -
                    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
         
     | 
| 
       145 
     | 
    
         
            -
                        // 写真を選ぶビュー
         
     | 
| 
       146 
     | 
    
         
            -
                        let pickerView = UIImagePickerController()
         
     | 
| 
       147 
     | 
    
         
            -
                        // 写真の選択元
         
     | 
| 
       148 
     | 
    
         
            -
                        pickerView.sourceType = .photoLibrary
         
     | 
| 
       149 
     | 
    
         
            -
                        pickerView.delegate = self
         
     | 
| 
       150 
     | 
    
         
            -
                        self.present(pickerView, animated: true)
         
     | 
| 
       151 
     | 
    
         
            -
                    }
         
     | 
| 
       152 
     | 
    
         
            -
                }
         
     | 
| 
       153 
     | 
    
         
            -
                
         
     | 
| 
       154 
     | 
    
         
            -
                // 写真を選んだ後の処理
         
     | 
| 
       155 
     | 
    
         
            -
                func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
         
     | 
| 
       156 
     | 
    
         
            -
                    // 選択した写真を取得
         
     | 
| 
       157 
     | 
    
         
            -
                    let image = info[UIImagePickerControllerOriginalImage] as! UIImage
         
     | 
| 
       158 
     | 
    
         
            -
                    // ビューに表示
         
     | 
| 
       159 
     | 
    
         
            -
                    self.imageView.image = image
         
     | 
| 
       160 
     | 
    
         
            -
                    // ビューを閉じる
         
     | 
| 
       161 
     | 
    
         
            -
                    self.dismiss(animated: true)
         
     | 
| 
       162 
     | 
    
         
            -
                }
         
     | 
| 
       163 
     | 
    
         
            -
                
         
     | 
| 
       164 
     | 
    
         
            -
                
         
     | 
| 
       165 
     | 
    
         
            -
                @IBAction func add(_ sender: Any) {
         
     | 
| 
       166 
     | 
    
         
            -
                    
         
     | 
| 
       167 
     | 
    
         
            -
                    sArray.append(textField.text!)
         
     | 
| 
       168 
     | 
    
         
            -
                    //配列をアプリに保存する
         
     | 
| 
       169 
     | 
    
         
            -
                    UserDefaults.standard.set(sArray, forKey: "sArray")
         
     | 
| 
       170 
     | 
    
         
            -
                    
         
     | 
| 
       171 
     | 
    
         
            -
                    
         
     | 
| 
       172 
     | 
    
         
            -
                    
         
     | 
| 
       173 
     | 
    
         
            -
                    if UserDefaults.standard.object(forKey: "douga") != nil{
         
     | 
| 
       174 
     | 
    
         
            -
                       array = UserDefaults.standard.object(forKey: "douga") as! [UIImage]
         
     | 
| 
       175 
     | 
    
         
            -
                        newArray = UserDefaults.standard.object(forKey: "douga") as! [Data]
         
     | 
| 
       176 
     | 
    
         
            -
                    }
         
     | 
| 
       177 
     | 
    
         
            -
                    
         
     | 
| 
       178 
     | 
    
         
            -
                    //        array.append(imageView.image!)
         
     | 
| 
       179 
     | 
    
         
            -
                    guard let image = imageView.image else {
         
     | 
| 
       180 
     | 
    
         
            -
                        return
         
     | 
| 
       181 
     | 
    
         
            -
                    }
         
     | 
| 
       182 
     | 
    
         
            -
                    let data = UIImagePNGRepresentation(image)
         
     | 
| 
       183 
     | 
    
         
            -
                    if let dt = data {
         
     | 
| 
       184 
     | 
    
         
            -
                        newArray.append(dt)
         
     | 
| 
       185 
     | 
    
         
            -
                        UserDefaults.standard.set(newArray, forKey: "douga")
         
     | 
| 
       186 
     | 
    
         
            -
                        self.navigationController?.popViewController(animated: true)
         
     | 
| 
       187 
     | 
    
         
            -
                    }
         
     | 
| 
       188 
     | 
    
         
            -
                }
         
     | 
| 
       189 
     | 
    
         
            -
                
         
     | 
| 
       190 
     | 
    
         
            -
                
         
     | 
| 
       191 
     | 
    
         
            -
                /*
         
     | 
| 
       192 
     | 
    
         
            -
                // MARK: - Navigation
         
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
                // In a storyboard-based application, you will often want to do a little preparation before navigation
         
     | 
| 
       195 
     | 
    
         
            -
                override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
         
     | 
| 
       196 
     | 
    
         
            -
                    // Get the new view controller using segue.destinationViewController.
         
     | 
| 
       197 
     | 
    
         
            -
                    // Pass the selected object to the new view controller.
         
     | 
| 
       198 
     | 
    
         
            -
                }
         
     | 
| 
       199 
     | 
    
         
            -
                */
         
     | 
| 
       200 
     | 
    
         
            -
            }
         
     | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
            ```
         
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
109 
     | 
    
         
             
            ###補足情報(言語/FW/ツール等のバージョンなど)
         
     | 
| 
       205 
110 
     | 
    
         
             
            Xcode Version 9.2 (9C40b)
         
     | 
5
コードを修正しました
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -12,24 +12,194 @@ 
     | 
|
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            ###該当のソースコード
         
     | 
| 
       14 
14 
     | 
    
         
             
            ```ここに言語を入力
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
            import UIKit
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
            class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
                @IBOutlet var tableView: UITableView!
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                var resultArray = [UIImage]()
         
     | 
| 
      
 22 
     | 
    
         
            +
                var newResultArray: [Data]!
         
     | 
| 
      
 23 
     | 
    
         
            +
                var sResultArray = [String]()
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                override func viewDidLoad() {
         
     | 
| 
      
 26 
     | 
    
         
            +
                    super.viewDidLoad()
         
     | 
| 
      
 27 
     | 
    
         
            +
                    
         
     | 
| 
      
 28 
     | 
    
         
            +
                    tableView.delegate = self
         
     | 
| 
      
 29 
     | 
    
         
            +
                    tableView.dataSource = self
         
     | 
| 
      
 30 
     | 
    
         
            +
                    
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
       18 
32 
     | 
    
         | 
| 
      
 33 
     | 
    
         
            +
                override func viewWillAppear(_ animated: Bool) {
         
     | 
| 
      
 34 
     | 
    
         
            +
                    super.viewWillAppear(animated)
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                    if UserDefaults.standard.object(forKey: "sArray") != nil {
         
     | 
| 
      
 36 
     | 
    
         
            +
                       sResultArray = UserDefaults.standard.object(forKey: "sArray") as! [String]
         
     | 
| 
      
 37 
     | 
    
         
            +
                    }
         
     | 
| 
       20 
38 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                    let img = UIImage(named: resultArray[indexPath.row] as! String)
         
     | 
| 
       22 
     | 
    
         
            -
                    let imageView = cell.viewWithTag(1) as! UIImageView
         
     | 
| 
       23 
     | 
    
         
            -
                    imageView.image = img
         
     | 
| 
       24 
39 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                    let textView = cell.viewWithTag(2) as! UITextView
         
     | 
| 
       26 
     | 
    
         
            -
                    textView.text = String(describing: rResultArray[indexPath.row])
         
     | 
| 
       27 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
                    if UserDefaults.standard.object(forKey: "douga") != nil {
         
     | 
| 
      
 42 
     | 
    
         
            +
                        newResultArray = UserDefaults.standard.object(forKey: "douga") as! [Data]
         
     | 
| 
      
 43 
     | 
    
         
            +
                        resultArray.removeAll()
         
     | 
| 
      
 44 
     | 
    
         
            +
                        for d in newResultArray {
         
     | 
| 
      
 45 
     | 
    
         
            +
                            let image = UIImage(data: d)
         
     | 
| 
      
 46 
     | 
    
         
            +
                            if let i = image {
         
     | 
| 
      
 47 
     | 
    
         
            +
                                resultArray.append(i)
         
     | 
| 
      
 48 
     | 
    
         
            +
                            }
         
     | 
| 
      
 49 
     | 
    
         
            +
                        }
         
     | 
| 
      
 50 
     | 
    
         
            +
                    }
         
     | 
| 
      
 51 
     | 
    
         
            +
                    tableView.reloadData()
         
     | 
| 
      
 52 
     | 
    
         
            +
                }
         
     | 
| 
      
 53 
     | 
    
         
            +
                
         
     | 
| 
      
 54 
     | 
    
         
            +
                    
         
     | 
| 
      
 55 
     | 
    
         
            +
                func numberOfSections(in tableView: UITableView) -> Int {
         
     | 
| 
      
 56 
     | 
    
         
            +
                    return 1
         
     | 
| 
      
 57 
     | 
    
         
            +
                    
         
     | 
| 
      
 58 
     | 
    
         
            +
                }
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         
     | 
| 
      
 61 
     | 
    
         
            +
                    return resultArray.count
         
     | 
| 
      
 62 
     | 
    
         
            +
                }
         
     | 
| 
      
 63 
     | 
    
         
            +
                
         
     | 
| 
      
 64 
     | 
    
         
            +
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         
     | 
| 
      
 65 
     | 
    
         
            +
                    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for:indexPath) as! CustomTableViewCell
         
     | 
| 
      
 66 
     | 
    
         
            +
                    cell.imageView?.image = resultArray[indexPath.row]
         
     | 
| 
      
 67 
     | 
    
         
            +
                    
         
     | 
| 
      
 68 
     | 
    
         
            +
                    // let img = UIImage(named: resultArray[indexPath.row] as! String)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    // let imageView = cell.viewWithTag(1) as! UIImageView
         
     | 
| 
      
 70 
     | 
    
         
            +
                    // imageView.image = img
         
     | 
| 
      
 71 
     | 
    
         
            +
                    
         
     | 
| 
      
 72 
     | 
    
         
            +
                    // let textView = cell.viewWithTag(2) as! UITextView
         
     | 
| 
      
 73 
     | 
    
         
            +
                    // textView.text = String(describing: sResultArray[indexPath.row])
         
     | 
| 
      
 74 
     | 
    
         
            +
                    
         
     | 
| 
       28 
75 
     | 
    
         
             
                    return cell
         
     | 
| 
      
 76 
     | 
    
         
            +
                }
         
     | 
| 
      
 77 
     | 
    
         
            +
                
         
     | 
| 
      
 78 
     | 
    
         
            +
                
         
     | 
| 
      
 79 
     | 
    
         
            +
                override func didReceiveMemoryWarning() {
         
     | 
| 
      
 80 
     | 
    
         
            +
                    super.didReceiveMemoryWarning()
         
     | 
| 
      
 81 
     | 
    
         
            +
                    // Dispose of any resources that can be recreated.
         
     | 
| 
      
 82 
     | 
    
         
            +
                }
         
     | 
| 
       29 
83 
     | 
    
         | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            }
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       30 
87 
     | 
    
         
             
            ```
         
     | 
| 
      
 88 
     | 
    
         
            +
            ###
         
     | 
| 
      
 89 
     | 
    
         
            +
            ```
         
     | 
| 
      
 90 
     | 
    
         
            +
            import UIKit
         
     | 
| 
       31 
91 
     | 
    
         | 
| 
      
 92 
     | 
    
         
            +
            class CustomTableViewCell: UITableViewCell {
         
     | 
| 
       32 
93 
     | 
    
         | 
| 
      
 94 
     | 
    
         
            +
               
         
     | 
| 
      
 95 
     | 
    
         
            +
                @IBOutlet weak var myImageView: UIImageView!
         
     | 
| 
      
 96 
     | 
    
         
            +
                @IBOutlet weak var myTextView: UITextField!
         
     | 
| 
      
 97 
     | 
    
         
            +
                
         
     | 
| 
      
 98 
     | 
    
         
            +
                override func awakeFromNib() {
         
     | 
| 
      
 99 
     | 
    
         
            +
                    super.awakeFromNib()
         
     | 
| 
      
 100 
     | 
    
         
            +
                    // Initialization code
         
     | 
| 
      
 101 
     | 
    
         
            +
                }
         
     | 
| 
       33 
102 
     | 
    
         | 
| 
      
 103 
     | 
    
         
            +
                override func setSelected(_ selected: Bool, animated: Bool) {
         
     | 
| 
      
 104 
     | 
    
         
            +
                    super.setSelected(selected, animated: animated)
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                    // Configure the view for the selected state
         
     | 
| 
      
 107 
     | 
    
         
            +
                }
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                /// 画像・タイトル・説明文を設定するメソッド
         
     | 
| 
      
 110 
     | 
    
         
            +
                func setCell(resultArray: UIImage, sResultArray: String) {
         
     | 
| 
      
 111 
     | 
    
         
            +
                    myImageView.image = resultArray
         
     | 
| 
      
 112 
     | 
    
         
            +
                    myTextView.text = sResultArray
         
     | 
| 
      
 113 
     | 
    
         
            +
                }
         
     | 
| 
      
 114 
     | 
    
         
            +
                
         
     | 
| 
      
 115 
     | 
    
         
            +
            }
         
     | 
| 
      
 116 
     | 
    
         
            +
            ```
         
     | 
| 
      
 117 
     | 
    
         
            +
            ###
         
     | 
| 
      
 118 
     | 
    
         
            +
            ```
         
     | 
| 
      
 119 
     | 
    
         
            +
            import UIKit
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
            class AddViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                @IBOutlet var imageView: UIImageView!
         
     | 
| 
      
 124 
     | 
    
         
            +
                @IBOutlet var textField: UITextField!
         
     | 
| 
      
 125 
     | 
    
         
            +
                
         
     | 
| 
      
 126 
     | 
    
         
            +
                var array = [UIImage]()
         
     | 
| 
      
 127 
     | 
    
         
            +
                var newArray = [Data]()
         
     | 
| 
      
 128 
     | 
    
         
            +
                var sArray = [String]()
         
     | 
| 
      
 129 
     | 
    
         
            +
                
         
     | 
| 
      
 130 
     | 
    
         
            +
                override func viewDidLoad() {
         
     | 
| 
      
 131 
     | 
    
         
            +
                    super.viewDidLoad()
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                    imageView.image = UIImage(named: "default.png")
         
     | 
| 
      
 134 
     | 
    
         
            +
                    
         
     | 
| 
      
 135 
     | 
    
         
            +
                }
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                override func didReceiveMemoryWarning() {
         
     | 
| 
      
 138 
     | 
    
         
            +
                    super.didReceiveMemoryWarning()
         
     | 
| 
      
 139 
     | 
    
         
            +
                    // Dispose of any resources that can be recreated.
         
     | 
| 
      
 140 
     | 
    
         
            +
                }
         
     | 
| 
      
 141 
     | 
    
         
            +
                
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                @IBAction func sentaku(_ sender: Any) {
         
     | 
| 
      
 144 
     | 
    
         
            +
                    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
         
     | 
| 
      
 145 
     | 
    
         
            +
                        // 写真を選ぶビュー
         
     | 
| 
      
 146 
     | 
    
         
            +
                        let pickerView = UIImagePickerController()
         
     | 
| 
      
 147 
     | 
    
         
            +
                        // 写真の選択元
         
     | 
| 
      
 148 
     | 
    
         
            +
                        pickerView.sourceType = .photoLibrary
         
     | 
| 
      
 149 
     | 
    
         
            +
                        pickerView.delegate = self
         
     | 
| 
      
 150 
     | 
    
         
            +
                        self.present(pickerView, animated: true)
         
     | 
| 
      
 151 
     | 
    
         
            +
                    }
         
     | 
| 
      
 152 
     | 
    
         
            +
                }
         
     | 
| 
      
 153 
     | 
    
         
            +
                
         
     | 
| 
      
 154 
     | 
    
         
            +
                // 写真を選んだ後の処理
         
     | 
| 
      
 155 
     | 
    
         
            +
                func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
         
     | 
| 
      
 156 
     | 
    
         
            +
                    // 選択した写真を取得
         
     | 
| 
      
 157 
     | 
    
         
            +
                    let image = info[UIImagePickerControllerOriginalImage] as! UIImage
         
     | 
| 
      
 158 
     | 
    
         
            +
                    // ビューに表示
         
     | 
| 
      
 159 
     | 
    
         
            +
                    self.imageView.image = image
         
     | 
| 
      
 160 
     | 
    
         
            +
                    // ビューを閉じる
         
     | 
| 
      
 161 
     | 
    
         
            +
                    self.dismiss(animated: true)
         
     | 
| 
      
 162 
     | 
    
         
            +
                }
         
     | 
| 
      
 163 
     | 
    
         
            +
                
         
     | 
| 
      
 164 
     | 
    
         
            +
                
         
     | 
| 
      
 165 
     | 
    
         
            +
                @IBAction func add(_ sender: Any) {
         
     | 
| 
      
 166 
     | 
    
         
            +
                    
         
     | 
| 
      
 167 
     | 
    
         
            +
                    sArray.append(textField.text!)
         
     | 
| 
      
 168 
     | 
    
         
            +
                    //配列をアプリに保存する
         
     | 
| 
      
 169 
     | 
    
         
            +
                    UserDefaults.standard.set(sArray, forKey: "sArray")
         
     | 
| 
      
 170 
     | 
    
         
            +
                    
         
     | 
| 
      
 171 
     | 
    
         
            +
                    
         
     | 
| 
      
 172 
     | 
    
         
            +
                    
         
     | 
| 
      
 173 
     | 
    
         
            +
                    if UserDefaults.standard.object(forKey: "douga") != nil{
         
     | 
| 
      
 174 
     | 
    
         
            +
                       array = UserDefaults.standard.object(forKey: "douga") as! [UIImage]
         
     | 
| 
      
 175 
     | 
    
         
            +
                        newArray = UserDefaults.standard.object(forKey: "douga") as! [Data]
         
     | 
| 
      
 176 
     | 
    
         
            +
                    }
         
     | 
| 
      
 177 
     | 
    
         
            +
                    
         
     | 
| 
      
 178 
     | 
    
         
            +
                    //        array.append(imageView.image!)
         
     | 
| 
      
 179 
     | 
    
         
            +
                    guard let image = imageView.image else {
         
     | 
| 
      
 180 
     | 
    
         
            +
                        return
         
     | 
| 
      
 181 
     | 
    
         
            +
                    }
         
     | 
| 
      
 182 
     | 
    
         
            +
                    let data = UIImagePNGRepresentation(image)
         
     | 
| 
      
 183 
     | 
    
         
            +
                    if let dt = data {
         
     | 
| 
      
 184 
     | 
    
         
            +
                        newArray.append(dt)
         
     | 
| 
      
 185 
     | 
    
         
            +
                        UserDefaults.standard.set(newArray, forKey: "douga")
         
     | 
| 
      
 186 
     | 
    
         
            +
                        self.navigationController?.popViewController(animated: true)
         
     | 
| 
      
 187 
     | 
    
         
            +
                    }
         
     | 
| 
      
 188 
     | 
    
         
            +
                }
         
     | 
| 
      
 189 
     | 
    
         
            +
                
         
     | 
| 
      
 190 
     | 
    
         
            +
                
         
     | 
| 
      
 191 
     | 
    
         
            +
                /*
         
     | 
| 
      
 192 
     | 
    
         
            +
                // MARK: - Navigation
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
                // In a storyboard-based application, you will often want to do a little preparation before navigation
         
     | 
| 
      
 195 
     | 
    
         
            +
                override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
         
     | 
| 
      
 196 
     | 
    
         
            +
                    // Get the new view controller using segue.destinationViewController.
         
     | 
| 
      
 197 
     | 
    
         
            +
                    // Pass the selected object to the new view controller.
         
     | 
| 
      
 198 
     | 
    
         
            +
                }
         
     | 
| 
      
 199 
     | 
    
         
            +
                */
         
     | 
| 
      
 200 
     | 
    
         
            +
            }
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
      
 202 
     | 
    
         
            +
            ```
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
       34 
204 
     | 
    
         
             
            ###補足情報(言語/FW/ツール等のバージョンなど)
         
     | 
| 
       35 
205 
     | 
    
         
             
            Xcode Version 9.2 (9C40b)
         
     | 
4
コードを一箇所修正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -23,7 +23,7 @@ 
     | 
|
| 
       23 
23 
     | 
    
         
             
                    imageView.image = img
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                    let textView = cell.viewWithTag(2) as! UITextView
         
     | 
| 
       26 
     | 
    
         
            -
                    textView.text = String(describing:  
     | 
| 
      
 26 
     | 
    
         
            +
                    textView.text = String(describing: rResultArray[indexPath.row])
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                    return cell
         
     | 
| 
       29 
29 
     | 
    
         | 
3
タイトル等を修正しました。
    
        title	
    CHANGED
    
    | 
         @@ -1,1 +1,1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            アプリ内に保存した配列を取り出せない
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -1,20 +1,35 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ###前提・実現したいこと
         
     | 
| 
       2 
     | 
    
         
            -
            テーブルビューに 
     | 
| 
      
 2 
     | 
    
         
            +
            テーブルビューにイメージとテキストを表示したい。
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            修正が必要な箇所を自分で探し出せるようになりたい。
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            ###発生している問題・エラーメッセージ
         
     | 
| 
       6 
6 
     | 
    
         
             
            ```
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            Thread 1: signal SIGABRT
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            ```
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            ###試したこと
         
     | 
| 
       13 
     | 
    
         
            -
            Text Fieldを置いても同じようなエラーが出ました。
         
     | 
| 
       14 
     | 
    
         
            -
            <参考エラー>
         
     | 
| 
       15 
     | 
    
         
            -
            The sTextView outlet from the ViewController to the UITextField is invalid. Outlets cannot be connected to repeating content.
         
     | 
| 
       16 
12 
     | 
    
         | 
| 
      
 13 
     | 
    
         
            +
            ###該当のソースコード
         
     | 
| 
      
 14 
     | 
    
         
            +
            ```ここに言語を入力
         
     | 
| 
      
 15 
     | 
    
         
            +
                   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
      
 17 
     | 
    
         
            +
                    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for:indexPath)
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
      
 19 
     | 
    
         
            +
                   cell.imageView?.image = resultArray[indexPath.row]
         
     | 
| 
      
 20 
     | 
    
         
            +
                    
         
     | 
| 
      
 21 
     | 
    
         
            +
                    let img = UIImage(named: resultArray[indexPath.row] as! String)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    let imageView = cell.viewWithTag(1) as! UIImageView
         
     | 
| 
      
 23 
     | 
    
         
            +
                    imageView.image = img
         
     | 
| 
      
 24 
     | 
    
         
            +
                    
         
     | 
| 
      
 25 
     | 
    
         
            +
                    let textView = cell.viewWithTag(2) as! UITextView
         
     | 
| 
      
 26 
     | 
    
         
            +
                    textView.text = String(describing: resultArray[indexPath.row])
         
     | 
| 
      
 27 
     | 
    
         
            +
                    
         
     | 
| 
      
 28 
     | 
    
         
            +
                    return cell
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            ```
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       19 
34 
     | 
    
         
             
            ###補足情報(言語/FW/ツール等のバージョンなど)
         
     | 
| 
       20 
35 
     | 
    
         
             
            Xcode Version 9.2 (9C40b)
         
     | 
2
タグの修正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         
            File without changes
         
     | 
1
タグ変更
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         
            File without changes
         
     |