core data giving merge conflict with single MOC and main thread used for core data - core-data

I'm using core data with a single NSManagedObjectContext and am doing all operation for core data on the main thread. The new and old row given in error description are identical and am at hoping that someone can explain why am getting a merge conflict. Setting merge policy to overwrite is causing the app to run into high CPU in simulator and become unresponsive.
However, when I try to update managed objects in one entity, the app crashes with following error,
NSMergeConflict (0x7144390) for NSManagedObject (0x7225db0) with objectID '0x721c0a0 <x-coredata://94349DC2-C441-4102-9C65-60737E940135/Locations/p1>' with oldVersion = 2 and newVersion = 3 and
old cached row = {\n AccountInfo = \"0x721bae0 <x-coredata://94349DC2-C441-4102-9C65-60737E940135/Account/p1>\";\n City = \"<null>\";\n Country = \"Russian Federation\";\n EntryStatusId = \"<null>\";\n ExitStatusId = \"<null>\";\n IsCorporateLocation = 1;\n IsVisible = 1;\n Latitude = 50;\n LocationId = 10003;\n Longitude = 40;\n Name = \"Test Location\";\n Radius = 304;\n State = \"Province of Voronezh\";\n Street = \"<null>\";\n Units = METER;\n Zip = \"<null>\";\n} and
new database row = {\n AccountInfo = \"0x7144560 <x-coredata://94349DC2-C441-4102-9C65-60737E940135/Account/p1>\";\n City = \"<null>\";\n Country = \"Russian Federation\";\n EntryStatusId = \"<null>\";\n ExitStatusId = \"<null>\";\n IsCorporateLocation = 1;\n IsVisible = 1;\n Latitude = 50;\n LocationId = 10003;\n Longitude = 40;\n Name = \"Test Location\";\n Radius = 304;\n State = \"Province of Voronezh\";\n Street = \"<null>\";\n Units = METER;\n Zip = \"<null>\";\n}
Update: The error doesn't happen if I save the MOC after updating every object but happens if I update all the objects and then save MOC. Anyone knows why this is happening?

The error suggest that you do actually have two separate contexts. You only get a merge when you have two or more context writing to the same store.
I would suggest logging the context before every save, everywhere you perform a save to make certain you only have one active context.

It is posible to let the Core Data deals with this conflicts automatically instead of throw an Exception. See this post: http://pauloliveira.net/tech/core-data-merging-conflicts

Related

How to scrape multiple tables using scrapy?

Hello am trying to scrape through multiple tables from this site https://hs.e-to-china.com and i want to loop through tables and get the needed information.
The problem is it only scrapes the first table and repeats it as many times as there is tables in that page.My question is how can i go from table to the next one.
Here is the code am using:
tables = response.xpath('//*[#class="tax-table"]').extract()
for table in tables:
hs_code = response.xpath('//*[#class="hs-code"]//code/text()').extract_first()
Unit = response.xpath('//*[#class="tax-table"]//tr[1]//td[1]/text()').extract_first()
Gen_General_Tariff_Rate = response.xpath('//*[#class="tax-table"]//tr[1]//td[2]/text()').extract_first()
MFN_Most_favored_Nation = response.xpath('//*[#class="tax-table"]//tr[1]//td[3]/text()').extract_first()
TaxVAT_Value_added_Tax = response.xpath('//*[#class="tax-table"]//tr[2]//td[1]/text()').extract_first()
Additional_Tariff_on_US_Imports = response.xpath('//*[#class="tax-table"]//tr[2]//td[2]/text()').extract_first()
Export_Tax_Rebate = response.xpath('//*[#class="tax-table"]//tr[2]//td[3]/text()').extract_first()
Regulations_and_Restrictions = response.xpath('//*[#class="tax-table"]//tr[3]//td[1]/text()').extract_first()
Inspection_and_Quarantine = response.xpath('//*[#class="tax-table"]//tr[3]//td[2]/text()').extract_first()
Consumption_Tax = response.xpath('//*[#class="tax-table"]//tr[3]//td[3]/text()').extract_first()
FTA_Free_Trade_Agreement_Tax = response.xpath('//*[#class="tax-table"]//tr[4]//td[1]/text()').extract_first()
CCC_Certificate = response.xpath('//*[#class="tax-table"]//tr[4]//td[2]/text()').extract_first()
In_Quota_on_Imported_Goods = response.xpath('//*[#class="tax-table"]//tr[4]//td[3]/text()').extract_first()
IT_Origin_Country_Tariff = response.xpath('//*[#class="tax-table"]//tr[5]//td[1]/text()').extract_first()
Anti_Dumping_Anti_Subsidy = response.xpath('//*[#class="tax-table"]//tr[5]//td[2]/text()').extract_first()
Be carefull when to use een XPath starting with //
This tells the engine to start from root.
If you are in a loop start with .// to use the current context
So instead off
hs_code = response.xpath('//*[#class="hs-code"]//code/text()').extract_first()
Use :
hs_code = response.xpath('.//*[#class="hs-code"]//code/text()').extract_first()

tvOS - Override start time / end time slider AVPlayerViewController

I'm using AVPlayerViewController in order to play an HLS file, however the start time is always 00:00 and the end time is the duration of the event from the HLS manifest.
Instead I would wish to display the start time of the event and the end time of the event.
I found that can be used: AVKitMetadataIdentifierExactStartDate / AVKitMetadataIdentifierExactEndDate
But looks like when I create an AVMutableMetadataItem and I try to assign as identifier the AVKitMetadataIdentifierExactStartDate it doesn't exist. So I'm kind of stuck.
Anyone has any idea?
After few days of researches, I found that this can be achieved creating a AVMutableMetadataItem, assigning them as identifier an AVMetadataIdentifier(AVKitMetadataIdentifierExactStartDate) then as value you can just add the start time as date and cast everything as NSCopying & NSObjectProtocol.
Once you setup both properties you can append to the player.currentItem.externalMetadatas the new metadataItems that you just created as array of metadataItems.
Full example below:
//Add start date
let item = AVMutableMetadataItem()
item.identifier = AVMetadataIdentifier(AVKitMetadataIdentifierExactStartDate)
item.value = startDate as? NSCopying & NSObjectProtocol
let metadataItem = item.copy() as! AVMetadataItem
//Add start date
let endTimeItem = AVMutableMetadataItem()
endTimeItem.identifier = AVMetadataIdentifier(AVKitMetadataIdentifierExactEndDate)
endTimeItem.value = endDate as? NSCopying & NSObjectProtocol
let endTimeMetadataItem = endTimeItem.copy() as! AVMetadataItem
var metadataItems = [AVMetdataItem]()
metadataItems.append(metadataItem)
metadataItems.append(endTimeMetadataItem)
self.player.currentItem?.externalMetadata = metadataItems

"Lot/serial nbr ('anyNumber') can not found in the system", why am i getting this?

"Lot/serial nbr ('anyNumber') can not found in the system", why am i getting this when transfer inventory from a location to another?
1) Transferred inventory from SHIPMENT location/warehouse to another location warehouse.
2) then transferring again from above location warehouse to another warehouse/location. then got error.
INTransferEntry transferGraph = PXGraph.CreateInstance<INTransferEntry>();
INRegister reg = new INRegister();
reg.SiteID = lotDetail.WarehouseID;
reg.ToSiteID = distribution.ToWarehouseID;
reg.TransferType = Order.Current.TranType;
reg.DocType = INDocType.Transfer;
reg.TranDate = DateTime.Now;
reg.TotalQty = distribution.Qty;
reg = transferGraph.transfer.Insert(reg);
INTran tran = new INTran();
tran.INTransitQty = distribution.Qty;
tran.InventoryID = Order.Current.InventoryID;
tran.ToLocationID = distribution.ToLocationID;
tran.ToSiteID = distribution.ToWarehouseID;
tran.TranType = INTranType.Transfer;
tran.InvtMult = INTranType.InvtMult(tran.TranType);
tran.Qty = distribution.Qty;
tran.ReasonCode = distribution.ReasonCode;
tran.SiteID = lotDetail.WarehouseID;
tran.LocationID = lotDetail.LocationID;
tran.TranDesc = distribution.Description;
tran.LotSerialNbr = lotDetail.LotSerNumVal;
tran = transferGraph.transactions.Insert(tran);
You need to look at the INTranSplit DAC, it links the Lot Tracking with the INTran DAC to manage the existing Lots linked to the INItem

Adding new element to Array - Swift 3

I have a Tableviewcontroller BeamsNameVC with 2 variables: Name and number.
If for example, the number is 7, and if I click on any row in this View controller, it will segue to another TableViewcontroller SpansListVC and than it will show 7 rows: S1, S2, S3, S4, S5, S6 & S7.
I want to save these Data, so I created 2 swift files:
class StructureElement: NSObject, NSCoding {
var name = ""
var nbrSpans = ""
var spans = [LoadDetailsForEachSpan]()
and
class LoadDetailsForEachSpan: NSObject, NSCoding {
var i_SpanName = ""
var i_Spanlength = ""
var i_ConcentratedLoadForEachSpans = [ConcentratedLoadForEachSpan]()
I created a protocol with the following:
let spanNbr = Int(structureElement[newRowIndex].nbrSpans)
let newElementDetailSpan = LoadDetailsForEachSpan()
for i in 0...spanNbr! {
newElementDetailSpan.i_SpanName = "S" + " \(i)"
structureElement[newRowIndex].spans.append(newElementDetailSpan)
}
If i run the application, it will segue to * SpansListVC* but all values are the last i.
Example:
if name is Test 7 and number of span is 7, I will be having inside *[Spans] * 7 values with the same name:
spans[0] = S 7
spans[1] = S 7
....
Any mistake with above code?
Welcome to the hell that mutable data objects can be ;). You are creating a single LoadDetailsForEachSpan instance and add that same instance a number of times to the array, while setting the i_SpanName property of that same instance every time the loop is iterated. You probably want to pull the instance creation into the loop:
for i in 0...spanNbr! {
let newElementDetailSpan = LoadDetailsForEachSpan()
newElementDetailSpan.i_SpanName = "S" + " \(i)"
structureElement[newRowIndex].spans.append(newElementDetailSpan)
}
Thanks #thm for your reply.
however, i find another solution as follow and it works:
var spanDetailAndLoadItem: [SpanDetailsAndLoads] = []
for var i in 1...nbr! {
let item = SpanDetailsAndLoads(name: "S\(i) - S\(i + 1)")
spanDetailAndLoadItem.append(item)
}
self.spans = spanDetailAndLoadItem

How to give data dynamically in a dialog box using visual c++

How can I send data to a dialog box dynamically?
In a previous project I used edit boxes (e.g for 3 conductors) and gave those data separately for each conductor. Now I have to give them dynamically and I don't have standard number of conductors and I can't use edit box again.
Could you please give me an idea or a good link describing step by step how to create a table in a dialog box dynamically?
I have created a dialog box in which I insert data about conductors (resistivity, permeability, diameter etc (electric power systems Smile | :) )) in edit boxes but I have done it only for 3 conductors. I have to insert-edit the number of conductors and then edit their characteristics. But I can't use again edit boxes because this is static. I want something like a dynamic table which will have rows=number of conductors and columns about is characteristic (resistivity, permeability, diameter)and edit them in dialog box. I don't know how to upload my executable to male clear what I have done but here is a part of my code for the static case of three conductors Smile | :) I want another dynamic way to edit data :/
void CInputView::OnLinefeaturesFeatures()
{
// TODO: Add your command handler code here
CInputDoc* pDoc = GetDocument();
CFeaturesDialog DialogWindow;
DialogWindow.m_DialogCon = m_NumCond;
DialogWindow.m_DialogLayers = m_Layers;
DialogWindow.m_DialogPermeability = m_AirPermeability;
DialogWindow.m_DialogAirConductivity = m_AirConductivity;
DialogWindow.m_DialogAirPermittivity = m_AirPermittivity;
DialogWindow.m_DialogEarthPermeability1 = m_EarthPermeability1;
DialogWindow.m_DialogEarthConductivity1 = m_EarthConductivity1;
DialogWindow.m_DialogEarthPermittivity1 = m_EarthPermittivity;
DialogWindow.m_DialogDepth = m_depth;
DialogWindow.m_DialogEarthPermeability2 = m_EarthPermeability2;
DialogWindow.m_DialogEarthConductivity2 = m_EarthConductivity2;
DialogWindow.m_DialogEarthPermittivity2 = m_EarthPermittivity2;
DialogWindow.m_Dialogfrequency = m_frequency;
if (DialogWindow.DoModal() == IDOK)
{
m_NumCond = DialogWindow.m_DialogCon;
m_Layers = DialogWindow.m_DialogLayers;
m_AirPermeability = DialogWindow.m_DialogPermeability;
m_AirConductivity = DialogWindow.m_DialogAirConductivity;
m_AirPermittivity = DialogWindow.m_DialogAirPermittivity;
m_EarthPermeability1 = DialogWindow.m_DialogEarthPermeability1;
m_EarthConductivity1 = DialogWindow.m_DialogEarthConductivity1;
m_EarthPermittivity = DialogWindow.m_DialogEarthPermittivity1;
m_depth = DialogWindow.m_DialogDepth;
m_EarthPermeability2 = DialogWindow.m_DialogEarthPermeability2;
m_EarthConductivity2 = DialogWindow.m_DialogEarthConductivity2;
m_EarthPermittivity2 = DialogWindow.m_DialogEarthPermittivity2;
m_frequency = DialogWindow.m_Dialogfrequency;
}
}

Resources