When building app using SwiftUI you can come across some limitations it has. One of such limitations is that we cannot open another view full screen using .sheet modifier.
It’s very sad. But here is workaround I found and would like to share with you!
Suppose we have tab view based application (MainView) and want to show some popup modally with dimmed background on one of its tabs (AccountView). The first thing that comes to mind is to use ZStack in AccountView using @State variable that triggers modal view visibility. That’s right thing. So let’s write the code down. …
Working with collection view may seem to be complicated. One of the main reasons developers choose table views over collection views is that you don’t have to “suffer” with layout, you only specify the height of a row and that’s it. Moreover, it’s pretty straightforward how to make table view cells self size and it bribes many developers. I personally believe that using collection view is better option because of its flexibility and more control over the layout.
In this article I’m going to describe number of ways how we can make collection view cells self size.
All of the…
I love building reusable components based on protocols, that can provide additional functionality for adopters. And sometimes I want to add for example gestures on UIView subclasses adopters.
So I have to add method that adds gesture recognizer and sets it target and action to handle it. Remember that action property is Selector and the method we referring in the selector must be available to Objective-C, thus marked with @objc modifier. But when we add the modifier we have the following error:
So for now it seems that there is no way to solve the puzzle. …
Hello! Here we are going to create a super simple list using things described in part 1. In the end, we will have this screen done.
Yeah, it doesn’t look cool, but the article is not about design :)
Download starter project:
I have already setup all the needed UI classes. Our plan is to:
Open ProfileViewModel.swift file.
Make the model conform to ViewModel protocol. Add setup() method…
Hello! Using table and/or collection views (I will name them lists throughout the article) is very common for any iOS app. If you care about following programming principles, you are probably wondering how can ViewModel be agnostic about View in its list representation. What is more, you want to be able to setup some list configuration and presentation logic once, and then reuse it throughout your project (or maybe in all your projects).
I hate huge cellForItemAtIndexPath/cellForRowAt methods implementation with several if clauses and frankly speaking it was the main reason I started finding some way to reduce those methods’…
Recently I was to implement certificate-based authentication for enterprise app. When I read documentation for integrating AppConnect SDK (MobileIron’s mobile SDK for wrapping an app), there was mentioned that you do not have to do anything to adopt certificate based authentication to your enterprise services. AppConnect SDK swizzles URLSession class and intercepts all requests from the app.
So when I’ve done nothing, nothing worked 🤷🏻♂️ I was struggling for couple of days to no avail. …
Recently I was working on client certificate-based authentication. The app is for enterprise, so is distributed through MDM. In my case it was MobileIron. Thus the app is using MobileIron mobile AppConnect SDK for iOS. The problem rose up when I managed to properly set the app configuration through MobileIron Core, but authentication still failed.
The process of authentication was driven by numerous redirects. Every next redirect response contained Set-Cookie header with cookies that were obviously important for next request caused by the response.
It is appeared that URLSession — for some reason I do not understand — loses cookies when handling redirects.
The workaround is to implement
urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void)
method of URLSessionTaskDelegate like this:
Do not lose your cookies! As I did 🤷🏻♂️
Hope it will help someone!
I have been developed iOS applications within MVVM architecture for a long time and every time I start new project I try to reduce distance between “perfect” MVVM and my MVVM.
This time I try to get closer to what I saw when searched for original MVVM applications within WPF. I noticed that there are two main players: Properties of a ViewModel, that represent state of a View, and Commands, whose execution is triggered from within a View and processed in the context of the ViewModel.
In this article we will try to create something similar using my favourite iOS…
There are a lot of articles about implementing state-machine in iOS application, but they do not take into consideration one iOS specific thing — transition to a state may take some time to complete and while it’s completing transition to another state may not be possible.
Consider the following situation.
Your view is displaying some content (let’s call it state C). Now you want to show loading when you do some API call (it can be mere ActivityIndicatorView or it can be some controller which you created for this purpose) so you switch state to state Loading and your view is…
It’s not uncommon to have alerts in your app and every developer implements showing alerts in some way. I want to share my approach to showing them when app’s architecture is MVVM.
For binding let’s use Bond framework.
Let’s create simple alert model which will be a view model of UIAlertController.
You can also add some extra properties if you need, that model is just for my approach explanation.
Now when we have the model we want to build it’s view representation consistently, so we create new class called AlertBulder.
And again, you can add here your extra…