Created
February 22, 2019 03:25
-
-
Save Bilguun132/17304f7889b319902e748be81f5527ae to your computer and use it in GitHub Desktop.
TableView-Tutorial-User.swift with manager
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 | |
public struct User { | |
let name: String | |
let gender: String | |
let email: String | |
} | |
public class UserManager { | |
//set array of users (in reality this is usually from a network call | |
public var users: [User] = [User(name: "Albert", gender: "Male", email: "albert@gmail.com"), User(name: "Bob", gender: "Male", email: "bob@gmail.com"), User(name: "Celine", gender: "Female", email: "celine@gmail.com"), User(name: "Derrick", gender: "Male", email: "derrick@gmail.com"), User(name: "Aldwin", gender: "Male", email: "aldwin@gmail.com")] | |
//return total count | |
public var userCount: Int { | |
return users.count | |
} | |
//get user | |
public func getUser(at index:Int) -> User { | |
return users[index] | |
} | |
public func deleteUser(at index: Int) { | |
users.remove(at: index) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment