teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

a

2020/09/09 09:42

投稿

kazuki_user
kazuki_user

スコア147

title CHANGED
File without changes
body CHANGED
@@ -12,6 +12,8 @@
12
12
  ```
13
13
 
14
14
  上記メッセージが出たのですが、**`RepositoryApi`のどこが不適切なのでしょうか?**
15
+ `self`を消すとエラーになるのですが..
16
+
15
17
  以下にコードを記載します。
16
18
 
17
19
  ## コード

5

2020/09/09 09:42

投稿

kazuki_user
kazuki_user

スコア147

title CHANGED
@@ -1,1 +1,1 @@
1
- EXC_BAD_ACCESS出る。【】
1
+ Exception BreakPointでエラーを特定した、不適切な箇所が分からないEXC_BAD_ACCESS
body CHANGED
@@ -1,4 +1,4 @@
1
- ## タイトル
1
+ ## Exception BreakPointでエラーを特定したが、不適切な箇所が分からない
2
2
 
3
3
  RUNすると画面が真っ白で、画面をタッチすると
4
4
  `EXC_BAD_ACCESS (code=2, address=0x7ffee12bafc8)`エラーが出てしまいます。

4

a

2020/09/09 09:41

投稿

kazuki_user
kazuki_user

スコア147

title CHANGED
@@ -1,1 +1,1 @@
1
- EXC_BAD_ACCESSが出る。【Add Exception BreakPointが無い..
1
+ EXC_BAD_ACCESSが出る。【】
body CHANGED
@@ -4,98 +4,51 @@
4
4
  `EXC_BAD_ACCESS (code=2, address=0x7ffee12bafc8)`エラーが出てしまいます。
5
5
 
6
6
 
7
- [**Xcodeでデバッグ実行中にクラッシュした時に捗るブレークポイント設定**](https://qiita.com/mono0926/items/bf70c7ef15db046ee163)を参考に
7
+ [**こちら**](https://www.hfoasi8fje3.work/entry/2018/08/22/004804)を参考に
8
- **Add Exception BreakPoint**てみたのですがそれもありません。
8
+ `Exception BreakPoint`利用し、
9
9
 
10
- 自分のXcode↓
10
+ ```
11
- ![イメージ説明](39dd5dee9e079bdccbe17a5e9f5bd9a7.png)
11
+ self CodeCheck_Test_Yumemi.RepositoryApi 0x00007fd96f0220e0
12
+ ```
12
13
 
14
+ 上記メッセージが出たのですが、**`RepositoryApi`のどこが不適切なのでしょうか?**
13
- これが無い
15
+ 以下にコードを記載します。
14
16
 
15
- ![![イメージ説明](8beb948fecd4744adbc9ee2dab561e2c.png)](b030681d475777c429d62b1c91b80aa3.png)
16
-
17
17
  ## コード
18
18
 
19
- ```SearchRootVC
19
+ ```RepositoryApi
20
20
  import UIKit
21
21
 
22
- class SearchRootVC: UITableViewController, UISearchBarDelegate {
22
+ class RepositoryApi: SearchRootVC {
23
+
23
-
24
+ func getRandomRepoUrlSession() {
25
+
24
- @IBOutlet weak var searchBar: UISearchBar!
26
+ let word = searchBar.text!
25
-
26
- var word: String!
27
- var url: String!
27
+ var url: String!
28
- var RepoToPass: Int!
28
+
29
-
30
- var task: URLSessionTask?
31
- var repo: [[String: Any]]=[]
32
-
33
- override func viewDidLoad() {
29
+ if word.count > 0 {
34
- super.viewDidLoad()
35
-
36
- repositoryApi.getRandomRepoUrlSession()
30
+ url = URL_BASE + "(word)"
37
-
38
- // UISearchBarのdelegateプロパティに、self(=SearchRootVC)を代入。
31
+ let task = URLSession.shared.dataTask(with: URL(string: url)!) { (data, res, err) in
32
+
39
- searchBar.delegate = self
33
+ guard err == nil else {
40
- self.tableView.register(RepositoryCell.self, forCellReuseIdentifier: Identifiers.RepositoryCell)
34
+ debugPrint(err.debugDescription)
35
+ return
41
- }
36
+ }
42
-
43
- // 以下3つ、元から用意されているsearchBar関数名なので、変更NG。
37
+
44
- func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
38
+ if let obj = try! JSONSerialization.jsonObject(with: data!) as? [String: Any] {
39
+ if let items = obj["items"] as? [[String: Any]] {
40
+ self.repo = items
41
+ DispatchQueue.main.async {
45
- searchBar.text = ""
42
+ self.tableView.reloadData()
46
- return true
47
- }
43
+ }
48
-
49
- func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
50
- task?.cancel()
51
- }
44
+ }
52
-
53
- func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
54
- // getRandomRepoUrlSession()を実行する処理をかきたい。
55
- }
45
+ }
56
-
57
-
58
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
59
- if segue.identifier == Segues.ToProfileDetail {
60
- if let detailVC = segue.destination as? ProfileDetailVC {
61
- detailVC.selectedUser = self
62
46
  }
47
+ // これ呼ばなきゃリストが更新されません
48
+ task.resume()
63
49
  }
64
- }
65
- }
66
50
 
67
- // extension
68
-
69
- // UITableViewDelegate や UITableViewDataSource への適合は不要。
70
- // 必要なプロトコルは、UITableViewController にて既に採用されているため。
71
-
72
- extension SearchRootVC {
73
-
74
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
75
- return repo.count
76
51
  }
77
-
78
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
79
-
80
- // dequeueReusableCellで、セルを再利用。
81
- // nilを返さない為、オプショナルバインディングは不要。
82
-
83
- let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: Identifiers.RepositoryCell, for: indexPath) as! RepositoryCell
84
- let rp = repo[indexPath.row]
85
- // Any から Stringへ、より具体的な型にダウンキャスト。
86
- // ダウンキャストに失敗し、nilとなると「""」。
87
- // ??は、Nil結合演算子。
88
-
89
- cell.textLabel?.text = rp[ApiKey.FullName] as? String ?? ""
90
- cell.detailTextLabel?.text = rp[ApiKey.Language] as? String ?? ""
91
- cell.tag = indexPath.row
92
- return cell
93
- }
94
-
95
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
96
- RepoToPass = indexPath.row
97
- performSegue(withIdentifier: Segues.ToProfileDetail, sender: self)
98
- }
99
52
  }
100
53
 
101
54
  ```

3

a

2020/09/09 09:40

投稿

kazuki_user
kazuki_user

スコア147

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,13 @@
7
7
  [**Xcodeでデバッグ実行中にクラッシュした時に捗るブレークポイント設定**](https://qiita.com/mono0926/items/bf70c7ef15db046ee163)を参考に、
8
8
  **Add Exception BreakPoint**を探してみたのですが、それもありません。
9
9
 
10
+ 自分のXcode↓
11
+ ![イメージ説明](39dd5dee9e079bdccbe17a5e9f5bd9a7.png)
12
+
13
+ これが無い
14
+
15
+ ![![イメージ説明](8beb948fecd4744adbc9ee2dab561e2c.png)](b030681d475777c429d62b1c91b80aa3.png)
16
+
10
17
  ## コード
11
18
 
12
19
  ```SearchRootVC

2

2020/09/09 09:33

投稿

kazuki_user
kazuki_user

スコア147

title CHANGED
@@ -1,1 +1,1 @@
1
- 画面が真っ白で、EXC_BAD_ACCESS (code=2, address=0x7ffee12bafc8)が出る。
1
+ EXC_BAD_ACCESSが出る。【Add Exception BreakPointが無い..】
body CHANGED
@@ -4,11 +4,9 @@
4
4
  `EXC_BAD_ACCESS (code=2, address=0x7ffee12bafc8)`エラーが出てしまいます。
5
5
 
6
6
 
7
+ [**Xcodeでデバッグ実行中にクラッシュした時に捗るブレークポイント設定**](https://qiita.com/mono0926/items/bf70c7ef15db046ee163)を参考に、
7
- **プログラムのOSキャッチ例外(不正アクセス)や、無限ループ**が原因とあったのですが、
8
+ **Add Exception BreakPoint**を探してみたのですが、それもありません。
8
- 以下のコードのどこが原因なのでしょうか?
9
9
 
10
- 大雑把な質問になってしまい恐縮ですが、ご返信頂けますと嬉しいです。
11
-
12
10
  ## コード
13
11
 
14
12
  ```SearchRootVC

1

a

2020/09/09 09:31

投稿

kazuki_user
kazuki_user

スコア147

title CHANGED
File without changes
body CHANGED
@@ -24,9 +24,7 @@
24
24
 
25
25
  var task: URLSessionTask?
26
26
  var repo: [[String: Any]]=[]
27
-
28
- var repositoryApi = RepositoryApi()
27
+
29
-
30
28
  override func viewDidLoad() {
31
29
  super.viewDidLoad()
32
30