Skip to content

Instantly share code, notes, and snippets.

@Bilguun132
Created February 22, 2019 03:25
Show Gist options
  • Save Bilguun132/17304f7889b319902e748be81f5527ae to your computer and use it in GitHub Desktop.
Save Bilguun132/17304f7889b319902e748be81f5527ae to your computer and use it in GitHub Desktop.
TableView-Tutorial-User.swift with manager
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