回答編集履歴

5

修正

2016/12/04 12:04

投稿

fromageblanc
fromageblanc

スコア2724

test CHANGED
@@ -84,11 +84,11 @@
84
84
 
85
85
  let entries:NSArray = [
86
86
 
87
- ["id":1,"title":"title 1","published":"2016-12-02 10:00:00"],
87
+ ["id":1,"title":"title 1","publishedDate":"2016-12-02 10:00:00"],
88
88
 
89
- ["id":2,"title":"title 2","published":"2016-12-01 12:00:00"],
89
+ ["id":2,"title":"title 2","publishedDate":"2016-12-01 12:00:00"],
90
90
 
91
- ["id":3,"title":"title 3","published":"2016-12-02 11:00:00"]
91
+ ["id":3,"title":"title 3","publishedDate":"2016-12-02 11:00:00"]
92
92
 
93
93
  ]
94
94
 
@@ -106,7 +106,7 @@
106
106
 
107
107
  // publishedでソート
108
108
 
109
- let sd = NSSortDescriptor(key:"published",ascending:false) // 降順
109
+ let sd = NSSortDescriptor(key:"publishedDate",ascending:false) // 降順
110
110
 
111
111
  let sorted = wk.sortedArray(using: [sd]) as NSArray
112
112
 
@@ -126,7 +126,7 @@
126
126
 
127
127
  id = 3;
128
128
 
129
- published = "2016-12-02 11:00:00";
129
+ publishedDate = "2016-12-02 11:00:00";
130
130
 
131
131
  title = "title 3";
132
132
 
@@ -136,7 +136,7 @@
136
136
 
137
137
  id = 1;
138
138
 
139
- published = "2016-12-02 10:00:00";
139
+ publishedDate = "2016-12-02 10:00:00";
140
140
 
141
141
  title = "title 1";
142
142
 
@@ -146,7 +146,7 @@
146
146
 
147
147
  id = 2;
148
148
 
149
- published = "2016-12-01 12:00:00";
149
+ publishedDate = "2016-12-01 12:00:00";
150
150
 
151
151
  title = "title 2";
152
152
 

4

しゅうせい

2016/12/04 12:04

投稿

fromageblanc
fromageblanc

スコア2724

test CHANGED
@@ -82,7 +82,7 @@
82
82
 
83
83
  // test data
84
84
 
85
- let feeds:NSArray = [
85
+ let entries:NSArray = [
86
86
 
87
87
  ["id":1,"title":"title 1","published":"2016-12-02 10:00:00"],
88
88
 
@@ -100,7 +100,7 @@
100
100
 
101
101
 
102
102
 
103
- wk = feeds.mutableCopy() as! NSMutableArray
103
+ wk = entries.mutableCopy() as! NSMutableArray
104
104
 
105
105
 
106
106
 

3

追加

2016/12/04 12:01

投稿

fromageblanc
fromageblanc

スコア2724

test CHANGED
@@ -54,7 +54,11 @@
54
54
 
55
55
  let sorted = wk.sortedArray(using: [sd]) as NSArray
56
56
 
57
+
58
+
57
- self.NewDataArray.add(sorted)
59
+ // self.NewDataArray.add(sorted) さらに改変
60
+
61
+ self.NewDataArray = sorted.mutableCopy() as! NSMutableArray
58
62
 
59
63
 
60
64
 
@@ -67,3 +71,91 @@
67
71
  }
68
72
 
69
73
  ```
74
+
75
+
76
+
77
+ ミニマムテストコード
78
+
79
+ ```swift
80
+
81
+ // sfift 3.0
82
+
83
+ // test data
84
+
85
+ let feeds:NSArray = [
86
+
87
+ ["id":1,"title":"title 1","published":"2016-12-02 10:00:00"],
88
+
89
+ ["id":2,"title":"title 2","published":"2016-12-01 12:00:00"],
90
+
91
+ ["id":3,"title":"title 3","published":"2016-12-02 11:00:00"]
92
+
93
+ ]
94
+
95
+
96
+
97
+ var wk = NSMutableArray()
98
+
99
+ var NewDataArray = NSMutableArray()
100
+
101
+
102
+
103
+ wk = feeds.mutableCopy() as! NSMutableArray
104
+
105
+
106
+
107
+ // publishedでソート
108
+
109
+ let sd = NSSortDescriptor(key:"published",ascending:false) // 降順
110
+
111
+ let sorted = wk.sortedArray(using: [sd]) as NSArray
112
+
113
+ NewDataArray = sorted.mutableCopy() as! NSMutableArray
114
+
115
+
116
+
117
+ print(NewDataArray)
118
+
119
+
120
+
121
+ /*
122
+
123
+ (
124
+
125
+ {
126
+
127
+ id = 3;
128
+
129
+ published = "2016-12-02 11:00:00";
130
+
131
+ title = "title 3";
132
+
133
+ },
134
+
135
+ {
136
+
137
+ id = 1;
138
+
139
+ published = "2016-12-02 10:00:00";
140
+
141
+ title = "title 1";
142
+
143
+ },
144
+
145
+ {
146
+
147
+ id = 2;
148
+
149
+ published = "2016-12-01 12:00:00";
150
+
151
+ title = "title 2";
152
+
153
+ }
154
+
155
+ )
156
+
157
+ */
158
+
159
+
160
+
161
+ ```

2

追加

2016/12/04 11:55

投稿

fromageblanc
fromageblanc

スコア2724

test CHANGED
@@ -33,3 +33,37 @@
33
33
 
34
34
 
35
35
  ```
36
+
37
+
38
+
39
+ 改変
40
+
41
+ ```swift
42
+
43
+ if let entries = feed["entries"] as? NSArray {
44
+
45
+
46
+
47
+ var wk:NSMutableArray = entries.mutableCopy() as! NSMutableArray
48
+
49
+
50
+
51
+ // publishedDateでソート
52
+
53
+ let sd = NSSortDescriptor(key:"publishedDate",ascending:false) // 降順
54
+
55
+ let sorted = wk.sortedArray(using: [sd]) as NSArray
56
+
57
+ self.NewDataArray.add(sorted)
58
+
59
+
60
+
61
+ DispatchQueue.main.async {
62
+
63
+ self.myTableView.reloadData()
64
+
65
+ }
66
+
67
+ }
68
+
69
+ ```

1

修正

2016/12/04 00:20

投稿

fromageblanc
fromageblanc

スコア2724

test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  // publishedDateでソート
16
16
 
17
- let sd = NSSortDescriptor(key:"published",ascending:false) // 降順
17
+ let sd = NSSortDescriptor(key:"publishedDate",ascending:false) // 降順
18
18
 
19
19
  let sorted = wk.sortedArray(using: [sd]) as NSArray
20
20