greedydev

Untitled

Oct 1st, 2023
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.03 KB | None | 0 0
  1. struct User {
  2.     init(name: String) {
  3.         self.name = name
  4.     }
  5.    
  6.     let name: String
  7.    
  8.     private var interests = [Interest]()
  9.     private var following = [User]()
  10.    
  11.     mutating func addInterest(_ interest: Interest) {
  12.         interests.append(interest)
  13.     }
  14.    
  15.     mutating func removeInterest(_ interest: Interest) {
  16.         interests.removeAll(where: { $0 == interest })
  17.     }
  18.    
  19.     mutating func follow(_ target: User) {
  20.         following.append(target)
  21.     }
  22.    
  23.     mutating func unfollow(_ target: User) {
  24.         following.removeAll(where: { $0 == target })
  25.     }
  26.    
  27.     func getFollowingList() -> [User] {
  28.         return following
  29.     }
  30.    
  31.     func getInterestsList() -> [Interest] {
  32.         return interests
  33.     }
  34. }
  35.  
  36. extension User: Equatable {
  37.     static func == (lhs: Self, rhs: Self) -> Bool {
  38.         return lhs.name == rhs.name
  39.     }
  40. }
  41.  
  42. struct Interest {
  43.     let name: String
  44. }
  45.  
  46. extension Interest: Equatable {
  47.     static func == (lhs: Self, rhs: Self) -> Bool {
  48.         return lhs.name == rhs.name
  49.     }
  50. }
  51.  
Add Comment
Please, Sign In to add comment