Created
June 9, 2022 15:47
-
-
Save pabloruan0710/8e8acbb3570d32ac27384c0d60d6e621 to your computer and use it in GitHub Desktop.
CodeReview Interview
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 Foundation | |
public enum DogGender: Int { | |
case male | |
case female | |
} | |
public class Dog { | |
public var name: String | |
public var gender: DogGender | |
} | |
public final class ListDogs: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
public var dogs: [Dogs] = [] | |
private var dogsMale: [Dogs] = [] | |
private var dogsFemale: [Dogs] = [] | |
override public func viewDidLoad() { | |
super.viewDidLoad() | |
getListDogsAPI() | |
} | |
func getListDogsAPI() { | |
// Background service called | |
service.getDogs { dogs in | |
self.dogs = dogs | |
self.tableView.reloadData() | |
} | |
self.dogsMale = getDogsFemale() | |
self.dogsFemale = getDogsMale() | |
} | |
func getDogsFemale() -> [Dogs] { | |
var dogsFilter = [] | |
for dog in self.dogs { | |
if dog.gender == .female { | |
dogsFilter.append(dog) | |
} | |
} | |
return dog | |
} | |
func getDogsMale() -> [Dogs] { | |
var dogsFilter = [] | |
for dog in self.dogs { | |
if dog.gender == .male { | |
dogsFilter.append(dog) | |
} | |
} | |
return dog | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment