Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from svartalfheim/work/apply-swift4-to-1.1
Browse files Browse the repository at this point in the history
day1/1.1のSwift4対応
  • Loading branch information
punchdrunker authored Sep 1, 2018
2 parents f623f13 + 6a9f546 commit fc10c80
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Swift/after/day1/1.1/HelloWorld.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ print(helloWorld)
//模範解答2
/*
* [h, ell, o, world]は[String?]型なので
* flatMapで[String]型に変換し、[String]型の
* compactMapで[String]型に変換し、[String]型の
* public func joined(separator: String = default) -> String
* を使って内部のstringを結合する。
* ※ループさせる回数が増える
*/
let helloWorld2: String = [h, ell, o, world].flatMap { $0 }.joined()
let helloWorld2: String = [h, ell, o, world].compactMap { $0 }.joined()
print(helloWorld2)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
14 changes: 8 additions & 6 deletions Swift/after/day1/1.1/Users.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class User: CustomStringConvertible {
* print時に実装したdescriptionが出力されます。
*/
var description: String {
return "\nUser:\n"
+ " name = \(name)\n"
+ " era = \(era)\n"
+ " age = \(age)\n"
+ " visits = \(visits)\n"
return """
\nUser:
\tname = \(name)
\tera = \(era)
\tage = \(age)
\tvisits = \(String(describing: visits))\n
"""
}

init?(dict: [String : Any?]) {
Expand Down Expand Up @@ -74,5 +76,5 @@ let dict: [String : [[String : Any?]]] = [
]

//usersのarrayを取得し、flatMapを使ってUser型に変換
let users: [User] = (dict["users"] ?? []).flatMap { User(dict: $0) }
let users: [User] = (dict["users"] ?? []).compactMap { User(dict: $0) }
print(users)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
20 changes: 17 additions & 3 deletions Swift/pages/day1/1-1_swift-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
|2016年03月|Swift 2.2|
|2016年12月|Swiftオープンソース化 [swift.org](https://swift.org/)|
|2016年09月|Swift 2.3、Swift 3.0|
|2017年09月|Swift 4.0|

APIの振る舞いに関して疑問を持ったら、[公式API Reference](https://developer.apple.com/reference)を見ましょう。
またはXcodeのソースコード上で型にカーソルをあわせて`command`を押しながらクリックすると
Expand Down Expand Up @@ -52,7 +53,7 @@ Int.max
123+456 //579
123 + 456 //579
123+ 456 //error: '+' is not a postfix unary operator
123 +456 //error: ambiguous use of operator '+'
123 +456 //error: consecutive statements on a line must be separated by ';'
```

## 文字列
Expand All @@ -69,6 +70,16 @@ print("Hello World!")
print("Hello " + "World!")
```

Swift4からは複数行での文字列定義に対応しました。

```swift
print("""
Hello
World
!!!
""")
```

## `let``var`

Swiftでは`var`で変数を、`let`で定数を宣言できます。
Expand Down Expand Up @@ -422,7 +433,7 @@ struct Person {

## propertyの値を監視

`wiiSet``didSet`を使うことで、propertyの値の変更を監視することができます。
`willSet``didSet`を使うことで、propertyの値の変更を監視することができます。

```swift
class Person {
Expand Down Expand Up @@ -702,7 +713,7 @@ Swift3では、C言語スタイルのfor文と`++`及び`--`が使用できな
for var i = 0; i < 10 ; i++ {
print(i)
}
// 0 1 2 3 4 5 6 7 8 9
// error: C-style for statement has been removed in Swift 3
```

```swift
Expand Down Expand Up @@ -886,6 +897,9 @@ print(dog as! PoliceDog)

## Access Control

swift4からは`private``extension`内からもアクセスできるように変更になりました
> 参考 [Improve Interaction Between private Declarations and Extensions](https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md#detailed-design)
|アクセス修飾子|内容|
|:---|:---|
|open|同じモジュールだけでなく、別のモジュールからもアクセスができ、別のモジュールで継承またはオーバーライドができる|
Expand Down

0 comments on commit fc10c80

Please sign in to comment.