質問編集履歴
2
説明文の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,18 +1,94 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
Swiftでタブ機能付きTodoアプリを作成しており、現在ConfigurationIntent(?)でウィジェットの設定を作っています。
|
2
|
+
Swiftでタブ機能付きTodoアプリを作成しており、現在widgetkitのConfigurationIntent(?)でウィジェットの設定を作っています。
|
3
|
-
ウィジェットの設定でタブを選択する事でそのタブのtodoを表示したいです。
|
3
|
+
ウィジェットの設定でタブを選択する事でそのタブ名と選択したタブのtodoを表示したいです。
|
4
4
|
|
5
5
|
### 発生している問題
|
6
6
|
|
7
|
+
こちらのサイトを参考に動的なウィジェットの作成をしています
|
8
|
+
[https://ichi.pro/widgetkit-kodona-kaihatsu-pa-to-2-183024227974601](https://ichi.pro/widgetkit-kodona-kaihatsu-pa-to-2-183024227974601)
|
9
|
+
```
|
10
|
+
Thread 1: "-[__NSCFString index]: unrecognized selector sent to instance 0x6000037239e0"
|
11
|
+
```
|
12
|
+
このようなエラーが出てきてウィジェットのビルドができないです。
|
7
13
|
|
8
|
-
### 試した事
|
9
|
-
|
10
14
|
### 該当のソースコード
|
11
15
|
|
16
|
+
```Swift
|
17
|
+
class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessagesIntentHandling, INSetMessageAttributeIntentHandling, ConfigurationIntentHandling {
|
18
|
+
func provideTabNameOptionsCollection(for intent: ConfigurationIntent, with completion: @escaping (INObjectCollection<TabName>?, Error?) -> Void) {
|
19
|
+
var tabIndex = 0
|
20
|
+
var tabNames = [String]()
|
21
|
+
let userDefaults = UserDefaults(suiteName: "group.my_todo_ios")
|
22
|
+
if let storedTabName = userDefaults?.array(forKey: "tabName") as? [String] {
|
23
|
+
tabNames.append(contentsOf: storedTabName)
|
24
|
+
}
|
25
|
+
let allTabNames = tabNames.map {(tabName) -> TabName in
|
26
|
+
let allTabName = TabName(identifier: "(tabIndex)", display: tabName)
|
27
|
+
allTabName.index = tabIndex as NSNumber?
|
28
|
+
tabIndex += 1
|
29
|
+
return allTabName
|
30
|
+
}
|
31
|
+
let collection = INObjectCollection(items: allTabNames)
|
32
|
+
completion(collection, nil)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
```
|
36
|
+
```Swift
|
37
|
+
struct Provider: IntentTimelineProvider {
|
12
38
|
|
39
|
+
typealias Intent = ConfigurationIntent
|
40
|
+
|
41
|
+
@available(iOSApplicationExtension 13.0, *)
|
42
|
+
func placeholder(in context: Context) -> SimpleEntry {
|
43
|
+
SimpleEntry(date: Date(), todoList: [], color: Color(.black), tabName:"")
|
44
|
+
}
|
45
|
+
|
46
|
+
@available(iOSApplicationExtension 13.0, *)
|
47
|
+
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
|
48
|
+
let entry = SimpleEntry(date: Date(), todoList: [], color: Color(.black), tabName:"")
|
49
|
+
completion(entry)
|
50
|
+
}
|
51
|
+
|
52
|
+
@available(iOSApplicationExtension 14.0, *)
|
53
|
+
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
|
54
|
+
var entries: [SimpleEntry] = []
|
55
|
+
var todoList = [String]()
|
56
|
+
var color = UIColor()
|
57
|
+
let userDefaults = UserDefaults(suiteName: "group.my_todo_ios")
|
58
|
+
if userDefaults?.object(forKey: "SaveUIColor") == nil {
|
59
|
+
let SaveColor = try? NSKeyedArchiver.archivedData(withRootObject: UIColor.black, requiringSecureCoding: true)
|
60
|
+
userDefaults?.synchronize()
|
61
|
+
userDefaults?.set(SaveColor, forKey: "SaveUIColor")
|
62
|
+
}
|
63
|
+
if let SetColor = userDefaults?.object(forKey: "SaveUIColor") as? Data{
|
64
|
+
if let reloadColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(SetColor) as? UIColor{
|
65
|
+
color = reloadColor
|
66
|
+
}
|
67
|
+
}
|
68
|
+
if let storedTodoList = userDefaults?.array(forKey: "todoList(String(describing: configuration.tabName?.index))") as? [String] {
|
69
|
+
todoList.append(contentsOf: storedTodoList)
|
70
|
+
}
|
71
|
+
let entry = SimpleEntry( date: Date(), todoList: todoList, color: Color(color), tabName: configuration.tabName?.displayString ?? "")
|
72
|
+
entries.append(entry)
|
73
|
+
let timeline = Timeline(entries: entries, policy: .atEnd)
|
74
|
+
completion(timeline)
|
75
|
+
}
|
76
|
+
}
|
13
77
|
|
78
|
+
```
|
79
|
+
|
14
80
|
コードが足りなければ追記しますのでよろしくお願いいたします。
|
15
81
|
|
82
|
+
### 試した事
|
83
|
+
|
84
|
+
```
|
85
|
+
configuration.tabName?.index
|
86
|
+
configuration.tabName?.displayString ?? ""
|
87
|
+
```
|
88
|
+
この2つを試しに静的に指定してあげると表示されます。
|
89
|
+
なのでここの呼び方、或いはconfigurationが悪いのだと思います。
|
90
|
+
どこが間違っているでしょうか?
|
91
|
+
|
16
92
|
### 補足情報(FW/ツールのバージョンなど)
|
17
93
|
|
18
94
|
Xcode 12.5.1
|
1
説明文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,56 +3,14 @@
|
|
3
3
|
ウィジェットの設定でタブを選択する事でそのタブのtodoを表示したいです。
|
4
4
|
|
5
5
|
### 発生している問題
|
6
|
-
タブの選択自体はできたのですが選択したタブのtodoを表示できません。
|
7
|
-
userDefaults?.array(forKey: "todoList(index)")のindexにユーザーが選択したタブのindexを代入できれば良いと思うのですが、何か方法はありますでしょうか?
|
8
|
-
やろうとしている方法自体がダメならばどのようなアプローチがあるか教えていただきたいです。
|
9
6
|
|
7
|
+
|
10
8
|
### 試した事
|
11
9
|
|
12
10
|
### 該当のソースコード
|
13
11
|
|
14
|
-
```Swift
|
15
|
-
class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessagesIntentHandling, INSetMessageAttributeIntentHandling, ConfigurationIntentHandling {
|
16
|
-
|
17
|
-
func provideTabNameOptionsCollection(for intent: ConfigurationIntent, searchTerm: String?, with completion: @escaping (INObjectCollection<NSString>?, Error?) -> Void) {
|
18
|
-
var tabName = [NSString]()
|
19
|
-
let userDefaults = UserDefaults(suiteName: "group.my_todo_ios")
|
20
|
-
if let storedTabName = userDefaults?.array(forKey: "tabName") as? [NSString] {
|
21
|
-
tabName.append(contentsOf: storedTabName)
|
22
|
-
}
|
23
|
-
let allNameIdentifiers = INObjectCollection(items: tabName)
|
24
|
-
print(allNameIdentifiers)
|
25
|
-
completion(allNameIdentifiers, nil)
|
26
|
-
}
|
27
|
-
}
|
28
|
-
```
|
29
|
-
```Swift
|
30
|
-
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
|
31
|
-
var entries: [SimpleEntry] = []
|
32
|
-
var todoList = [String]()
|
33
|
-
var color = UIColor()
|
34
|
-
let index = 0
|
35
|
-
let userDefaults = UserDefaults(suiteName: "group.my_todo_ios")
|
36
|
-
if userDefaults?.object(forKey: "SaveUIColor") == nil {
|
37
|
-
let SaveColor = try? NSKeyedArchiver.archivedData(withRootObject: UIColor.black, requiringSecureCoding: true)
|
38
|
-
userDefaults?.synchronize()
|
39
|
-
userDefaults?.set(SaveColor, forKey: "SaveUIColor")
|
40
|
-
}
|
41
|
-
if let SetColor = userDefaults?.object(forKey: "SaveUIColor") as? Data{
|
42
|
-
if let reloadColor = try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(SetColor) as? UIColor{
|
43
|
-
color = reloadColor
|
44
|
-
}
|
45
|
-
}
|
46
|
-
if let storedTodoList = userDefaults?.array(forKey: "todoList(index)") as? [String] {
|
47
|
-
todoList.append(contentsOf: storedTodoList)
|
48
|
-
}
|
49
|
-
let entry = SimpleEntry( date: Date(), todoList: todoList, color: Color(color), tabName: configuration.tabName ?? "")
|
50
|
-
entries.append(entry)
|
51
|
-
let timeline = Timeline(entries: entries, policy: .atEnd)
|
52
|
-
completion(timeline)
|
53
|
-
}
|
54
|
-
```
|
55
12
|
|
13
|
+
|
56
14
|
コードが足りなければ追記しますのでよろしくお願いいたします。
|
57
15
|
|
58
16
|
### 補足情報(FW/ツールのバージョンなど)
|