Some finishing on core data (II.)

Source: Internet
Author: User

Some finishing on core data (II.)

When creating a subclass of Nsmanagedobject, one thing to emphasize in this middle is whether to tick the use scalar properties for primitive data types.

By ticking this option, you are using the original data type that you used when you defined it.

If not checked, there will be a type of conversion, the conversion situation is as follows:

    • string  maps to string
    • integer 16/32/64, Float, Double and boolean map to nsnumber 
    • decimal maps to Nsdecimalnumber
    • date  Maps to NSDate
    • binary data Maps to NSData
    • transformable maps to Anyobject

Then generate four files as follows:

the above two are responsible for the data Attributes section, the following two are responsible for the Data operations SectionIf you modify the core data file in use, re-create the subclass, the newly generated file only two above and overwrite the original file, the following data Operation section is not newthe code needs to be aware of not many places, there are two points below:
    • Add nspredicate condition for nsfetchrequest
1 //create a match request and add a judgment statement2Nsfetchrequest *request = [Nsfetchrequest fetchrequestwithentityname:@"Bowtie"];3NSString *firsttitle = [Self.segmentedcontrol titleforsegmentatindex:0];4Request.predicate = [Nspredicate predicatewithformat:@"Searchkey = =%@", Firsttitle];5Nsarray *results =[Self.managedcontext executefetchrequest:request error:nil];6Self.currentbowtie = Results.firstobject;
    • Save the picture can choose allows External Storage, your database memory is not the picture, but the picture in your folder in the path

1   // working with picture save 2   Nsentitydescription *entity = [nsentitydescription entityforname:@ "Bowtie"  InManagedObjectContext:self.managedContext]; 3   Bowtie *bowtie = [[Bowtie alloc] initwithentity:entity InsertIntoManagedObjectContext:self.managedContext]; 4   Bowtie.photodata = Uiimagepngrepresentation ([UIImage imagenamed:dict[@ "imageName" ]]);

Some finishing on core data (II.)

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.