Skip to content

Commit

Permalink
Shorten method body
Browse files Browse the repository at this point in the history
  • Loading branch information
minacle committed May 27, 2022
1 parent 7c67d60 commit 6c40ef4
Showing 1 changed file with 24 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,69 +232,31 @@ extension PersistentContainer {
userDetail.userID = latestUserDetail.userID
userDetail.username = latestUserDetail.username
}
if let blockingUserIDs = previewUserDetail.blockingUserIDs {
userDetail.blockingUserIDs = blockingUserIDs
}
if let creationDate = previewUserDetail.creationDate {
userDetail.creationDate = creationDate
}
else {
userDetail.creationDate = .now
}
if let followerUserIDs = previewUserDetail.followerUserIDs {
userDetail.followerUserIDs = followerUserIDs
}
if let followerUsersCount = previewUserDetail.followerUsersCount {
userDetail.followerUsersCount = .init(followerUsersCount)
}
if let followingUserIDs = previewUserDetail.followingUserIDs {
userDetail.followingUserIDs = followingUserIDs
}
if let followingUsersCount = previewUserDetail.followingUsersCount {
userDetail.followingUsersCount = .init(followingUsersCount)
}
if let isProtected = previewUserDetail.isProtected {
userDetail.isProtected = isProtected
}
if let isVerified = previewUserDetail.isVerified {
userDetail.isVerified = isVerified
}
if let listedCount = previewUserDetail.listedCount {
userDetail.listedCount = .init(listedCount)
}
if let location = previewUserDetail.location {
userDetail.location = location
}
if let mutingUserIDs = previewUserDetail.mutingUserIDs {
userDetail.mutingUserIDs = mutingUserIDs
}
if let name = previewUserDetail.name {
userDetail.name = name
}
if let profileHeaderImageURL = previewUserDetail.profileHeaderImageURL {
userDetail.profileHeaderImageURL = profileHeaderImageURL
}
if let profileImageURL = previewUserDetail.profileImageURL {
userDetail.profileImageURL = profileImageURL
}
if let tweetsCount = previewUserDetail.tweetsCount {
userDetail.tweetsCount = .init(tweetsCount)
}
if let url = previewUserDetail.url {
userDetail.url = url
}
if let userAttributedDescription = previewUserDetail.userAttributedDescription {
userDetail.userAttributedDescription = .init(userAttributedDescription)
}
if let userCreationDate = previewUserDetail.userCreationDate {
userDetail.userCreationDate = userCreationDate
}
if let userID = previewUserDetail.userID {
userDetail.userID = userID
}
if let username = previewUserDetail.username {
userDetail.username = username
func assign<T>(_ value: T?, to dest: inout T) {
if let value = value {
dest = value
}
}
assign(previewUserDetail.blockingUserIDs, to: &userDetail.blockingUserIDs)
assign(previewUserDetail.creationDate ?? .now, to: &userDetail.creationDate)
assign(previewUserDetail.followerUserIDs, to: &userDetail.followerUserIDs)
assign(previewUserDetail.followerUsersCount.flatMap({.init($0)}), to: &userDetail.followerUsersCount)
assign(previewUserDetail.followingUserIDs, to: &userDetail.followingUserIDs)
assign(previewUserDetail.followingUsersCount.flatMap({.init($0)}), to: &userDetail.followingUsersCount)
assign(previewUserDetail.isProtected, to: &userDetail.isProtected)
assign(previewUserDetail.isVerified, to: &userDetail.isVerified)
assign(previewUserDetail.listedCount.flatMap({.init($0)}), to: &userDetail.listedCount)
assign(previewUserDetail.location, to: &userDetail.location)
assign(previewUserDetail.mutingUserIDs, to: &userDetail.mutingUserIDs)
assign(previewUserDetail.name, to: &userDetail.name)
assign(previewUserDetail.profileHeaderImageURL, to: &userDetail.profileHeaderImageURL)
assign(previewUserDetail.profileImageURL, to: &userDetail.profileImageURL)
assign(previewUserDetail.tweetsCount.flatMap({.init($0)}), to: &userDetail.tweetsCount)
assign(previewUserDetail.url, to: &userDetail.url)
assign(previewUserDetail.userAttributedDescription.flatMap({.init($0)}), to: &userDetail.userAttributedDescription)
assign(previewUserDetail.userCreationDate, to: &userDetail.userCreationDate)
assign(previewUserDetail.userID, to: &userDetail.userID)
assign(previewUserDetail.username, to: &userDetail.username)
if save {
do {
try context.save()
Expand Down

0 comments on commit 6c40ef4

Please sign in to comment.