回答編集履歴
4
コード修正
test
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
if let range = address.rangeOfString(mstAddress.address) {
|
52
52
|
|
53
|
-
if range.startIndex ==
|
53
|
+
if range.startIndex == address.startIndex {
|
54
54
|
|
55
55
|
if foundAddress == nil || (range.endIndex > foundAddress?.address.endIndex) {
|
56
56
|
|
3
コード修正
test
CHANGED
File without changes
|
2
コード修正
test
CHANGED
File without changes
|
1
説明修正
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
とかいった、番地なしでマンション名のみのパターンもあるかもしれないので、
|
12
12
|
|
13
|
-
番地が始まるまでを完全一致検索するのではなく、
|
13
|
+
番地(数字)が始まるまでを完全一致検索するのではなく、
|
14
14
|
|
15
15
|
前方一致するものの中で、最長一致するものを検索するのが
|
16
16
|
|
@@ -22,52 +22,50 @@
|
|
22
22
|
|
23
23
|
```swift
|
24
24
|
|
25
|
-
|
25
|
+
struct Address {
|
26
26
|
|
27
|
-
|
27
|
+
var address: String
|
28
28
|
|
29
|
-
|
29
|
+
var postCode: String
|
30
30
|
|
31
|
-
|
31
|
+
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
let mstAddressResults:[Address] = [
|
36
|
-
|
37
|
-
Address(address:"埼玉県上尾市上尾下", postCode:"362-0025"),
|
38
|
-
|
39
|
-
Address(address:"埼玉県上尾市上", postCode:"362-0001"),
|
40
|
-
|
41
|
-
]
|
42
32
|
|
43
33
|
|
44
34
|
|
45
|
-
|
35
|
+
let mstAddressResults:[Address] = [
|
46
36
|
|
47
|
-
|
37
|
+
Address(address:"埼玉県上尾市上尾下", postCode:"362-0025"),
|
48
38
|
|
49
|
-
|
39
|
+
Address(address:"埼玉県上尾市上", postCode:"362-0001"),
|
50
40
|
|
51
|
-
|
41
|
+
]
|
52
42
|
|
53
|
-
|
43
|
+
let address = "埼玉県上尾市上尾下9999-9999"
|
54
44
|
|
55
|
-
if range.startIndex == mstAddress.address.startIndex {
|
56
45
|
|
57
|
-
if foundAddress == nil || (range.endIndex > foundAddress?.address.endIndex) {
|
58
46
|
|
59
|
-
|
47
|
+
var foundAddress:Address? = nil
|
60
48
|
|
61
|
-
|
49
|
+
for mstAddress in mstAddressResults {
|
62
50
|
|
51
|
+
if let range = address.rangeOfString(mstAddress.address) {
|
52
|
+
|
53
|
+
if range.startIndex == mstAddress.address.startIndex {
|
54
|
+
|
55
|
+
if foundAddress == nil || (range.endIndex > foundAddress?.address.endIndex) {
|
56
|
+
|
63
|
-
|
57
|
+
foundAddress = mstAddress
|
64
58
|
|
65
59
|
}
|
66
60
|
|
67
61
|
}
|
68
62
|
|
69
|
-
|
63
|
+
}
|
70
64
|
|
65
|
+
}
|
66
|
+
|
67
|
+
print(foundAddress?.postCode)
|
68
|
+
|
71
|
-
|
69
|
+
print(foundAddress?.address)
|
72
70
|
|
73
71
|
```
|