Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct User {
- init(name: String) {
- self.name = name
- }
- let name: String
- private var interests = [Interest]()
- private var following = [User]()
- mutating func addInterest(_ interest: Interest) {
- interests.append(interest)
- }
- mutating func removeInterest(_ interest: Interest) {
- interests.removeAll(where: { $0 == interest })
- }
- mutating func follow(_ target: User) {
- following.append(target)
- }
- mutating func unfollow(_ target: User) {
- following.removeAll(where: { $0 == target })
- }
- func getFollowingList() -> [User] {
- return following
- }
- func getInterestsList() -> [Interest] {
- return interests
- }
- }
- extension User: Equatable {
- static func == (lhs: Self, rhs: Self) -> Bool {
- return lhs.name == rhs.name
- }
- }
- struct Interest {
- let name: String
- }
- extension Interest: Equatable {
- static func == (lhs: Self, rhs: Self) -> Bool {
- return lhs.name == rhs.name
- }
- }
Add Comment
Please, Sign In to add comment