Joseph Michael Pesch
VP Programming

XCode - Add AppDelegate.swift and SceneDelegate.swift to SwiftUI Application

by 13. March 2021 13:42

Step 1) Comment out (or remove) the @main code entry point (example below).


structiDineApp: App {

    @StateObject var order = Order()


    var body: some Scene {

        WindowGroup {






Step 2) Add entry shown below to info.plist











                <string>Default Configuration</string>







Step 3) Add AppDelegate.swift

import Foundation

import UIKit



classAppDelegate: UIResponder, UIApplicationDelegate {


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // Override point for customization after application launch.




    // MARK: UISceneSession Lifecycle


    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {

        // Called when a new scene session is being created.

        // Use this method to select a configuration to create the new scene with.

        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)



    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

        // Called when the user discards a scene session.

        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.

        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.




Step 4) Add SceneDelegate.swift

import UIKit

import SwiftUI


classSceneDelegate: UIResponder, UIWindowSceneDelegate {


    var window: UIWindow?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.

        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.

        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).


        // Create the SwiftUI view that provides the window contents.

        let contentView = ContentView()


        // Use a UIHostingController as window root view controller.

        if let windowScene = scene as? UIWindowScene {

            let window = UIWindow(windowScene: windowScene)

            window.rootViewController = UIHostingController(rootView: contentView)

            self.window = window





    funcsceneDidDisconnect(_ scene: UIScene) {

        // Called as the scene is being released by the system.

        // This occurs shortly after the scene enters the background, or when its session is discarded.

        // Release any resources associated with this scene that can be re-created the next time the scene connects.

        // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).



    funcsceneDidBecomeActive(_ scene: UIScene) {

        // Called when the scene has moved from an inactive state to an active state.

        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.



    funcsceneWillResignActive(_ scene: UIScene) {

        // Called when the scene will move from an active state to an inactive state.

        // This may occur due to temporary interruptions (ex. an incoming phone call).



    funcsceneWillEnterForeground(_ scene: UIScene) {

        // Called as the scene transitions from the background to the foreground.

        // Use this method to undo the changes made on entering the background.



    funcsceneDidEnterBackground(_ scene: UIScene) {

        // Called as the scene transitions from the foreground to the background.

        // Use this method to save data, release shared resources, and store enough scene-specific state information

        // to restore the scene back to its current state.







Swift | XCode

XCode - Tab Bar View Controller - Add Tab View

by 13. March 2021 11:58

To add an additional tab view:

  1. Add new View Controller to storyboard
  2. CTRL + Drag from the Tab Bar Controller (top left icon) to the new View Controller
  3. Select "View Controller" from the Segue dialog window



XCode Hangs on Startup

by 1. November 2020 15:13

Try deleting this directory:

~/Library/Saved Application State/



Swift IOS UITableViewCell Button

by 5. January 2019 12:40

There are two steps to add a working button to a table view cell. The first step is to add a button like this:

cell.accessoryType = .detailDisclosureButton

The second step is to take action when the button is tapped by creating the accessoryButtonTappedForRowWith method:

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {


XCode | iOS | Swift

xCode Support for IOS Device

by 24. November 2018 06:47

Trying to run xCode against connected iPhone and receive error message below:

Could not locate device support files. This iPhone 6s Plus is running iOS 12.0.1 (16A404), which may not be supported by this version of Xcode.


Download latest xCode from (as .xip file), extract the .app file (

Right click on latest xCode .app and select "Show Package Contents" and navigate to:


Select the required version(s) and copy to:


Look into this path as well: /Users/xxx/Library/Developer/Xcode/iOS DeviceSupport



xCode Facebook Login Integration Using CocoaPods

by 18. November 2018 09:26

Terminal window, navigated to root folder where xCode project exists and run the following commands:

  • $ sudo gem install cocoapods
  • $ pod init

This will create a file named Podfile in your project's root directory. Open the Podfile with a text editor and add the following:

  • pod 'FBSDKLoginKit'

Back in the Terminal window, run the following command:

  • $ pod install 

Register app with Facebook (follow steps in this link:

Configure the information property list file (info.plist) with an XML snippet that contains data about your app. Right-click info.plist, and choose Open As Source Code. Copy and paste the following XML snippet into the body of your file ( ...)


To use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, your application's info.plist also needs to include:


Go to the Project Navigator in Xcode and select your project to see project settings. Select Other Linker Flags for editing. Add the flag -ObjC to Other Linker Flags for all build targets. NOTE: Use the find feature to easily locate the Other Linker Flags in the settins area.

If you still have the xCode project open close it. Open the new Workspace that should have been created in the same root folder as the project (e.g. MyApp.xcodeproj should now have a MyApp.xcworkspace partner).

Update the applications AppDelegate method to include the FBSDKLoginKit import reference and methods with FBSDKApplicationDelegate and FBSDKAppEvents (sample shown below).

import UIKit
import FBSDKLoginKit

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        // FaceBook
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

        // FaceBook
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.


Build Project for Running to make sure everything compiles correctly.



Facebook | XCode

xCode Custom Icons - Tab Bar Item - System Item Custom - Bar Item Image

by 14. October 2017 09:56

The steps below are for creating an app icon fro an xCode/Swift iOS application.  The xCode steps are specifically for setting a custom icon on a tab of a  tabbed application.  

I use Gimp for image editing and follow these steps to create the icon:

  1. Import (or create) the image you want to use as the tab bar icon. NOTE: For importing an existing image it's best to use a black and white image so that you don't have to remove colors. Also, for your starting image it's best to have 75x75 pixel image (or larger) as the large image, then it can easily be scaled down to medium (50x50) and standard (25x25).
  2. Set the background to 'Transparent' rather than white.
  3. Remove all white from the image so that it was just a black image with a transparent background.
  4. Resize the image to be a square with dimensions 75x75 pixels, export/save as .png file format and name imageName@3x.png
  5. Resize the image to be a square with dimensions 50x50 pixels, export/save as .png file format and name imageName@2x.png
  6. Resize the image to be a square with dimensions 25x25 pixels, export/save as .png file format and name imageName.png

In xCode I perform the following steps:

  1. Drag the images into xCode project.
  2. Highlight select the images in xCode project, right-click and select 'New Group from Selection', name the image group iconImageName.
  3. Select the desired tab on the storyboard view.
  4. From the properties, set the 'Tab Bar Item' => 'System Item' = 'Custom'.
  5. From the properties, set the 'Bar Item' => 'Image' = 'imageName.png'
  6. NOTE: Do not set the 'Selected Image' under the 'Tab Bar Item' (leave this blank).