Coding Explorer Blog

Exploring how to code for iOS in Swift and Objective-C

  • Home
  • Apps
  • About
  • Contact

Error Handling in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 10, 2020

Ideally, errors should never occur.  File we need should always be available and networks should always be present and reliable.  Unfortunately this reality is not ideal and we have to deal with the consequences.  Thankfully the Swift team included a great way to handle these deviations from the ideal in Swift 2.  Swift Error Handling lets us quickly and easily warn the compiler whether a function can throw an error, actually throw it, and handle it in whatever way seems appropriate.
[Read more…]

Filed Under: Swift Tagged With: Swift

Creating and Modifying a URL in your Swift App

Xcode 11.6 Swift 5.2.4

Last updated on December 22, 2020

In many types of apps, you have to access files.  They can be in your app bundle, on the file system, or even somewhere on the web.  You need to have someway to refer to where they are in your code.  On Apple platforms, you basically have 2 choices, as a String or aURL.

Given the address bar right above you, or any use of a terminal, a Swift String would be a very understandable choice, I mean, that’s all that text is in the address bar, right?  Many of the older APIs in the Cocoa and Cocoa Touch SDKs take URLs and Strings (referred to as a “path” in those APIs usually), but things are moving more and more towards just using URL objects everywhere.  URL objects have many advantages over String paths, most notably that you can access different parts of the URL from properties, instead of having to write your own code to parse those components from the path String.

Stay tuned as we learn a thing or two about creating and using URL objects in your Swift app.
[Read more…]

Filed Under: Swift

Watch Connectivity in Swift — Application Context

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

In the age of watchOS 1, the watchKit extension was on the paired iOS device, making sharing data between it and the main iOS app easy.  For the simplest of data, like preferences, we could just use NSUserDefaults with App Groups functionality.  We still should use that when sharing data between other extensions that still remain on the phone, like today view extensions, but not for watchOS apps anymore.

Luckily, Apple gave us a new API to use, that is significantly more robust than piggy-backing on App Groups, Watch Connectivity.  Watch Connectivity gives a lot more information about the status of the connection between your Apple Watch and its paired iPhone.  It also allows interactive messaging between the iOS App and the watchOS app, as well as background transfers that come in 3 flavors.  Those flavors are:

  1. Application Context
  2. User Info Transfer
  3. File Transfer

Today we will be talking about the first one, Application Context.
[Read more…]

Filed Under: Swift

watchOS Hello World App in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

I have been working on some watchOS updates lately, and thought it would be helpful to share a bit about that.  First things first, we need to actually know how to make a watchOS app in the first place.  It’s time to do “Hello World!” watchOS style!

Before we begin though, I want to help you the reader, learn what you need to know about programming for iOS, watchOS, tvOS, or OS X in Swift.  As such, if you have any topics you would like to learn about on the Coding Explorer Blog, please suggest them to me on Twitter @CodingExplorer or the Contact Page.
[Read more…]

Filed Under: Swift Tagged With: watchOS

API Availability Checking in Swift

Xcode 11.6 Swift 5.2.4

Last updated on August 12, 2020

With all of the new and awesome APIs that come out every year for each successive iOS version, it can be tempting to just drop support for the previous versions of iOS, and just go completely to the new stuff.  Of course though, we usually can’t do that for many reasons.  As such, we need to support older versions of iOS, and maybe dropping the oldest ones after they just become too difficult to support, or when active users on that platform drop to a certain amount.

There have been ways to check for API availability for some time, by checking if something responds to a selector, or just checking the iOS version ourselves and using that in a normal Swift “if” statement.  With the arrival of Swift though, we have an even nicer version of API checking, that is even helped by Xcode itself.  This allows Xcode to actually warn you if you try to use something that is unavailable on one of the deployment targets for your Swift app.
[Read more…]

Filed Under: Swift Tagged With: Swift

  • 1
  • 2
  • 3
  • …
  • 16
  • Next Page »

Subscribe to the Coding Explorer Newsletter

* indicates required

Follow Us

Facebooktwitterrss

Recent Posts

  • Error Handling in Swift
  • Creating and Modifying a URL in your Swift App
  • Watch Connectivity in Swift — Application Context
  • watchOS Hello World App in Swift
  • API Availability Checking in Swift

Categories

  • Class Reference
  • General
  • Interface Builder
  • My Apps
  • Objective-C
  • Swift
  • Syntax
  • Tutorial
  • Uncategorized

Archives

  • May 2016
  • March 2016
  • February 2016
  • December 2015
  • July 2015
  • June 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • January 2014
  • November 2013
  • September 2013
  • August 2013
  • July 2013
  • Terms Of Use
  • Privacy Policy
  • Affiliate Disclaimer

Subscribe to the Coding Explorer Newsletter

* indicates required

Copyright © 2025 Wayne Media LLC · Powered by Genesis Framework · WordPress