This video is available to students only

Turning our app into a status bar app

Now, we are going to turn our app into a status bar app. To do this we are going to migrate the native code from Objective-C to Swift. In all honesty, this is not 100% necessary - we could do this without Swift, but... I don't know Objective-C and I also don't want to learn it! It has very complicated syntax, and outside mac native development there is very little use for it.

When I started developing my apps on macOS I knew very little Swift, but it's much more similar to JavaScript and C-like languages than Objective-C, so it makes sense to migrate our base app to Swift.

Migrating to Swift#

There are quite a few steps here, so I'm going to be as thorough as possible.

1. Remove the existing Obj-C code#

Delete the following files from the project

You have to delete them from XCode to remove the internal references, otherwise your project might be left in a broken state.

Delete references

2. Create a AppDelegate.swift file#

In your project's -macos folder, right-click and select create new file, then select Swift and create an AppDelegate.swift file.

Once you create it, XCode will ask if you want to create a bridging header file. Accept the prompt. The bridging header file will expose Obj-C libraries to our Swift code, a requirement if you write any Swift in an XCode project.

After creating the app delegate

The bridging header simply allows exposing Obj-c libraries to Swift - within this bridging header add the following content:

and in AppDelegate you can replace the following content (we will walk through it next):

 

This page is a preview of Building React Native Apps for Mac

Start a new discussion. All notification go to the author.