my sqlite table structure is :
CREATE TABLE "location" ("latitude" DOUBLE,"longitude" DOUBLE,"date" DATETIME,"locationDescription" VARCHAR,"photopath" VARCHAR,"placemark" BLOB,"wheelId" INTEGER,"wheelSize" DOUBLE,"frontWheelx" DOUBLE,"frontWheely" DOUBLE,"rearWheelx" DOUBLE,"rearWheely" DOUBLE)
and now I want to insert one record into the table, insert column : ( date , photopath , wheelId , wheelSize , frontWheelx , frontWheely , rearWheelx , rearWheely ) and ignore column : (latitude , longitude , locationDescription , placemark)
my code is :
BOOL succeed = [lunGaiDataBase executeUpdate:#"insert into location (date, photopath, wheelid, wheelsize, frontwheelx, frontwheely, rearwheelx, rearwheely) values(?,?,?,?,?,?,?,?)",
location.date,location.photoPath, location.wheelId,location.wheelSize,location.frontWheelx,location.frontWheely,location.rearWheelx,location.rearWheely];
my location class is :
#property (nonatomic, assign) double latitude;
#property (nonatomic, assign) double longitude;
#property (nonatomic, retain) NSDate * date;
#property (nonatomic, retain) NSString * locationDescription;
#property (nonatomic, retain) NSString * photoPath;
//#property (nonatomic, retain) NSString * category;
#property (nonatomic, retain) CLPlacemark * placemark;
#property (nonatomic, assign) NSInteger wheelId;
#property (nonatomic, assign) double frontWheelx;
#property (nonatomic, assign) double frontWheely;
#property (nonatomic, assign) double rearWheelx;
#property (nonatomic, assign) double rearWheely;
#property (nonatomic, assign) double wheelSize;
when I run the program, it crashed !! Help me !!
If i've not mistaken, your crash message would be something like "EXC_BAD_EXCESS" right?
Try this :
BOOL succeed = [lunGaiDataBase executeUpdate:#"insert into location (wheelId) values(?)",
[NSNumber numberWithInt:location.wheelId]];
Since wheelId is declared as NSInteger, you've got to pass it as
[NSNumber numberWithInt:location.wheelId]
Related
Can any one suggest me a m3u8 parser that works on iOS 10. I used this but its giving me errors
M3U8_BASE_URL undecleared indentifier, No visible interface declared
in NSString for isExtendedM3Ufile these kind of errors,, more than 17
in NSString+m3u8.m. I want to pass an m3u8 file to AudioStreamer.
Please help me.
Thanks
According to the screenshot, I copied all the files into one folder and import to the project.
Then m3u8 file URL to the M3U8PlaylistModel
let playlistModel = M3U8PlaylistModel(url: self.m3u8_url)
guard let m3u8PlaylistModel = playlistModel else {
return
}
guard let masterPlaylist = m3u8PlaylistModel.masterPlaylist else {
return
}
guard let streamList = masterPlaylist.xStreamList else {
return
}
streamList.sortByBandwidth(inOrder: .orderedAscending)
for i in 0 ..< streamList.count {
if let extXStreamInf = streamList.xStreamInf(at: i){
/* you can get below properties, using this extXStreamInf object
#property (nonatomic, readonly, assign) NSInteger bandwidth;
#property (nonatomic, readonly, assign) NSInteger programId; // removed by draft 12
#property (nonatomic, readonly, copy) NSArray *codecs;
#property (nonatomic, readonly) MediaResoulution resolution;
#property (nonatomic, readonly, copy) NSString *audio;
#property (nonatomic, readonly, copy) NSString *video;
#property (nonatomic, readonly, copy) NSString *subtitles;
#property (nonatomic, readonly, copy) NSString *closedCaptions;
#property (nonatomic, readonly, copy) NSURL *URI;
*/
}
}
I have the following model and I'm using Realm:
#interface GUIRoutineModel : GUIModel # GUIModel is a subclass of RLMObject
#property (nonatomic, retain) NSString *dateCreated;
#property (nonatomic, retain) NSString *dateModified;
#property (nonatomic, retain) NSString *name;
#property (nonatomic, retain) NSString *type;
#property NSInteger userId;
#property int routineId; #also have same issue using NSInteger
#end
When I call:
// Persist to Realm DB
RLMRealm *realm = [RLMRealm defaultRealm];
[realm transactionWithBlock:^{
[realm addObject:routineModel];
}];
I get the following error:
'Property 'routineId' requires a protocol defining the contained type - example: NSNumber<RLMInt>.'
I have tried changing the routineId property to NSNumber<RLMint>, but that didn't work either. Can anyone tell me what I'm doing wrong?
UPDATE:
Here is another version of the model that I have tried:
#interface GUIRoutineModel : GUIModel
#property (nonatomic, retain) NSString *dateCreated;
#property (nonatomic, retain) NSString *dateModified;
#property (nonatomic, retain) NSString *name;
#property (nonatomic, retain) NSString *type;
#property NSInteger userId;
#property NSNumber<RLMInt> *routineId;
#end
The Property requires a protocol defining the contained type error is only generated by Realm for a property of type NSNumber without a protocol annotating the expected concrete type. That means it cannot be generated for either of the model classes you mention. It's likely you have a another routineId property elsewhere in your app that is triggering the error.
I have a master realm object:
#interface MasterRealmObject : RLMObject
#property (nonatomic, strong) RLMArray<IDNameRealmObject *><IDNameRealmObject> *retailerType;
#property (nonatomic, strong) RLMArray<IDNameRealmObject *><IDNameRealmObject> *firmType;
#property (nonatomic, strong) RLMArray<IDNameRealmObject *><IDNameRealmObject> *businessAge;
#property (nonatomic, strong) RLMArray<StateRealmObject *><StateRealmObject> *state;
#property (nonatomic, strong) RLMArray<KYCDocsRealmObject *><KYCDocsRealmObject> *kycDocs;
#property (nonatomic, strong) RLMArray<ProofRealmObject *><ProofRealmObject> *businessDocs;
#property (nonatomic, strong) NSString *ReligareTollFreeNumber;
#end
I'm trying to store values from a Dictionary as below:
-(void)insertMasterAPIObjects:(NSDictionary *)masterDictionary
{
RLMRealm *realmInsertMasterObjects = [RLMRealm defaultRealm];
[realmInsertMasterObjects beginWriteTransaction];
MasterRealmObject *masterRealm = [[MasterRealmObject alloc]init];
masterRealm.retailerType = [masterDictionary objectForKey:#"retailer_type"];
masterRealm.firmType = [masterDictionary objectForKey:#"firm_type"];
masterRealm.businessAge = [masterDictionary objectForKey:#"BusinessAge"];
masterRealm.kycDocs = [masterDictionary objectForKey:#"kyc_docs"];
masterRealm.businessDocs = [masterDictionary objectForKey:#"business_docs"];
masterRealm.state = [masterDictionary objectForKey:#"states"];
[realmInsertMasterObjects addObject:masterRealm];
[realmInsertMasterObjects commitWriteTransaction];
}
I'm getting this exception here on the first line in this method.
I hit a similar problem because I had omitted the
RLM_ARRAY_TYPE(IDNameRealmObject)
RLM_ARRAY_TYPE(StateRealmObject)
RLM_ARRAY_TYPE(KYCDocsRealmObject)
RLM_ARRAY_TYPE(ProofRealmObject)
macros before my #interface declaration.
I have object
#interface Hourly (CoreDataProperties)
#property (nullable, nonatomic, retain) NSDate *dt;
#property (nullable, nonatomic, retain) NSNumber *temp;
#property (nullable, nonatomic, retain) NSNumber *temp_min;
#property (nullable, nonatomic, retain) NSNumber *temp_max;
#property (nullable, nonatomic, retain) NSNumber *humidity;
#property (nullable, nonatomic, retain) NSNumber *pressure;
#property (nullable, nonatomic, retain) NSString *main;
#property (nullable, nonatomic, retain) NSString *des;
#property (nullable, nonatomic, retain) NSString *icon;
#end
And url
http://api.openweathermap.org/data/2.5/forecast/dayly?lat=35&lon=139&cnt=2
I can' add json to object by jsonmodel pod because weather in list is a array .
#Ngọc Thái:
I don't really understand your question. But, if you want parse from JSON (contain array of objects) to object.
Simple, you can try it: https://github.com/elado/jastor#arrays
Hope this help!
Try my project BWJSONMatcher. It helps you easily convert a json string to NSArray:
NSArray *dataArray = [BWJSONMatcher matchJSON:YOURJSONSTRING withClass:[Hourly class]];
The library is fully opensourced and under MIT license.
I have an iOS application where I am using Core Data for storage. I have two entities ("MyEntity", and "OtherEntity") which are in a one to one relationship. Both entities are related to each other (i.e. each entity has an inverse relationship with the other). In addition to having a relationship with each other, one of the attributes of each entity is also the primarykey of the other entity.
The problem I am having is that I realize that I shouldn't have an attribute that is the foreign key of another entity, when the entities have a relationship with each other, however I am unable to retrieve the primary key indirectly by referencing the relationship attribute, but I am able to retrieve it by referencing the attribute that I explicitly set to the primary key of the other entity:
//NSInteger userId = [testUser.otherEntity.userId integerValue]; --> returns nil
NSInteger userId = [testUser.userId integerValue]; --> works fine
where "testUser" is an instance of type "MyEntity" which is a subclass of NSManagedObject, and "otherEntity" is an instance of the Entity, "OtherEntity" that has an inverse relationship with "MyEntity".
Here are the attributes of each Entity:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#class OtherEntity;
#interface MyEntity : NSManagedObject
#property (nonatomic, strong) NSString * email;
#property (nonatomic, strong) NSNumber * primaryId; //primary key for MyEntity
#property (nonatomic, strong) NSString * metaData;
#property (nonatomic, strong) NSDate * birthDate;
#property (nonatomic, strong) NSString * name;
#property (nonatomic, strong) NSNumber * userId; //this is the primary key for OtherEntity
#property (nonatomic, strong) OtherEntity *otherEntity;
#end
and here are the attributes for OtherEntity:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#class MyEntity;
#interface OtherEntity : NSManagedObject
#property (nonatomic, strong) NSString * address;
#property (nonatomic, strong) NSString * city;
#property (nonatomic, strong) NSString * country;
#property (nonatomic, strong) NSString * fax;
#property (nonatomic, strong) NSString * phone;
#property (nonatomic, strong) NSString * postalCode;
#property (nonatomic, strong) NSString * province;
#property (nonatomic, strong) NSNumber * myUserId//primary key of MyEntity
#property (nonatomic, strong) NSNumber * userId;//primary key of Other Entity
#property (nonatomic, strong) MyEntity *myEntity;
#end
What is it that I'm doing wrong?
(From the comments:) You did not set a relationship for testUser,
Therefore testUser.otherEntity is nil.
Then testUser.otherEntity.userId is also nil and [testUser.otherEntity.userId integerValue] return zero.