Created
July 22, 2020 14:02
-
-
Save halilyuce/eaff46c93d5673b2b5fabc2413b3cd0f to your computer and use it in GitHub Desktop.
SwiftUI Checkbox
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 Platform: Codable { | |
var id: Int | |
var name: String? | |
var logo: String? | |
var color: String? | |
var created_at: String? | |
var updated_at: String? | |
} | |
struct SettingsView: View { | |
@State var platforms = [Platform]() | |
@State var selectedPlatforms = [Int]() | |
var body: some View { | |
List{ | |
ForEach(self.platforms, id: \.id){ platform in | |
HStack { | |
if self.selectedPlatforms.contains(platform.id) { | |
Image(systemName: "checkmark.square.fill") | |
}else{ | |
Image(systemName: "square") | |
} | |
Text(platform.name!).padding(.leading, 5) | |
}.padding(.vertical, 5) | |
.padding(.horizontal) | |
.listRowInsets(EdgeInsets()) | |
.onTapGesture { | |
if self.selectedPlatforms.contains(platform.id) { | |
self.selectedPlatforms.removeAll(where: { $0 == platform.id }) | |
} | |
else { | |
self.selectedPlatforms.append(platform.id) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment