Created
October 21, 2019 19:59
-
-
Save renanzinho/be265b66eb491424e915616c160512c8 to your computer and use it in GitHub Desktop.
This file contains 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 Foundation | |
import SwiftUI | |
import Combine | |
class Person: Identifiable{ | |
var id: Int | |
var name: String | |
init(id: Int, name: String){ | |
self.id = id | |
self.name = name | |
} | |
func mudar(nome: inout String) { | |
nome = "ois" | |
} | |
} | |
class People: ObservableObject{ | |
@Published var people: [Person] | |
init(){ | |
self.people = [ | |
Person(id: 1, name:"Javier"), | |
Person(id: 2, name:"Juan"), | |
Person(id: 3, name:"Pedro"), | |
Person(id: 4, name:"Luis")] | |
} | |
} | |
struct ContentView: View { | |
@ObservedObject var mypeople: People = People() | |
var body: some View { | |
VStack(alignment: .center){ | |
ForEach(mypeople.people){ person in | |
Text("\(person.name)") | |
} | |
Button(action: { | |
self.dale(dole: &self.mypeople.people[0], newName: "diz") | |
}) { | |
Text("Add/Change name") | |
} | |
} | |
} | |
func dale(dole: inout Person, newName: String) { | |
dole.name = newName | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment