Q:

iOS - how to create hideable top UIView from code

I want to add custom UIView to the main screen of my app, that shows / hide if internet connection is lost / restored. How can I do this from code? 

A:

To hide a view in Swift 3 you use:
viewVar.isHidden = true

If you want to pair that with a reachability check, I use the Reachability Swift library found here.
I create a function to check reachability like this:
 func CheckWiFi() -> Bool

    {

        do {
            try reachability.startNotifier()

        } catch {

            print("Unable to start notifier")
        }

        if reachability.isReachable == true{

            if reachability.isReachableViaWiFi == true{

                reachability.stopNotifier()

                wifi = true

                return wifi

            } else if reachability.isReachableViaWWAN == true{

                reachability.stopNotifier()

                print("Reachable via WWAN simulator")

                return wifi

            }else

            {

                reachability.stopNotifier()

                print("Reachable via Cellular")

                return wifi
            }

        }
        else

        {

            wifi = false

            reachability.stopNotifier()

            print("Not reachable")

            return wifi

        }

    }

Then in order to use it, I use the following:
 if CheckWiFi() == true
        {

        // show view here

        }

        else

        {
            // hide view here
        }

