New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to parse and extract data #3
Comments
When starting from scratch, then the first step will be defining the root level class without any properties like this:
Then run a base test where you try to parse the XML to that object model with code like this:
If you then run the test again, you can see more fields that you should map. In the output you will now see:
So here you can see that you need an extra property for StateProv. In the output you can also see that it has an attribute for _stateprov_id and _stateprov_name and that it has an array of game elements below that. We will add those to the classes we have. And since we see what should be in the game class, we also will make an initial setup for that:
If you now run the test, then you can see that all values are set. You probably do notice that all dates are put into a string. I did that because the standard date formatter is not right in your case. So you have to find out the correct dateformatter and use that. I tried it with the code below, but that does not work. I have to leave now, so I will let it up to you to fix this :)
You can now find this solution as a unit test in the project. |
You can find the test here: AlamofireXmlToObjects/AlamofireXmlToObjectsTests/AlamofireXmlToObjects3Tests.swift Line 56 in d30d525
|
Thanks so much. This really helps. I'm not able to import XCTest though, so it's throwing a bunch of errors. |
Could you try updating the pod? |
Pod updating works fine. XCTest is showing "cannot import underlying module". I did some Googling and it didn't help. |
Ah, XCTest is part of the Apple unit test framework. I see that you imported the code into your view controller. You could do that, but then you have to remove the import XCTest and change all the XCTAssert* by other checks. And then... Is AlamofireXMLToObjects a dependency for your app (added by cocoapods)? It should automatically import EVReflection, XMLDictionary and Alamofire |
Yes, I have it in my podfile.
|
When i search for the error 'unable to read module map' then I find this solution:
Besides that... Did you open the workspace file instead of the project? |
Tried that and still getting all those errors. It seems like a problem with XCTest. The calls related to that (XCTestCase or XCTAsset) are still showing Unresolved Identifier. |
I do think this is a generic pod issue with your project. You also have the same issue with Objectmapper. When you look at your project tree. Do you also have a Pods project besides your own project? In the screenshot below you se the Pods project with 3 pods. You should also see a couple of other pods like ObjectMapper and AlamofireXMLToObject |
This sounds like it could be your problem: |
Great, |
Ok, now I'm really confused. I don't have an 'import XCTest' and all the XCTAssert statements are from the code you sent earlier. |
Do I need the tests in there to get the XML parsing to work correctly? |
no you don't need it in your actual code, it's just additional code to show in a unit test that the code works. The 'import XCTest' will make the testing framework available. Ale XCAssert statements will do some sort of comparison to validate results. When removing all test related code, you will end up with code like this:
|
:-) The unit test was copied from the AlamofireXMLToObjects project. When using the code from an other project that imports AlamofireXMLToObjects as a pod, then you also have to add an import statement for that. So add the following line to your code:
|
Unfortunately, that didn't clear those errors. |
the expectation.fulfill is a left over from the test.... You can remove that line. The Request.outputDictionary is added in the latest version of AlamofireXMLToObjects. You should run a 'pod update' . Actually now that the object structure is there you could also remove that line. The only thing that line does is print the dictionary that was created from the XML |
That's it! Thank you so much for the help. |
Hi Edwin,
Here's a section of the file I'm trying to parse:
Some sections of my code:
The text was updated successfully, but these errors were encountered: