This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct Response: Codable { | |
| var results: [Result] | |
| } | |
| struct Result: Codable { | |
| var trackId: Int | |
| var trackName: String | |
| var collectionName: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // userColorRepositoryを使うクラス。 | |
| class ColorChange(private val repo: UserColorRepositoryInterface) { | |
| //... | |
| val userColor = repo.getUserColor(username = currentUsername) | |
| if (usercolor == Color.White) { | |
| repo.setUserColor(username = currentUsername, color = Color.Red) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val userColor = UserColorSingleton.getuserColor(username = currentUserName) | |
| if (userColor == Color.White) { | |
| UserColorSingleton.setUserColor(username = currentUserName, color = Color.Red) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object UserColorSingleton { | |
| private val userColorMap: MutableMap<String, Int> = mutableMapOf() | |
| fun setUserColor(username: String, color: Int) { | |
| userColorMap[username] = color | |
| } | |
| fun getUserColor(username: String): Int { | |
| return userColorMap.getOrDefault(username, Color.White) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private var _table: Map<String, Int>? = null | |
| public val table: Map<String, Int> | |
| get() { | |
| if (_table == null) { | |
| _table = HashMap() | |
| } | |
| return _table ?: throw AssertionError("他のスレッドによってnullにセットされました。") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val isEmpty: Boolean | |
| get() = this.size == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var doubledNumber: Int = 0 | |
| get() = doubledNumber | |
| set(value) { | |
| this.doubledNumber = value * 2 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var doubledNumber: Int = 0 | |
| get() = field | |
| set(value) { | |
| field = value * 2 | |
| } |