Swift ERROR-A class not found solution appears for swift development CoreData

Source: Internet
Author: User

Reprinted from http://blog.csdn.net/longhai0long/article/details/38379247

Just looking at Swift developing iOS, there was a problem with the core data framework, and the console typed the log as follows:

class ' collectnews '  for ' collectnews '.  using default Nsmanagedobject instead.

Baffled, and later found a solution on the StackOverflow, is in the Model class switch plus this note:

Demo part of the code to share to everyone, only to do the reference:
Model class

Import Foundation    Import CoreData  
@objc (collectnews)     class collectnews:nsmanagedobject {          @NSManaged var date:nsnumber        @NSManaged var newsid:nsnumber    

Appdelegate class:

Func application (application:uiapplication!, Didfinishlaunchingwithoptions launchoptions:nsdictionary!)Bool {insertdata () Selectdata ()return true    }        //Inserting Datafunc InsertData () {//take entity Objectvar collectnews = Nsentitydescription.insertnewobjectforentityforname ("collectnews", InManagedObjectContext:self.managedObjectContext) ascollectnews//to modify a propertyCollectnews.newsid = Acollectnews.date=20140805            //Save    ifself.managedobjectcontext.haschanges{Self.managedObjectContext.save (Nil)}}//Enquiryfunc selectdata () {//The request object.var request =nsfetchrequest () var entityqueue= Nsentitydescription.entityforname ("collectnews", InManagedObjectContext:self.managedObjectContext) request.entity=entityqueue var errorinfo:nserror?//Fetch result setvar Resultarr = self.managedObjectContext.executeFetchRequest (Request, error: &errorinfo) asNsarray println ("----"\ (resultarr.count)") var temp= resultarr[0] ascollectnews println ("--->\ (temp.newsid)")    } 

Swift ERROR-A class not found solution appears for swift development CoreData

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.