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.)