9

I am new to iOS development and struggling with few build errors. I looked up the web on how to fix these errors but could not get a hint. Using Xcode 9.4 with built in Swift.

  1. 'LaunchOptionsKey' is not a member type of 'UIApplication'
  2. Instance member 'state' cannot be used on type 'UIControl'
  3. Instance member 'state' cannot be used on type 'UIControl'
  4. Type 'UIControl' has no member 'State'

Link is below as I was not allowed to include the screenshot in this post.

Xcode build errors

halfer
  • 19,824
  • 17
  • 99
  • 186

3 Answers3

29

It should be like this :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    return true
}
U. Benlice
  • 901
  • 9
  • 14
  • Thank you, I replaced the code with your recommendation, it worked but needed me to add a boolean return value .. thank you. I am still trying to fix the other errors. I will try to paste the codes here too – Omanex Jeep Adventures Jun 11 '18 at 09:51
  • You can read apple document about this methods requirements. https://developer.apple.com/documentation/uikit/uiapplicationdelegate#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFinishLaunchingWithOptions: – U. Benlice Jun 11 '18 at 10:01
  • Thanks Benlice, indeed I think I need to spend more time reading and understanding the docs, somehow all codings look strange symbols to me :-) hopefully it is a matter of time and efforts to get there ..thanks for the advice – Omanex Jeep Adventures Jun 11 '18 at 10:37
  • Same question here. I fixed the problem using what you showed. However I find it very hard to reconcile this with the fact that `UIApplication.LaunchOptionsKey` is indeed a structure. How does this work? Link: https://developer.apple.com/documentation/uikit/uiapplication/launchoptionskey – user3207158 Sep 27 '18 at 19:56
  • But on Apple's [documentation](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application), it shows the same format of the asker, namely `UIApplication.LaunchOptionsKey`. How are we supposed to know which one is correct? – instanceof Oct 12 '18 at 08:00
5

Neither the original question nor the accepted answer note that the code with the error is generated code when a project is created and as such generally shouldn't need to be changed.

The problem is because of the version of Xcode. UIApplicationLaunchOptionsKey has been renamed to UIApplication.LaunchOptionsKey in the newer version of Xcode (10.2). I came across this when I tried to open my project in an older version of Xcode. This sucks because I now can't work on my project on my older computer that can't be updated to the latest version.

sp_nz
  • 51
  • 1
  • 2
2

I am running Xcode 9.3 and Android Studio 3.5.1.

All I did was remove the "." on the definition:

UIApplication.LaunchOptionsKey: Any

To:

UIApplicationLaunchOptionsKey: Any

without the period. Works like a charm! Enjoy.

Val
  • 101
  • 1
  • 10