ios - Use of undeclared type 'AppDelegate' Swift -


i've spent half day trying solve next problem. testing coredata using swift language. follow this tutorial works fine.

but after titorial i've tried modify structure , code. 'src' , groups inside folders, not groups created xcode.

nssexpense.swift

import foundation import coredata  class nssexpense: nsmanagedobject {      @nsmanaged var name: string     @nsmanaged var descr: string     @nsmanaged var value: nsnumber     @nsmanaged var ismonthly: nsnumber     @nsmanaged var paydayinmonth: nsnumber      class func createinmanagedobjectcontext(moc: nsmanagedobjectcontext, name: string, value: double, paydayinmonth: int16, ismonthly: bool, descr: string!) -> nssexpense {         let newexpense = nsentitydescription.insertnewobjectforentityforname("nssexpense", inmanagedobjectcontext: moc) nssexpense          newexpense.name = name         newexpense.value = nsnumber(double: value)         newexpense.paydayinmonth = nsnumber(short: paydayinmonth)         newexpense.ismonthly = nsnumber(bool: ismonthly)          if let expensedesctiption = descr {             newexpense.descr = expensedesctiption         } else {             newexpense.descr = ""         }          return newexpense     } } 

nssdatamanager.swift

import uikit import coredata  class nssdatamanager: nsobject {      class var shareddatamanager: nssdatamanager {         struct static {             static var instance: nssdatamanager?             static var token: dispatch_once_t = 0         }          dispatch_once(&static.token) {             static.instance = nssdatamanager()         }          return static.instance!     }      lazy var managedobjectcontext : nsmanagedobjectcontext? = {         // error @ next line "use of undeclared type 'nssappdelegate'"         let appdelegate = uiapplication.sharedapplication().delegate nssappdelegate          if let managedobjectcontext = appdelegate.managedobjectcontext {             return managedobjectcontext         } else {             return nil         }     }()      var expensesinmemory : [nssexpense] {         {             let fetchrequest = nsfetchrequest(entityname: "nssexpense")             if let fetchresults = managedobjectcontext!.executefetchrequest(fetchrequest, error: nil) as? [nssexpense] {                 return fetchresults             } else {                 return [nssexpense]()             }         }     }      func addexpensewithname(name: string, value: double, paydayinmonth: int16, ismonthly: bool, descr: string!) -> nssexpense {         return nssexpense.createinmanagedobjectcontext(managedobjectcontext!, name: name, value: value, paydayinmonth: paydayinmonth, ismonthly: ismonthly, descr: descr?)     }  } 

i've tried solve problem different ways: 1) create new project (swift main language) , make same structure again (failed) 2) create new project (objective-c main language). have appdelegate.h , appdelegate.m. add swift files using bridging-header. same problem. (failed)

really interesting next thing. if put next code viewcontroller.swift creates automatically new project works fine. when put code other class. i've code error.

lazy var managedobjectcontext : nsmanagedobjectcontext? = {         // error @ next line "use of undeclared type 'nssappdelegate'"         let appdelegate = uiapplication.sharedapplication().delegate nssappdelegate          if let managedobjectcontext = appdelegate.managedobjectcontext {             return managedobjectcontext         } else {             return nil         }     }() 

[update 1]

i've tried create class right @ same folder nssappdelegate.swift , works fine. it's still issue, how can use classes stored in other folders?


[update 2]

just tried same thing in other project. if file structure this appdelegate.swift , ngdatamanager.swift in same folder works great. but, if put ngdatamanager.swift inside 'src' folder this (not group, folder) error occurs. may should create other question this.


[update 3]

i don't know how, can forget i've said in udate 2. because thats not work. create new project coredata named "test" , create new class named "testclass". magic in next thing: if put code inside testclass.swift

import uikit  class testclass: nsobject {     func somefunc() {         let appdel = uiapplication.sharedapplication().delegate appdelegate     } } 

the error occurs. if put line in viewdidload in viewcontroller.swift generated automatically xcode

import uikit  class viewcontroller: uiviewcontroller {      override func viewdidload() {         super.viewdidload()         let appdel = uiapplication.sharedapplication().delegate appdelegate     } } 

their no error , works great. don't know say...

you may see appdelegate code here didn't modify generated automatically xcode. i've created single view application this settings.

chances when created project created '{projectname}tests' target. problem appdelegate not assigned membership in '{projectname}tests' target.

select appdelegate.swift in right-hand inspector click on file inspector (the paper icon) make sure in "target membership" both project , test target checkmarks set on.

clean, rebuild.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -