Search code examples
iosswiftxcode6-beta6xcode6-beta5

(Swift) Error: UIApplicationMain attribute cannot be used in a module


So, as part of my effort to learn Swift, I got my hands on the open source "Adventure" project (found HERE) made available by Apple.

Embarrassingly, I didn't go too far before I ran into my first predicament. When I tried to compile the project, I got the following error:

'UIApplicationMain' attribute cannot be used in a module that contains top-level code'

Specifically, the error is found in the AppDelegate.swift file and the attribute comes immediately after the import UIKit declaration as follows:

import UIKit

@UIApplicationMain
class AppDelegate: NSObject, UIApplicationDelegate {
    var window: UIWindow?
    ....
    // a number of functions that I won't list here...
    ....
}

I did some research on this but understandably(?) there doesn't seem to be much information regarding this issue. I wonder if anyone has run into the same issue.

(By the way, I am using Xcode6-beta5)

EDIT 1 --------------

Now with a fresh install of Beta6, I get the following errors after compile:

Undefined symbols for architecture x86_64: "TFSs15_arrayForceCastU___FGSaQ__GSaQ0", referenced from: __TFC9Adventure13HeroCharacter20animationDidCompletefS0_FOS_14AnimationStateT_ in HeroCharacter.o __TFC9Adventure13HeroCharacter14fireProjectilefS0_FT_T_ in HeroCharacter.o __TFC9Adventure4Cave15applyCaveDamagefS0_FTSd10projectileCSo6SKNode_T_ in Cave.o __TFC9Adventure4Cave12performDeathfS0_FT_T_ in Cave.o __TFFC9Adventure4Cave16loadSharedAssetsFMS0_FT_T_U_FT_T_ in Cave.o __TFC9Adventure6Goblin20animationDidCompletefS0_FOS_14AnimationStateT_ in Goblin.o __TFFC9Adventure6Goblin16loadSharedAssetsFMS0_FT_T_U_FT_T_ in Goblin.o ... "__TFSsoi1aUSs17_RawOptionSetType_USs21BitwiseOperationsTypeSs9Equatable__FTQ_Q__Q_", referenced from: __TFC9Adventure21LayeredCharacterScene14handleKeyEventfS0_FTCSo7NSEvent7keyDownSb_T_ in LayeredCharacterSceneOSXEvents.o "__TFVSC6CGSizeCfMS_FT5widthSd6heightSd_S_", referenced from: __TFFC9Adventure6Archer16loadSharedAssetsFMS0_FT_T_U_FT_T_ in Archer.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1

I'm not even going to try to guess what these errors mean.


Solution

  • Apparently the Adventure project doesn't compile correctly in Xcode6-Beta5. However, Xcode6-Beta6 compiles and runs it just fine.

    As for the error encountered after upgrading to Beta6, the way to fix that is to delete the derived data for the project. To do that, open the Organizer ("Window" menu -> "Organizer"), select the "Adventure" project on the left side of the window, then click the "Delete" button associated with the project's derived data (should be the top one on the far right).