With the ability to follow and unfollow users through the browser, it's finally time to make sure we can do the same from our iOS application. In this lesson, we'll present a list of users upon clicking a search button in the nav bar. We'll also discuss how to fetch and display the following status per row.

Comments (9)
Dustin Doosun Yang
4 years ago
Hi Brian I get a following error in UsersSearchController.swift UsersSearchController.swift:31:1: Conformance of subclass of a generic class 'UsersSearchController' to @objc protocol 'UICollectionViewDelegateFlowLayout' cannot be in an extension for the below code extension UsersSearchController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return .init(width: view.frame.width, height: 80) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0 } }
Dustin Doosun Yang
4 years ago
And also I get this error as well. @objc is not supported within extensions of generic classes or classes that inherit from generic classes
Brian Voong
4 years ago
Doosun Yang
4 years ago
I just downloaded your code and try to use it.(just copy and paste) But i am getting those errors.Could it be related to the swift version or something? I am compiling 4.2 swift version for lbtatool framework
Brian Voong
4 years ago
Doosun Yang
4 years ago
If i use 5.0, the xcode complains about your framework(lbtatool is not supported by >=5.0). That’s why switched to 4.2
Brian Voong
4 years ago
Doosun Yang
4 years ago
Ok i will try thanks
Brian Voong
4 years ago
Doosun Yang
4 years ago
I can’t check it now. But i recently updated xcode. Might be 11 then(whatever the latest version)
Brian Voong
4 years ago
Dustin Doosun Yang
4 years ago
I am still getting an error with Swift 5 Showing All Messages :-1: SWIFT_VERSION '5.0' is unsupported, supported versions are: 3.0, 4.0, 4.2. (in target 'LBTATools')
Brian Voong
4 years ago
Dustin Doosun Yang
4 years ago
Anyway, that part was resolved after I switched to 4.2. However, I am still getting an error. ( I downloaded your code and trying to run now. Issue still persists) Conformance of subclass of a generic class 'UsersSearchController' to @objc protocol 'UICollectionViewDelegateFlowLayout' cannot be in an extension extension UsersSearchController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return .init(width: view.frame.width, height: 80) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0 } }
Dustin Doosun Yang
4 years ago
And my xcode version is Version 10.1 (10B61)
Brian Voong
4 years ago
Dustin Doosun Yang
4 years ago
Thanks Brian, Everything starts working fine after I updated my xcode to 10.3. Seems that code is not compatible with 10.1.
Brian Voong
4 years ago
omari
3 years ago
Hi Brian, Can you please give some more details about the LBTATools especially about the LBTAListController. Do you have any reference. I only know the LBTA tool from earlier lessons where it helped us to layout views.
omari
3 years ago
I found this video I will check it out https://www.youtube.com/watch?v=cpZzWZEKTKE&feature=youtu.be
AlfieLBTA
3 years ago
Hey Fellow LBTA students: For those having this error: Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength on the console, as of Alamofire V5 you need to send data back on your response with something like this: res.end("Successfully following user ", userTofollow); in order for Alamo to skip the serialization error and let the collection view reload the index.
joeypozzyclinch
3 years ago
Hi Alfie, Thank you for posting this! Where do I put this? I assumed it was at the end of the "search.js" file in the Visual Studio Code project, but then what is the "userToFollow" variable referring to?
AlfieLBTA
3 years ago
Thats a local variable of my proyect, you can return the Id of the user like in my case or just the message.
joeypozzyclinch
3 years ago
Oh, it was in "follow.js". Awesome thank you so much Alfie!!
gerkov77
3 years ago
Thank you AlfieLBTA, you are an Ace !
Setwork44
3 years ago
Hey Brian, in your LBTA syntax how would I be able to wrap that HStack of user name inside a Stack so I can put another title underneath the user name? while still keeping the spacer and the button on the right ? Kind Regards.
Brian Voong
3 years ago
Setwork44
3 years ago
*VStack
Udin Rajkarnikar
3 years ago
Hello Brian, Can you explain more about the parentController? Still a bit confused.
Brian Voong
3 years ago
gerkov77
3 years ago
Hello Brian, Could you update us with the latest Alamofire request methods? The code for this in your sample project does not work anymore and it is very confusing how to fix it correctly! Thanks in advance! Greg
omq78
3 years ago
hi brian seems everything is fine here BUT i have a small problem i have to dismiss search controller manually and reload it back to toggle the buttons of follow and unfollow it did not directly toggled thanks
omq78
3 years ago
ok got it it fills in dataResp.error {} code block this block had a return command so it wasn't process the reload items now my code is working but i think not correct because i have alamofire error [ responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength) ] but iOS passes this error and process the following and unfollowing posts strange !
Christopher J. Roura
2 years ago
Hi all, A lot of people are asking for the AlamoFire request update. The code below works for now: extension UsersSearchController { func didFollow(user: User) { guard let index = self.items.firstIndex(where: {$0.id == user.id}) else { return } let isFollowing = user.isFollowing == true let url = "\(Service.shared.baseUrl)/\(isFollowing ? "unfollow" : "follow")/\(user.id)" AF.request(url, method: .post) .validate(statusCode: 200 ..< 300) .response { dataResp in if let err = dataResp.error { print("Failed to unfollow:", err) return } self.items[index].isFollowing = !isFollowing self.collectionView.reloadData() } } }
Lazaro Ambrosio
2 years ago
Thanks Christopher!
HELP & SUPPORT