How should I refactor my app correctly? [closed] - ios

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to create an app with ability for user to log in via Facebook, Twitter, Google, and LinkedIn. I'm using a single UIViewController and adding more and more code to viewDidLoad method. At this point my controller looks awful and I would like to split the code between associated classes (one for Facebook, and so on). I even thought about using custom views for every social media login button...
What would be the right thing to do?

There are at least two things to split in your case.
Login with different networks. It purely depends on your UI. You might have a separate view (and corresponding class) for each network or a popup.
Split code by applying an architectural pattern (MVC, MVVM, VIPER, etc.)
Here is a nice overview of them:
https://techblog.badoo.com/blog/2016/03/21/ios-architecture-patterns/
Additional change you should do is to introduce a separate bunch of classes to handle log in via social networks. Then in your view controller (or better in a View Model or somewhere else, depending on the design pattern you choose) you call SocialNetworkService.authenticateWithTwitter(email:password)
But remember, these classes have to know nothing about view controller.
I hope my answer gives you a hint in which direction to go.

Related

Create a chat like in Ada in Swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm new to programming, so please be patient. I'd like to implement in my current app a chat, but not with other users, but rather with the app itself. In the app called "Ada" the way user interacts with the app is through various buttons that he presses, after which the app gives the answer. So, as far as I understand what I try to create has nothing to do with machine learning, so I'd like to avoid such services as DialogFlow or the same service provided by IBM, as I don't want to pay for the additional features that I will never use (I don't want my users to use keyboard input to interact with the app, I want them to use only buttons). But I'd like to create a page, which looks like a chat. The only app that I know that has implemented exactly what I need is Ada. The problem is that there is literally no page on that topic on the Internet, so I don't know where to even begin. As I don't know where to even start, I have no starting code to provide you with.
Here is a simple example of what I mean:
On the right the app gives the user a test, as user pressed "begin" button
Hope that you understand what I need and you'd help me a lot if you would explain exactly how to create such a chat.
It looks like there is a Udemy course on this very subject:
https://www.udemy.com/course/simple-ios-chat-app-in-swift-4-firebase-4/?LSNPUBID=VkwVKCHWj2A&siteID=VkwVKCHWj2A-wV3kGNSueSCVcV8Oj.3Qxw&utm_source=adwords&utm_medium=udemyads&utm_campaign=DSA_Catchall_la.EN_cc.US&utm_content=deal4584&utm_term=_._ag_95911180068_._ad_436639626698_._kw__._de_c_._dm__._pl__._ti_dsa-402185414521_._li_9059739_._pd__._&matchtype=b&gclid=EAIaIQobChMI-uSro4KM6gIVCYizCh3XiwKLEAAYASAAEgL81PD_BwE

Xcode UI Testing plan [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I would like to implement UI Testing for my app, but I couldn't find anywhere some guides on how to structure the tests, group them or which is the best way to proceed writing the tests - a big flow in a test, or multiple tests for smaller flows.
If you have some resources regarding these topics, any help would be appreciated.
Thank you!
You can use this as reference https://www.raywenderlich.com/960290-ios-unit-testing-and-ui-testing-tutorial
and this one https://www.hackingwithswift.com/articles/148/xcode-ui-testing-cheat-sheet
For UI Testing, you must record first your test cases, and Xcode will fill automatically the codes for you(But I don't do this approach since I preferred to do it manually and programmatically, so I don't have to record all the event's that I need to test)
I assign a accessibilityIdentifier to every views/buttons and etc, that I have so I can call/compare it inside the UITest Class.
I grouped them depending on the scene that I want to test like for example I created test cases that would start from login. And separate test cases that would start from registration, depending on the state of your app.
In addition to this, I have created a simplified pattern and created an Example project to implement UI Testing from this repository https://github.com/michaelhenry/AutoBot
Update:
For testing views that are created using SwiftUi,
You can use the method “.accessibility(identifier: “your_control_accessibility_identifier”)”
I believe there is no general answer to your question, since UI testing depends essentially on the UI of your app.
In the app I am currently working on, I test scene by scene, i.e. the controls of every view controller. So, some of them are related to basic functions, some to iCloud setup, etc.. I believe - but I don’t have too much experience - that testing scene by scene is straightforward, if your scene structure is clear, and it is relatively easy not to omit essential functions.

Are Storyboards a good idea for apps that access the cloud? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm just about to delve into the world of app development (I'm usually a game developer) in iOS, and I've read the debates of using Storyboards Vs doing it programmatically, and I get for simple apps Storyboards is the way to go, but what about for Apps that access a server? and need to do lots of things dynamically? it seems most Apps these days would be like that, if that's the case are Storyboards a good idea in that situation?
You have to remember that Storyboards are not an alternative to code. They are a tool that can be used along with coded view, nibs, etc...
The real skill comes in using all of these in such a way that takes least effort and gives most maintainability, readability and reliability.
Many of my apps combine several storyboards and a lot of nibs.
Having said that. Nothing that can be done in a storyboard should be anywhere near any cloud code.
The classes that access the cloud should not change whether you are coding views using nibs or using storyboards.
The article that was linked in the other answer is very odd indeed. To dismiss storyboards as things that are only used for prototyping is just plain wrong.
A well structured app (or part of an app) that access some network stuff should be modelled something like...
[Networking stuff]----[View Controller Stuff]----[View Stuff]
It doesn't matter whether the view controller is created in a storyboard, nib or in code. The networking stuff is unchanged.
Also, the article mentions "custom views" as something that you can't do with Storyboards. Again, that's just wrong. My latest app Emojicate was written using a combination of Storyboards (the project has 2 storyboards), nibs (for custom cells etc...) and a couple of coded views (the emoji message view is coded).
It sounds like the guy writing that hasn't really looked into the various tools in any amount of detail.
Please take a look at the this article. I think it's summarised really nice and briefly the pros and cons:
http://andrewrauh.com/2013/09/01/storyboardsnibs-vs-doing-everything-with-code-in-ios/

Recommendation? New class (xib) or new View in a class [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This question is in relation to X-code, ios, objective-c
Can anyone kindly suggest what is recommended in terms of having a new class or just additional views within exiting class for each new screen I require.
I understand that each approach has its own pros and cons in terms of flexibility in implementation, but wanted to understand if the approaches make any difference in how the app perform or.. is there a recommended way of doing things.
Thanks a lot in advance
Adding an example, as the question was suggested to be too vague.
If I wanted to add a T&C page to my login screen, what is recommended, should I simply add a 'View' to my login class, or should I create a new class 'T&C' (T&C maybe a very simple example, but I think that kind of gives the idea)
To your general question, the answer is "it depends..."
But for your T&C example, I would create a new view controller to be presented onscreen. Since you may end up needing that T&C content elsewhere in the app (e.g., and About screen), that would be the approach I'd take.

How do you manage view tags in your iOS project? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have an iOS app that uses a few viewcontrollers with lots of elements. I built the viewcontrollers in the interface builder (in a storyboard). For some key elements (loginbutton, important text, etc..) I created an IBOutlet to be able to use these elements in my code (adjust text/graphics mostly).
For some others where I just needed a quick fix (for example an activity indicator that I show and hide programmatically), I chose to not create an IBOutlet, but instead give them a tag number and access them by the viewWithTag:(NSInteger) method.
This seemed to work for me (it's only my second iOS project so it might be completely wrong to do this). But now that the viewcontrollers get more complex I find it hard to remember which numbers I already used for tags. Is there any way to keep track of this other than by going trough all the elements and checking their tag?
Maybe it's all wrong to use tags this way, in that case that's fine too. I could look them all up once and just create IBOutlets for all the cases where I use a tag now.
I would try to avoid using view tags as much as possible.
There are always other (and almost always better) ways to do exactly the same thing by using properties and data models instead of tags.
Here is an article that I found with some nice examples of why they're not a good idea to use... http://doing-it-wrong.mikeweller.com/2012/08/youre-doing-it-wrong-4-uiview.html
If you need to access a UI element then create an IBOutlet for it in the interface of the class that needs it.
Alternatively, if there are several elements that are the same then you can create and IBOutletCollection which is just an array that contains all the elements linked to it.
EDIT
For anyone stumbling across this now. This is an article from a former Apple engineer explaining why using tags is not only a code smell and bad practice but also a performance issue.
https://www.fadel.io/blog/posts/ios-performance-tips-you-probably-didnt-know/

Resources