Skip to content

Instantly share code, notes, and snippets.

View yaxarat's full-sized avatar

Yashar yaxarat

  • United States
View GitHub Profile
@yaxarat
yaxarat / rimk_fetch.swift
Last active February 7, 2021 17:44
Network request example using swiftUi - iTunes fetch music swiftUi
import SwiftUI
struct Response: Codable {
var results: [Result]
}
struct Result: Codable {
var trackId: Int
var trackName: String
var collectionName: String
// userColorRepositoryを使うクラス。
class ColorChange(private val repo: UserColorRepositoryInterface) {
//...
val userColor = repo.getUserColor(username = currentUsername)
if (usercolor == Color.White) {
repo.setUserColor(username = currentUsername, color = Color.Red)
val userColor = UserColorSingleton.getuserColor(username = currentUserName)
if (userColor == Color.White) {
UserColorSingleton.setUserColor(username = currentUserName, color = Color.Red)
}
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)
private var _table: Map<String, Int>? = null
public val table: Map<String, Int>
get() {
if (_table == null) {
_table = HashMap()
}
return _table ?: throw AssertionError("他のスレッドによってnullにセットされました。")
}
val isEmpty: Boolean
get() = this.size == 0
var doubledNumber: Int = 0
get() = doubledNumber
set(value) {
this.doubledNumber = value * 2
}
}
var doubledNumber: Int = 0
get() = field
set(value) {
field = value * 2
}