Infinite Profiles ViewController: Swift Best Practices - ios

I building an app with user profiles. When a user searches for another user or searches their own followers I of course want to display said user profiles. My question is how should I best set up clicking on user profiles within user profiles while being able to handle the potentially infinite stack of profiles.
Example, user searches for a friends and then looks thru the friends of the friend and then keeps searching and keeps clicking. I then want the user to be able to back track like in the FB app.
The two options I've thought about are making UIViews within UIViews or more Viewcontrollers. If anyone has experience with this particular issue or github links to projects that address this issue that'd be amazing thanks!
Also I can post code from my project if anyone would think it'd be helpful but I don't see how it would be at the moment.

In general you would just use a regular UINavigationController and let the user navigate normally, continually pushing new view controllers onto the stack. You shouldn't really have to worry about performance in the view controllers underneath the top one, unless maybe they are doing something expensive repeatedly (in which case, you would disable those expensive operations in something like viewDidDisappear: and re-enable them in viewDidAppear:).
The number of view controllers would have to be pretty high for this to cause issues under normal conditions.

Related

Detecting screen interaction outside of the component in SwiftUI

I'm building my own custom list using LazyVStack with swipeable actions thanks to this tutorial: https://prafullkumar77.medium.com/swiftui-how-to-make-custom-swipe-able-cell-727a27abdddd
It isn't half bad as long as you read through it and understand it instead of just copying and pasting. However, much like all the currently available open-source frameworks out there, it is missing a core feature that I don't know if people are just forgetting about or it's just not possible so I thought I'd ask because I can't figure it out.
In a native list in UIKit, if you drag a list item to the semi-open state and have one of the list item actions visible but then interact anywhere else in the list via drag or tap, it will dismiss the currently visible list item action. Dismissing the action is the easy part, it's telling it to dismiss which puzzles me.
I know there are many things apple can do that isn't publicly available but this does seem like something that should theoretically be possible. I'd like to figure this out and make it publicly available as these swipeable actions are a key feature apple seemingly forgot to add before deciding to move towards these lazy stacks.

How are apps with typical menu-bar-style navigation coded?

I’m a relatively new app developer working on a couple of individual projects. I’ve dumped at least one hundred hours into coding using Swift in Xcode, and, as embarrassing as it may be to admit, it seems I can’t fully grasp or find information pertaining to how popular apps such as Facebook, Instagram, YouTube, or Tinder implement non-linear view navigation via a menu bar at the bottom of the screen.
I’ve seen one particular app tutorial series that exemplifies how to go about making this menu bar style possible using a collection view of horizontally-placed views each equivalent to the size of the screen. I understand this gets rid of the issue of loading new views on top of existing old ones that sit in the background (my primary worry, outside of unnecessarily reloading information), but is this the typical method of implementing non-linear menu navigation in an app? I suppose a more pressing question at this point is “How can I go about making something like this using SwiftUI?”
If anyone can offer information, explanations, and/or sources, they would all be much appreciated. Thank you for your time!
So, upon receiving TylerTheCompiler’s comment on my post, I started researching the UITabView. It appears that this is used for creating exactly what I was trying to explain in the initial post. I subsequently searched for a way to implement this in SwiftUI and found the “tabbed view.” The tabbed view seems very easy to implement and is exactly what I’ve been looking for. I still wonder if popular applications have been utilizing the UITabBar rather than something else more practical that I am still unaware of. If you happen to know, please comment on this post — I would love to know, myself. As always, thank you for your time, everyone!

Complex Startup Logic in iOS Apps: Where Should it Reside?

Everyone has seen the classic didFinishLaunchingMethod run amok.
Well now that we have additional things to consult when starting up like CloudKit, that are, to make things worse, asynchronous, the app delegate seems like the wrong place to do even the most basic stuff like asking if they have accounts and establishing syncing, or grabbing a snapshot.
I hate the idea that those things would go into the first controller that the app would launch, flashes me back to 4GL tinkertoys from days of yore.
Yet, we have to honor the flows of the storyboards. I have found nothing searching around on this. And sadly the most extensive Apple example, Lister, is not a great source for best practices.
It's suitable for the app delegate to trigger the start of this work, but not to handle the results. Often you want some way to display progress / errors / request user info. So, having some form of 'splash' view controller which handles the transition from your launch image into this process and controls the flow into the main app is handy. Generally the logic for this kind of thing is reusable in other situations so that part should be in some other controller class. The storyboard can make the splash VC the initial controller and the app delegate can create and pass it the data controller class which deals with the logic and updates the VC (it's delegate) with the results. Often the splash VC will then pass the data controller on to the subsequent VC it displays, though that isn't required of course.

ScrollView and viewcontrollers

Here is context for my question, this is an optional read:
I have to develop an app for a
school project. At the end of the year some people I don't know will
listen to me presenting my app, and review my presentation and my app
(note that they will probably not be app developers, they are usually
IT professors) (note also that I'm allowed to ask for help to anybody,
and I can use internet since I do this mostly on my "free time")
So since October I'm developing my app, that takes a lot of time
because this is my first app. And here comes the issue:
My app is a giant Scroll view with 5 NavigationsControllers, each containing a ViewController. These ViewControllers sometimes have buttons that leads to an other ViewController. The problem is when I use these buttons, and another view controller is displayed, when I swipe right or left the ScrollView scrolls and another ViewController from the scrollView is displayed. I don't want this to happen because most of the time the ViewController displayed after the tap on a button is not meant to stay, it's generally a form to send data to the server.
As I think this is difficult to understand, you can download the project on Github
Is there a way for me to disable scroll on chosen ViewControllers? or should I change everything to avoid using a ScrollView?
Bonus question:
Is it a really really bad idea to make an app this way, or did I just miss something?
Thanks for your help!

Direct to appropriate ViewController when user logs out/ is not logged in

I posted a similar question some time back, but it turns out the solution I chose is not sustainable nor a good one. So I'm trying again, with a different approach.
Here's my problem
I'm making an app that uses Facebook login and connects to a server. Therefore, at any given time, the user has to be logged in with Facebook and the user_id needs to be stored in the NSUserDefaults. If at any time in the app, any of the two is not present, I need to direct the user to a log-in screen.
In the same fashion, if the user manually presses log out, I need to direct him/ her to that same screen.
Seing that I'm using the SWRevealViewController, I need more than one UINavigationController. Therefore the popViewController does not work.
Here's my app setup
The initialViewController is a UINavigationController, pointing to another ViewController. In here, I check if the user is signed into Facebook and that the user_id is stored in the NSUserDefaults. If they are, I direct them to the SWRevealViewController. If they are not, I direct them to a LoginViewController (I use performSegueWithIdentifier:). From the LoginViewController, after the user is successfully signed into both Facebook and my servers, I direct them to the same SWRevealViewController.
Basically, the SWRevealViewController splits into two: A sw_front and a sw_rear (the menu). Each of those requires their own UINavigationController (as far as I know, I didn't get it to work without).
From here on, the app splits into several different ViewControllers.
You can see the storyboard in this image:
(Link to full-res image here)
(The logout button is the blue one on the top, the login is the blue one at the start)
Here's what I've tried:
The last time I asked a similar question, I chose to go with a solution where I present the InitialNavigationController using the presentViewController function when the user logs out. This seemed to work fine, and the new ViewController was presented modally which other apps seem to do as well (see linkedIn and more).
However, when I proceeded to log in again, the Facebook showLoggedInUser method seemed to be called twice (I placed a NSLog() statement in there). When I repeated a third time, it ran three times. Fourth login, four times, and so on.
In addition, on the second logout, I would get a warning in the compiler saying Warning: Attempt to present <UINavigationController: 0x13c566730> on <UINavigationController: 0x13c549c70> whose view is not in the window hierarchy!. This warning would also keep incrementing as I repeated the login-logout process.
What I want:
As I understand, I keep adding the InitialViewController to the stack as a modal view, and this is not what I want. I simply want to go back to the start. Or anything that works for that matter. Just as long as I have a simple login/ logout system that works, I'll be glad. Bear in mind that we need to be able to call the View that should be presented from any view in the app if the user appears to be logged out (if he logged out from Facebook, if the Facebook thing timed out, or if the NSUserDefaults for some reason reset (for example under an update)).
If possible, I'd like to know what other apps does to achieve this (for example linkedIn, Facebook, Twitter, or anyone else).
What I've been thinking about is adding a separate LoginView not connected to anything, that I can load up modally whenever I see the user is logged out. Whenever the login is completed, I simply dismiss the view and the user returns to where he was last.
The only problem I see about this is that when the user logs out, he is technically still "inside" the app, though he cannot dismiss the modal view controller without logging in.
Would this be a bearable solution to my problem?
What do you suggest?
Some physical code showing how to present the new view/ going back (or any other solution) is preferred, but any help is appreciated!
I know this was a long question, and there are possibly many answers, but I've been stuck at this for way to long and I just want a solution that will work with my setup. So I felt the need to explain everything. If there's anything you don't get, please don't hesitate to ask!
Thank you so much in advance!

Resources