How to implement main.swift in an iOS Xcode 6 application?

in my ios (swift) application, I created main.swift in which I set the global variable by checking NSDefault to check for the deletion of ads.

then in each view manager, I first check this global variable and remove ads, if necessary, before showing the view.

the problem is that xcode doesn't like @UIApplicationMain in AppDelegate.swift because I have main.swift. If I delete the @UIApplicationMain line, the application will crash on startup.

Am I doing main.swift incorrectly?

+4
source share
4 answers

Your main.swift file should look something like this:

import Foundation
import UIKit

// Your initialization code here

UIApplicationMain(C_ARGC, C_ARGV, nil, NSStringFromClass(AppDelegate))

UIApplicationMain .

C_ARGC C_ARGV - Swift-, C, main, int argc char *argv[].

2016-01-02: C_ARGC C_ARGV Process.argc Process.unsafeArgv . []

+9

Swift? Darrarski...

Swift 3:

//
//  main.swift
//

import Foundation
import UIKit

// very first statement after load.. the current time
let WaysStartTime = CFAbsoluteTimeGetCurrent()

// build the parameters for the call to UIApplicationMain()
let argc = CommandLine.argc
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))

// start the main loop
UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.self))

"@UIApplicationMain" AppDelegate.swift, .

+4

Swift 1.2:

UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(AppDelegate))

+3

Here's what it should look like main.swiftin Swift 5

Hardy_Germany's answer gives a warning in Xcode 10.2.

//
//  main.swift
//  TopLevelCode
//
//  Created by Stoyan Stoyanov on 04/04/2019.
//  Copyright © 2019 Stoyan Stoyanov. All rights reserved.
//

import UIKit
import Foundation

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self))
0
source

All Articles