HTTP -> HTTPS redirects need to be handled correctly

Had the issue that a URLSession request I was POSTing wasn’t having its data arrive on the server. Figured out the server was redirecting the HTTP request to an HTTPS URL, however turning it into a GET request, dropping the POST data. The solution – wrap the request and implement

public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
        originalRequest.url = request.url

(from the URLSessionTaskDelegate). This fixed the issue.

Found solution on

Push segue not pushing? Delete it and try again.

Ugh. Created a segue from a ViewController in the Document Outline to a new View Controller, set it to push. But in the app it was showing it as a modal segue.

Solution was: delete the segue, recreate it (this time I went straight from the table view cell itself instead of from the Document Outline), aaaaand it works. Thanks, Obama Xcode.

Changes Inside Property Observers

Changes Inside Property Observers
It is also possible to make changes to the variable inside its own property observers. You can reassign the entire variable, change its values or call mutating functions on it. When you do that from inside a property observer, the property observers do not trigger since that would most likely cause an endless loop. Keep in mind that changing something in willSet will be without effect since your change will be overwritten by that value that was being set originally (this gives a nice warning in Xcode as well).
– via Xebia Blog


Presenting Controller is nil in custom transitioning delegate: “nil while unwrapping Optional”

Have a custom UIViewControllerTransitioningDelegate which, when its presentationController(forPresented, presenting, source)  method is called after a View Controller calls present, the presenting parameter is nil, which my method wasn’t expecting. Well, turns out, according to Swift docs…

This parameter may also be nil to indicate that the presenting view controller will be determined later.

Well, what a helpful parameter. So we need to handle this case, just in case the presenting view controller needs to be determined later for some reason.