App and Extension - Use Core data == error : sharedApplication()' is unavailable

后端 未结 3 821
Happy的楠姐
Happy的楠姐 2020-12-20 06:16

I\'m trying to read/write data in extra class file which is public. (StoreData.swift)

My function :

  func FetchName (NameforDate: String) -> NSSt         


        
3条回答
  •  鱼传尺愫
    2020-12-20 06:47

    Your issue:

    StoreData.swift:115:49: 'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.

    Is because -[UIApplication sharedApplication] is not available to extensions. Your extension does not run as part of your application, so there is no application context for an extension to message.

    This is clearly explained in the App Extension Programming Guide section on Understanding How an App Extension Works:

    Because of its focused role in the system, an app extension is ineligible to participate in certain activities. An app extension cannot:

    • Access a sharedApplication object, and so cannot use any of the methods on that object

提交回复
热议问题