I'm developing iOS app with Realm library and it works fine.
But when I tried to save one model it throws error like this.
Terminating app due to uncaught exception 'RLMException', reason:
'Target table row index out of range
Here's code.
....
do {
try realm?.write {
let newPatientImage = PatientImage()
newPatientImage.path = imageName
if let flap = flap {
newPatientImage.setStronglyTypedFlap(flap)
}
newPatientImage.hasPhoto = hasPhoto
newPatientImage.flap?.flapLocationRaw = flapLocation.rawValue
newPatientImage.id = newPatientImage.incrementalID()
patient.patientImages.append(newPatientImage)
realm?.add(newPatientImage)
realm?.add(patient, update: true)
}
} catch {
}
...
Here's newPatientImage object.
PatientImage {
id = 22;
hasPhoto = 0;
isPostOp = 0;
path = 4426699712;
date = 2019-04-26 11:32:15 +0000;
flap = RhomboidAFlap {
id = 1;
name = Rhomboid A;
adjustables = List<Adjustable> <0x280b5c120> (
[0] Adjustable {
value = 60;
defaultValue = 60;
name = A;
isDegrees = 1;
},
[1] Adjustable {
value = 60;
defaultValue = 60;
name = B;
isDegrees = 1;
},
[2] Adjustable {
value = 200;
defaultValue = 200;
name = C;
isDegrees = 0;
},
[3] Adjustable {
value = 200;
defaultValue = 200;
name = E;
isDegrees = 0;
}
);
a = 0.6491648060943035;
b = 0;
c = 0;
d = 0.6491648060943035;
tx = -195.6666717529297;
ty = -144.5;
xOffset = -44.99840983089462;
yOffset = 30.7939660691552;
width = 650;
height = 1000;
centerX = 429.5;
centerY = 499.9999999999999;
calibrationSettings = CalibrationSettings {
measurementUnitRaw = px;
conversionRatio = 1;
measuredLength = 0;
startX = 0;
startY = 0;
endX = 0;
endY = 0;
};
flapLocationRaw = ;
};
ohPlastyFlap = (null);
curvelinearFlap = (null);
rhomboidAFlap = RhomboidAFlap {
id = 1;
name = Rhomboid A;
adjustables = List<Adjustable> <0x280b5c120> (
[0] Adjustable {
value = 60;
defaultValue = 60;
name = A;
isDegrees = 1;
},
[1] Adjustable {
value = 60;
defaultValue = 60;
name = B;
isDegrees = 1;
},
[2] Adjustable {
value = 200;
defaultValue = 200;
name = C;
isDegrees = 0;
},
[3] Adjustable {
value = 200;
defaultValue = 200;
name = E;
isDegrees = 0;
}
);
a = 0.6491648060943035;
b = 0;
c = 0;
d = 0.6491648060943035;
tx = -195.6666717529297;
ty = -144.5;
xOffset = -44.99840983089462;
yOffset = 30.7939660691552;
width = 650;
height = 1000;
centerX = 429.5;
centerY = 499.9999999999999;
calibrationSettings = CalibrationSettings {
measurementUnitRaw = px;
conversionRatio = 1;
measuredLength = 0;
startX = 0;
startY = 0;
endX = 0;
endY = 0;
};
flapLocationRaw = ;
};
rhomboidBFlap = (null);
noteFlap = (null);
vyPlastyFlap = (null);
bilobedFlap = (null);
circularZFlap = (null);
atPlastyFlap = (null);
ouPlastyAFlap = (null);
ouPlastyBFlap = (null);
simpleEllipseFlap = (null);
}
And Here's patient object.
Patient {
id = 1;
firstName = Gg;
lastName = ;
email = ;
phone = ;
address1 = ;
address2 = ;
city = ;
state = ;
dateOfBirth = 2019-04-03 21:24:28 +0000;
medicalRedcordNumber = ;
imageUrl = avatar_1;
patientImages = List<PatientImage> <0x2834a5200> (
[0] PatientImage {
id = 1;
hasPhoto = 1;
isPostOp = 0;
path = 4489901936;
date = 2019-04-08 16:21:54 +0000;
flap = (null);
ohPlastyFlap = (null);
curvelinearFlap = (null);
rhomboidAFlap = (null);
rhomboidBFlap = (null);
noteFlap = (null);
vyPlastyFlap = (null);
bilobedFlap = (null);
circularZFlap = (null);
atPlastyFlap = (null);
ouPlastyAFlap = (null);
ouPlastyBFlap = (null);
simpleEllipseFlap = (null);
}
}
Could anyone please help me resolve this issue?
This issue doesn't happen before updating iOS version and Realm version.
Thanks.
You need to manipulate realm in a write transaction like this:
do {
try self.realm.write
{
self.realm.add(entity, update: update)
}
}
catch {}
It was because every Flap classes(like ohPlastyFlap, curvelinearFlap ...) override Flap class and Realm doesn't recognize Flap type.
I fixed it by correctly setting Flap type.
The "patient" object is missing the corresponding initialization, which is still a nil.
Before
patient.patientImages.append(newPatientImage)
try creating for "patient".
Related
please tell me how to unwrap this josn response because of optional json i am not able to parse in label
i have tried my best but i am new to swift so i can't get it to unwrap the optional json
response::
Optional(<__NSArrayM 0x600000848340>(
{
contributors = "";
coordinates = "";
"created_at" = "Thu Jul 12 11:49:57 +0000 2018";
entities = {
hashtags = (
);
media = (
{
"display_url" = "pic.twitter.com/IJtq6aLM7K";
"expanded_url" = "";
id = 1017375504448479232;
"id_str" = 1017375504448479232;
indices = (
12,
35
);
"media_url" = "";
"media_url_https" = "";
sizes = {
large = {
h = 1820;
resize = fit;
w = 2048;
};
medium = {
h = 1067;
resize = fit;
w = 1200;
};
small = {
h = 604;
resize = fit;
w = 680;
};
thumb = {
h = 150;
resize = crop;
w = 150;
};
};
type = photo;
url = "";
}
);
symbols = (
);
urls = (
);
"user_mentions" = (
);
};
"extended_entities" = {
media = (
{
"display_url" = "pic.twitter.com/IJtq6aLM7K";
"expanded_url" = "";
id = 1017375504448479232;
"id_str" = 1017375504448479232;
indices = (
12,
35
);
"media_url" = "";
"media_url_https" = "";
sizes = {
large = {
h = 1820;
resize = fit;
w = 2048;
};
medium = {
h = 1067;
resize = fit;
w = 1200;
};
small = {
h = 604;
resize = fit;
w = 680;
};
thumb = {
h = 150;
resize = crop;
w = 150;
};
};
type = photo;
url = "";
}
);
};
"favorite_count" = 0;
favorited = 0;
geo = "";
id = 1017375507174719488;
"id_str" = 1017375507174719488;
"in_reply_to_screen_name" = "";
"in_reply_to_status_id" = "";
"in_reply_to_status_id_str" = "";
"in_reply_to_user_id" = "";
"in_reply_to_user_id_str" = "";
"is_quote_status" = 0;
lang = fr;
place = "";
"possibly_sensitive" = 0;
"retweet_count" = 0;
retweeted = 0;
source = "";
text = "Tweet Tweet ";
truncated = 0;
user = {
"contributors_enabled" = 0;
"created_at" = "Tue Mar 27 05:14:33 +0000 2018";
"default_profile" = 1;
"default_profile_image" = 0;
description = "";
entities = {
description = {
urls = (
);
};
};
"favourites_count" = 3;
"follow_request_sent" = 0;
"followers_count" = 1;
following = 0;
"friends_count" = 0;
"geo_enabled" = 1;
"has_extended_profile" = 0;
id = 978500498897563648;
"id_str" = 978500498897563648;
"is_translation_enabled" = 0;
"is_translator" = 0;
lang = en;
"listed_count" = 0;
location = "";
name = Mike;
notifications = 0;
"profile_background_color" = F5F8FA;
"profile_background_image_url" = "";
"profile_background_image_url_https" = "";
"profile_background_tile" = 0;
"profile_image_url" = "";
"profile_image_url_https" = "";
"profile_link_color" = 1DA1F2;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = 1;
protected = 0;
"screen_name" = Mike50430315;
"statuses_count" = 13;
"time_zone" = "";
"translator_type" = none;
url = "";
"utc_offset" = "";
verified = 0;
};
}
because of this i am getting nil value in all like name text retweet please tell me how to solve this
var timeline = (FHSTwitterEngine.shared().getTimelineForUser(FHSTwitterEngine.shared().authenticatedUsername, isID: true, count: 10), terminator: "")
from this line i am getting whole response
and then i have on array i create and store in to array like below
var serviceData = [AnyObject]()
let timelinedata = [timeline] as [AnyObject]
serviceData = (timelinedata)
print(serviceData)
In general, anything optional can be unwrapped like so:
let optionalValue: String? = "Hello, this is optional!"
if let noLongerOptional = optionalValue {
print("\(noLongerOptional) no its not! ahah")
}
Edit: more specific example...
Assuming you have a variable 'myJson' which hold your optional value... and you did:
print("\(myJson)")
You can solve this by:
if let validJson = myJson {
print("\(validJson)")
}
Edit 2: ... FHSTwitter... (updated.... this is getting long)
let twitterEngine = FHSTwitterEngine.sharedEngine()
let twitterUser = twitterEngine.authenticatedID
let timeline = twitterEngine.getTimelineForUser(twitterUser, isID: true, count: 10)
According to FHSTwitterEngine docs... getTimelineForUser() will return either a NSError or an array of Tweets.
so...
if let error = timeline as? Error {
print("Oops, looks like something went wrong: \(error)")
} else {
if let tweets = timeline as? [Any] {
for tweet in tweets {
print("This is a tweet: \(tweet)")
}
}
}
If you have any more trouble using FHSTwitterEngine, I suggest you play with: https://github.com/natesymer/FHSTwitterEngine/tree/master/FHSTwitterEngineDemoSwift/Demo-Swift
Or open a support ticket with the FHSTwitterEngine developer(s) at: https://github.com/natesymer/FHSTwitterEngine/issues
Good Luck!
I am getting battery status and others .
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];
int batinfo=(batLeft*100);
NSLog(#"Battry Level is :%d and Battery Status is :%d",batinfo,i);
switch (i)
{
case UIDeviceBatteryStateUnplugged:
{
break;
}
case UIDeviceBatteryStateCharging:
{
break;
}
case UIDeviceBatteryStateFull:
{
break;
}
default:
{
break;
}
}
Now i am trying to get the temperature details is it possible to get the battery temperature from device .
That is not possible and there is no public API to find . but I found the some answers in here May be it helps you , see once. But some private API you can get this details.
sample app you cannot use this if you deploy your app on the Apple Store, but it can be useful when deploying to TestFlight
Brother I gone through the answer for your question and which indicates that you can get and generally it shows the following states
Battery design capacity
Battery current raw capacity (in mAh)
Battery cycle count
Current battery temperature
Current battery voltage
Current battery discharge rate (device power consumption), in mA
Also following shows the results of battery
{
AdapterDetails = {
Amperage = 1000;
Description = "usb host";
FamilyCode = "-536854528";
PMUConfiguration = 1000;
Watts = 5;
};
AdapterInfo = 16384;
Amperage = 1000;
AppleRawCurrentCapacity = 1279;
AppleRawMaxCapacity = 1275;
AtCriticalLevel = 0;
AtWarnLevel = 0;
BatteryData = {
BatterySerialNumber = REDACTED;
ChemID = 355;
CycleCount = 524;
DesignCapacity = 1420;
Flags = 640;
FullAvailableCapacity = 1325;
ManufactureDate = REDACTED;
MaxCapacity = 1273;
MfgData = REDACTED;
QmaxCell0 = 1350;
StateOfCharge = 100;
Voltage = 4194;
};
BatteryInstalled = 1;
BatteryKey = "0003-default";
BootBBCapacity = 52;
BootCapacityEstimate = 2;
BootVoltage = 3518;
CFBundleIdentifier = "com.apple.driver.AppleD1815PMU";
ChargerConfiguration = 990;
CurrentCapacity = 1275;
CycleCount = 524;
DesignCapacity = 1420;
ExternalChargeCapable = 1;
ExternalConnected = 1;
FullyCharged = 1;
IOClass = AppleD1815PMUPowerSource;
IOFunctionParent64000000 = <>;
IOGeneralInterest = "IOCommand is not serializable";
IOInterruptControllers = (
IOInterruptController34000000,
IOInterruptController34000000,
IOInterruptController34000000,
IOInterruptController34000000
);
IOInterruptSpecifiers = (
<03000000>,
<26000000>,
<04000000>,
<24000000>
);
IOMatchCategory = AppleD1815PMUPowerSource;
IOPowerManagement = {
CurrentPowerState = 2;
DevicePowerState = 2;
MaxPowerState = 2;
};
IOProbeScore = 0;
IOProviderClass = AppleD1815PMU;
InstantAmperage = 0;
IsCharging = 0;
Location = 0;
Manufacturer = A;
MaxCapacity = 1275;
Model = "0003-A";
Serial = REDACTED;
Temperature = 2590;
TimeRemaining = 0;
UpdateTime = 1461830702;
Voltage = 4182;
"battery-data" = {
"0003-default" = <...>;
"0004-default" = <...>;
"0005-default" = <...};
"built-in" = 1;
}
Above things are from UIDeviceListener
I run with sample code I got below temparature
in EEPowerInformation.m class I put the breakpoint and check that.It is called and brings all information about battery.
- (void) listenerDataUpdated: (NSNotification *) notification
{
latestPowerDictionary = notification.userInfo;
NSLog(#"The latest Power Dictionary is - %#",latestPowerDictionary);
NSLog(#"The battery Temperature is - %#",[latestPowerDictionary objectForKey:#"Temperature"]);
if (self.delegate != nil)
[self.delegate powerInformationUpdated: self];
}
The Printed Statements are
The latest Power Dictionary is - {
AdapterDetails = {
Amperage = 1000;
Description = "usb host";
FamilyCode = "-536854528";
PMUConfiguration = 970;
Watts = 5;
};
AdapterInfo = 16384;
Amperage = 1000;
AppleChargeRateLimitIndex = 0;
AppleRawBrickIDVoltages = (
(
39,
420
)
);
AppleRawCurrentCapacity = 1084;
AppleRawExternalConnected = 1;
AppleRawMaxCapacity = 1221;
AtCriticalLevel = 0;
AtWarnLevel = 0;
BatteryInstalled = 1;
BatteryKey = "0003-default";
BootBBCapacity = 673;
BootCapacityEstimate = 29;
BootVoltage = 3810;
CFBundleIdentifier = "com.apple.driver.AppleARMPlatform";
ChargerConfiguration = 900;
CurrentCapacity = 1222;
CycleCount = 343;
DesignCapacity = 1430;
ExternalChargeCapable = 1;
ExternalConnected = 1;
FullyCharged = 0;
IOClass = AppleARMPMUCharger;
IOFunctionParent5E000000 = <>;
IOGeneralInterest = "IOCommand is not serializable";
IOMatchCategory = IODefaultMatchCategory;
IONameMatch = charger;
IONameMatched = charger;
IOPowerManagement = {
CapabilityFlags = 32832;
CurrentPowerState = 2;
DevicePowerState = 2;
MaxPowerState = 2;
};
IOProbeScore = 1000;
IOProviderClass = IOService;
InstantAmperage = 198;
IsCharging = 1;
Location = 0;
Manufacturer = A;
MaxCapacity = 1300;
Model = "0003-A";
Temperature = 3120;
TimeRemaining = 67;
UpdateTime = 1470665642;
Voltage = 4188;
"built-in" = 1;
}
Finally the Printed result of battery Temperature is
The battery Temperature is - 3120
if you don't need temperature number then it is useful to use ThermalState api
https://developer.apple.com/documentation/foundation/nsprocessinfothermalstate?language=objc
How can I populate a few UILabels on a ViewController from the JSON object I receive from a previously passed id parameter? I get the response from the server but, I don't know how to populate the key/value pairs to a UILabel.
The JSON response I get is:
{
product = {
attributes = (
);
"average_rating" = "0.00";
backordered = 0;
"backorders_allowed" = 0;
"button_text" = "";
"catalog_visibility" = visible;
categories = (
);
"created_at" = "2016-02-23T05:00:55Z";
"cross_sell_ids" = (
);
description = "<p>Microsoft Office</p>\n";
dimensions = {
height = "";
length = "";
unit = in;
width = "";
};
"download_expiry" = 0;
"download_limit" = 0;
"download_type" = "";
downloadable = 0;
downloads = (
);
featured = 0;
"featured_src" = "https://qashop.taxometry.com/wordpressv4/wp-content/uploads/2016/02/softwarecontract-150x150.jpg";
"grouped_products" = (
);
id = 15;
images = (
{
alt = "";
"created_at" = "2016-02-23T05:01:35Z";
id = 16;
position = 0;
src = "https://qashop.taxometry.com/wordpressv4/wp-content/uploads/2016/02/softwarecontract-150x150.jpg";
title = "softwarecontract-150×150";
"updated_at" = "2016-02-23T05:01:35Z";
}
);
"in_stock" = 1;
"managing_stock" = 0;
"menu_order" = 0;
"on_sale" = 1;
parent = (
);
"parent_id" = 0;
permalink = "https://qashop.taxometry.com/wordpressv4/product/software-contract/";
price = 25;
"price_html" = "<del><span class=\"amount\">$30.00</span></del> <ins><span class=\"amount\">$25.00</span></ins>";
"product_url" = "";
"purchase_note" = "";
purchaseable = 1;
"rating_count" = 0;
"regular_price" = 30;
"related_ids" = (
);
"reviews_allowed" = 1;
"sale_price" = 25;
"shipping_class" = "";
"shipping_class_id" = "<null>";
"shipping_required" = 1;
"shipping_taxable" = 1;
"short_description" = "";
sku = 2370;
"sold_individually" = 0;
status = publish;
"stock_quantity" = "<null>";
tags = (
);
"tax_class" = "";
"tax_status" = taxable;
taxable = 1;
title = "Software Contract";
"total_sales" = 5;
type = simple;
"updated_at" = "2016-02-23T05:01:41Z";
"upsell_ids" = (
);
variations = (
);
virtual = 0;
visible = 1;
weight = "<null>";
};
}
Try this - > First
then Second
I've managed to export the below data, multiplied by several hundred, into an NSDictionary. I now need to build out a way to put this data into Tinder style app. Can anyone advise how I can get my app to pull out the data against Key "Title" for various indexes. Currently it pulls out 45 records of data containing that one Title as there are 45 keys in my data set.
{
AttachmentFiles = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/AttachmentFiles";
};
};
Attachments = 0;
AuthorId = 22;
AverageRating = "<null>";
BestAnswerId = "<null>";
Body = "We need to think xyz";
CategoriesLookupId = 16;
Community = "<null>";
ContentType = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/ContentType";
};
};
ContentTypeId = 0x01200200C5BB1FEE2601B9439CD527C288D85A7B;
Created = "2014-03-21T08:37:33Z";
DescendantLikesCount = 8;
DescendantRatingsCount = "<null>";
DiscussionLastUpdated = "2014-06-19T12:57:58Z";
EditorId = 96;
EmailSender = "<null>";
FieldValuesAsHtml = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FieldValuesAsHtml";
};
};
FieldValuesAsText = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FieldValuesAsText";
};
};
FieldValuesForEdit = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FieldValuesForEdit";
};
};
File = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/File";
};
};
FileSystemObjectType = 1;
FilterCategory = "<null>";
FirstUniqueAncestorSecurableObject = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/FirstUniqueAncestorSecurableObject";
};
};
Folder = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/Folder";
};
};
GUID = "28144fd4-84b0-434b-9e99-01d939e6a773";
Has20likes = "<null>";
ID = 3;
Id = 3;
IsFeatured = 0;
IsIdeaCreated = "<null>";
IsQuestion = 0;
LastReplyById = 49;
LikesCount = 5;
MemberLookupId = 7;
Modified = "2015-03-11T15:25:20Z";
"OData__UIVersionString" = "2.0";
ParentItemEditorId = "<null>";
ParentItemID = "<null>";
ParentList = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/ParentList";
};
};
Popularity = "7.23632608186099";
RatingCount = "<null>";
RoleAssignments = {
"__deferred" = {
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)/RoleAssignments";
};
};
StepChangePillar = "<null>";
Title = "JIRA Governance";
"__metadata" = {
etag = "\"14\"";
id = "Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)";
type = "SP.Data.Community_x0020_DiscussionListItem";
uri = "https://xxxxxxx/_api/Web/Lists(guid'1594ea5e-0ca7-4de3-81aa-4082bde336a4')/Items(3)";
};
},
Thanks
You should have an array of dictionaries correct?
If so this should work:
NSInteger index = 0; //You can set this to the current page of your scroll view
NSArray * items = /* YOUR ARRAY OF DICTIONARIES */;
NSDictionary * dict = [items objectAtIndex:index];
NSString * title = [dict objectForKey:#"Title"];
You might also consider making a subclass of NSObject and building in a parser for your dictionary so you can access the variables with strong types.
I have Json object like this :
{
CO = 1;
CUABR = "<null>";
CUNO = "<null>";
DIV = 2;
DLDAT = 1020923;
SALID = "<null>";
"form_number" = MM23000;
type = VHNO;
},
{
CO = 1;
CUABR = "<null>";
CUNO = "<null>";
DIV = 2;
DLDAT = 1020923;
SALID = "<null>";
"form_number" = MM23001;
type = VHNO;
},
{
CO = 1;
CUABR = "<null>";
CUNO = "<null>";
DIV = 2;
DLDAT = 1020924;
SALID = "<null>";
"form_number" = MM23002;
type = VHNO;
},
{
CO = 1;
CUABR = "\U53f0\U5316\U65b0\U6e2f";
CUNO = FCFC3;
DIV = 2;
DLDAT = 1020924;
SALID = M;
"form_number" = MM23003;
type = VHNO;
}
}
then I need to remove json array content null dictionary key value to sort like this:
{
CO = 1;
CUABR = "\U53f0\U5316\U65b0\U6e2f";
CUNO = FCFC3;
DIV = 2;
DLDAT = 1020924;
SALID = M;
"form_number" = MM23003;
type = VHNO;
}
}
How should I do?
I would like to know the proper way, should I use nest loop or block?
Thanks for helping.
use this may help you..
NSMutableArray *newarray=[NSMutableArray array];
for (NSDictionary *dictionary in parseArrray)
{
if (dictionary[key] != [NSNull null]) {
[newarray addObject:dictionary];
}
}