How to reach NSDictionary properties that have a class? - properties

I've created an NSMutableArray with a class "Adealer" for it's objects. In my "listVC" I populate all the properties (as shown below) within a loop, where the "Adealer" class is used to create objects.
I then transferred one object from that array via a segue to my "detailsVC". Here I first import Adealer class and when I call this in my "detailsVC";
NSLog(#"restGPSTransfer (NSDictionary) class = %#, content is = %#",[restGPSTransfer class],[restGPSTransfer description]);
I get this;
restGPSTransfer (NSDictionary) class = Adealer, content is =
theDealer object and it's properties:
dealerID = 7
dealerName = Uppsala Centrum Test
dealerAdressStreet = Dragarbrunnsgatan 55
dealerAdressZip = 75320
dealerAdressCity = Uppsala
dealerTel =
dealerMail =
dealerWeb = www.uppsala.se
dealerLogo =
dealerImages =
dealerText = Uppsala centrum
dealerProducts =
dealerLongitude = 17.63893
dealerLatitude = 59.85856
dealerDistance = (null) // This is ok
dealerDistance2 = 8586398.000000
So far so god, BUT I can't reach the above properties in a simple call like this in the "detailsVC" (?!);
self.labelRestName.text = [restGPSTransfer objectForKey:#"dealerName"];
...it crashes with the error: "-[Adealer objectForKey:]: unrecognized selector sent to instance 0x8a92db0" (then termination with InvalidArgumentExeption...)
What have I missed?
Much more detail can be found in my question here (which I still got no answers to!);
How do I get out data from my NSDirectory (not just a property typo)?
Thank's for any help :-)

It looks like memory issue,
Are you using ARC?
Could you add your dictionary allocation code?

Related

Trying to get property 'path' of non-object

Hello I am having the above error in production but all works well in development. I am using the code bellow to get the path to the main image for the property but it defaults into the else despite the if not being false plus the else does not find the paths even when dump shows that the object has been returned
//check if there are hotels in the selected destination
if($hotels->isNotEmpty()){
//Loop through the hotels
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where(['p_id'=>$hotel->id])->where(['is_main'=>1])->first();
$altbanner = Photo::where(['p_id'=>$hotel->id])->first();
$banner_path = "";
$altText = "";
if($banner!=null){
$banner_path = $banner->path;
$altText = $banner->alt_text;
}else{
$banner_path = $altbanner->path;
$altText = $altbanner->alt_text;
}
Have you checked your database if each hotel has an image? Based on your question and explanation, there is a part of the for each that returns null for the image hence the if part fails and the else return the error. If that is the case then you may want to check and sort it by uploading the image or modifying your checks to handle cases where no image is found.
I think the way you are using the where clause isn't right
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where('p_id',$hotel->id)->where('is_main',1)->first();
$altbanner = Photo::where('p_id',$hotel->id)->first();
// .....
if($banner){
$banner_path = $banner->path;
// ......

Using mogenerator with Core Data entities results in error saving the data store

I have an iPad app that I use MagicalRecord to save the Core Data entities in a SQLite d/b. Everything was working fine until I decided to use FTASync to sync the Core Data with Parse.com.
Part of the requirements of FTASync are that you have to use mogenerator to generate the entity class files. Now, I'm getting this error:
2013-12-14 12:38:59.375 foo[5451:70b] Failed to save to data store: The operation couldn’t be completed. (Cocoa error 1560.)
2013-12-14 12:38:59.380 foo[5451:70b] DetailedError: {
NSLocalizedDescription = "The operation couldn\U2019t be completed. (Cocoa error 1570.)";
NSValidationErrorKey = objectId;
NSValidationErrorObject = "<PreferenceData: 0x1149c3a0> (entity: PreferenceData; id: 0x114a7eb0 <x-coredata://03C39CC9-AC6C-4E56-BB5A-67038ACB6801/PreferenceData/p25> ; data: {\n aAddlSvcs1 = \"\";\n aAddlSvcs10 = \"\";\n aAddlSvcs11 = \"\";\n aAddlSvcs12 = \"\";\n aAddlSvcs2 = \"\";\n aAddlSvcs3 = \"\";\n aAddlSvcs4 = \"\";\n aAddlSvcs5 = \"\";\n aAddlSvcs6 = \"\";\n aAddlSvcs7 = \"\";\n aAddlSvcs8 = \"\";\n aAddlSvcs9 = \"\";\n aApptInterval = \"\";\n aDeleteOldAppts = \"-1\";\n aDoubleBooking = \"-1\";\n aHideHelpBtns = 0;\n aHourFormat12 = 0;\n aShopCloses = 1200;\n aShopOpens = 1000;\n createdHere = 1;\n deleted = 0;\n objectId = nil;\n syncStatus = 2;\n updatedAt = nil;\n})";
}
If I want to sync my Core Data store using FTASync, I have to use mogenerator.
So, what exactly is this telling me, other than "it couldn't be completed"? How do I fix this?
UPDATED:
This is an image from the XCode Data Model Inspector
You have defined some validation rules in the xcdatamodel with the model editor: minimum/maximum values, required relationship, min/max string length.
When you insert objects via a GUI, you'll see immediate feedback when you try to create an object that fails validation. But if you create or modify an object in code, you won't see an error unless you try to save the Managed Object Context.
You can invoke -validateForUpdate: (or -validateForInsert: or -validateForDelete:) within the code that's creating your PreferenceData instance. Invoke it multiple times as you build the object, and you'll see where you're going wrong.

NSManaged object sometimes is null and causes crash

I am using coredata and often my app crashes because one of the properties of a managed object turn out null. For example when i set text of a UILabel to a text property of the managed object it displays NULL
To find the problem I overrode the setter which assigns the NSManagedObject to a instance variable. In the setter I use NSLog to print the object:
NSLog(#"TSC: setting segment: %#", segment);
its output:
2012-11-05 21:01:56.758 JetLagged[4505:907] TSC: setting segment: <Segment: 0x1d0ab790> (entity: Segment; id: 0x1d0a7f60 <x-coredata://BF6F2D98-0658-4005-8BEF-9FE6B398AF86/Segment/p8> ; data: {
arrivalDate = "2012-11-11 05:00:17 +0000";
arrivalLeg = "0x1d0abba0 <x-coredata://BF6F2D98-0658-4005-8BEF-9FE6B398AF86/IteneryLeg/p11>";
departureDate = "2012-11-10 19:00:17 +0000";
departureLeg = "0x1d0abba0 <x-coredata://BF6F2D98-0658-4005-8BEF-9FE6B398AF86/IteneryLeg/p11>";
iteneryLegs = (
"0x1d0abba0 <x-coredata://BF6F2D98-0658-4005-8BEF-9FE6B398AF86/IteneryLeg/p11>"
);
trip = "0x1c58add0 <x-coredata://BF6F2D98-0658-4005-8BEF-9FE6B398AF86/Trip/p5>";
})
All looks fine, however app still displayes null in some places or crashes. I catch the problem I added some NSAsserts and when I ran the code below in the same run as the output above it failed the assertion. Here is the assert code (segmentToCheck is segment from above).
NSSet *legs = [segmentToCheck valueForKey:#"iteneryLegs"];
NSAssert([legs count] != 0, #"Error: nolegs %#", legs);
its output:
2012-11-05 21:01:56.763 JetLagged[4505:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: nolegs (null)'
When i run the app again (without any data modification) it works fine. Any idea what it might be?
Looks like a typo: #"itineryLegs" instead of #"iteneryLegs".

How to add extra data to a member in MDS?

I'm running MDS on a virtual machine and trying to access the service from my host OS.
I've been able to add something to the database but my data is all over the place and in the Master Data Manager (website) I don't see the new member.
I suppose I shouldn't be using Attributes but something else but what and how? Are there tutorials because I can't find any ...?
Here's the code I'm using:
International international = new International();
EntityMembers entityMembers = new EntityMembers();
// Set the modelId, versionId, and entityId.
entityMembers.ModelId = new Identifier { Name = modelName };
entityMembers.VersionId = new Identifier { Name = versionName };
entityMembers.EntityId = new Identifier { Name = entityName };
entityMembers.MemberType = memberType;
Collection<Member> members = new Collection<Member>();
Member aNewMember = new Member();
aNewMember.MemberId = new MemberIdentifier() { Name = employee.FullName, Code = aNewCode, MemberType = memberType };
Collection<MDS.Attribute> attributes = new Collection<MDS.Attribute>();
MDS.Attribute attrOrgUnit = new MDS.Attribute();
attrOrgUnit.Identifier = new Identifier() { Name = "OrganizationalUnit" };
attrOrgUnit.Value = employee.OrganizationalUnit;
attrOrgUnit.Type = AttributeValueType.String;
attributes.Add(attrOrgUnit);
aNewMember.Attributes = attributes.ToArray();
members.Add(aNewMember);
entityMembers.Members = members.ToArray();
// Create a new entity member
OperationResult operationResult = new OperationResult();
clientProxy.EntityMembersCreate(international, entityMembers, false, out operationResult);
HandleOperationErrors(operationResult);
I have been able to fix my own problem.
First of all: creating separate variables with collections and converting them to arrays afterwards is not necessary. The code from the tutorials works but fails to mention that, when adding the service reference, you have to configure it (right-click on the service reference -> configure) to use Collections as "Collection type" instead of arrays and to generate message contracts.
Second, the code above with the attributes is correct and works perfectly. The problem I had which failed to add messages with attributes was unrelated. It was a connection/authentication problem between my Host OS and Guest OS.
Hope this helps someone.

Hard time debugging Local Variable in XCode

I'm having a hard-time debugging a local variable. I'm running gcc 4.2, XCode 3.2.4, base SDK Mac OS 10.5, and Objective-C++ in Debug-Mode.
Here's the issue. I'm working on trying to understand some code and it goes like this:
#define MAX4D 500
...
NSMutableArray *viewerPix[ MAX4D ];
When I hover over it during debug (pause on the line before and after) I get this
Unable to access variable "viewerPix"
Unable to access variable "viewerPix"
Unable to access variable "viewerPix"
...
repeated until I kill the application. What would cause this? I've tried setting it to a lower number... but to no avail. Even after I actually set the C-Array:
viewerPix[0] = [[NSMutableArray alloc] initWithCapacity:0];
I still get the same repeated error message.
However, if I don't mouse-over the value (or debug) it "appears" to run fine, even doing stuff like:
[viewerPix[0] addObject: dcmPix];
if( [viewerPix[0] count] != [loadList count])...
but if I debug after those steps, it crashes just like before. Here are my build settings:
STRIPFLAGS =
ALTERNATE_GROUP = $(INSTALL_GROUP)
ALTERNATE_OWNER = $(INSTALL_OWNER)
ALTERNATE_MODE = $(INSTALL_MODE_FLAG)
ALTERNATE_PERMISSIONS_FILES =
DEPLOYMENT_LOCATION = NO
DEPLOYMENT_POSTPROCESSING = NO
INSTALL_GROUP = $(GROUP)
INSTALL_OWNER = $(USER)
INSTALL_MODE_FLAG = u+w,go-w,a+rX
DSTROOT = /tmp/$(PROJECT_NAME).dst
INSTALL_PATH = $(HOME)/Applications
SKIP_INSTALL = NO
COPY_PHASE_STRIP = NO
STRIP_INSTALLED_PRODUCT =
STRIP_STYLE = debugging
SEPARATE_STRIP = NO
GCC_FAST_OBJC_DISPATCH = YES
GCC_AUTO_VECTORIZATION = NO
GCC_OBJC_CALL_CXX_CDTORS = YES
GCC_ENABLE_SSE3_EXTENSIONS = NO
GCC_ENABLE_SSE41_EXTENSIONS = NO
GCC_ENABLE_SSE42_EXTENSIONS = NO
GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS = NO
GCC_STRICT_ALIASING = NO
GCC_FEEDBACK_DIRECTED_OPTIMIZATION = Off
GCC_ENABLE_FIX_AND_CONTINUE = NO
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
GCC_DYNAMIC_NO_PIC = NO
GCC_GENERATE_TEST_COVERAGE_FILES = NO
GCC_INLINES_ARE_PRIVATE_EXTERN = YES
GCC_MODEL_TUNING = G5
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO
GCC_ENABLE_KERNEL_DEVELOPMENT = NO
GCC_DEBUGGING_SYMBOLS = default
GCC_REUSE_STRINGS = YES
GCC_NO_COMMON_BLOCKS = NO
GCC_ENABLE_OBJC_GC = unsupported
GCC_OPTIMIZATION_LEVEL = 0
GCC_FAST_MATH = NO
GCC_ENABLE_SYMBOL_SEPARATION = YES
GCC_THREADSAFE_STATICS = YES
GCC_SYMBOLS_PRIVATE_EXTERN = NO
GCC_UNROLL_LOOPS = NO
GCC_MODEL_PPC64 = NO
I don't know what else to say. Let me know what more information is needed, because I'm at a loss. There's also no 'build' tab when I get-info on the .mm file. Just General, Target, Comments (some helps I checked said to remove file-specific tags).
Should I initialize that c-array to nil? I can't just do.. array[500] = {nil}; right? that's C#?
I was using LLVM and Clang 1.5, but I switched to GCC 4.2 since I wasn't getting any local symbols. Am I missing something??
If the optimizer is on, that can effectively eliminate local variables.
However, why a C array of mutable ObjC arrays? That seems odd.
check Product->Scheme->Edit Scheme->Run xxx, Build Configuration is Debug, if that is Release happened you see.