Created
June 7, 2020 07:04
-
-
Save TungVuDuc2805/e36456045151bd992567c011b248076c 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
protocol ProfileLoader { | |
func load() -> [ProfileSectionControllerProtocol] | |
} | |
class RemoteProfileLoader: ProfileLoader { | |
func load() -> [ProfileSectionControllerProtocol] { | |
var items = [ProfileSectionControllerProtocol]() | |
guard let data = dataFromFile("ServerData"), let profile = Profile(data: data) else { | |
return [] | |
} | |
if let name = profile.fullName, let pictureUrl = profile.pictureUrl { | |
let nameAndPictureItem = ProfileViewModelNamePictureItem(name: name, pictureUrl: pictureUrl) | |
let sectionItem = ProfileSectionController(title: "Main Info", cells: [ProfileNamePictureCellController(dataModel: nameAndPictureItem)]) | |
items.append(sectionItem) | |
} | |
if let about = profile.about { | |
let aboutItem = ProfileViewModelAboutItem(about: about) | |
let sectionItem = ProfileSectionController(title: "About", cells: [ProfileAboutCellController(dataModel: aboutItem)]) | |
items.append(sectionItem) | |
} | |
if let email = profile.email { | |
let dobItem = ProfileViewModelEmailItem(email: email) | |
let sectionItem = ProfileSectionController(title: "Email", cells: [ProfileEmailCellController(dataModel: dobItem)]) | |
items.append(sectionItem) | |
} | |
var attributeCells = [ProfileAttributesCellController]() | |
let attributes = profile.profileAttributes | |
for attribute in attributes { | |
let attributesItem = ProfileViewModeAttributeItem(attribute: attribute) | |
attributeCells.append(ProfileAttributesCellController(dataModel: attributesItem)) | |
} | |
let attributeSectionItem = ProfileSectionController(title: "Attributes", cells: attributeCells) | |
items.append(attributeSectionItem) | |
var friendCells = [ProfileFriendsCellController]() | |
let friends = profile.friends | |
for friend in friends { | |
let friendsItem = ProfileViewModeFriendsItem(friend: friend) | |
friendCells.append(ProfileFriendsCellController(dataModel: friendsItem)) | |
} | |
let sectionItem = ProfileSectionController(title: "Friends", cells: friendCells) | |
items.append(sectionItem) | |
return items | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment