How can I check for an active Internet connection on iOS or macOS?

Important: This check should always be performed asynchronously. The majority of answers below are synchronous so be careful otherwise you’ll freeze up your app. Swift Install via CocoaPods or Carthage: https://github.com/ashleymills/Reachability.swift Test reachability via closures let reachability = Reachability()! reachability.whenReachable = { reachability in if reachability.connection == .wifi { print(“Reachable via WiFi”) } else { … Read more

Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

TL;DR: Don’t like reading? Jump straight to the sample projects on GitHub: iOS 8 Sample Project – Requires iOS 8 iOS 7 Sample Project – Works on iOS 7+ Conceptual Description The first 2 steps below are applicable regardless of which iOS versions you are developing for. 1. Set Up & Add Constraints In your … Read more

How can I make a UITextField move up when the keyboard is present – on starting to edit?

You will only need a ScrollView if the contents you have now do not fit in the iPhone screen. (If you are adding the ScrollView as the superview of the components just to make the TextField scroll up when keyboard comes up, then it’s not needed.) The standard way to prevent the TextFields from being … Read more

What’s the difference between the atomic and nonatomic attributes?

The last two are identical; “atomic” is the default behavior (note that it is not actually a keyword; it is specified only by the absence of nonatomic — atomic was added as a keyword in recent versions of llvm/clang). Assuming that you are @synthesizing the method implementations, atomic vs. non-atomic changes the generated code. If … Read more