Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

victorynaveen

macrumors newbie
Original poster
Feb 3, 2016
2
0
Help needed in swift language to convert below nsmutable string into nsdictionary.
Code:
//-----------nsmutablestring:

      <INFO>

    <Store>

    <StoreName>Colombian Jeans USA</StoreName>

    <StoreCity>Tamarac</StoreCity>

    <StoreAddress>4638 nw 58 CT</StoreAddress>     

    <StoreState>Florida</StoreState><

    StoreTelephone>(786) 290-5724</StoreTelephone>

    <StoreLocation>Tamarac</StoreLocation>

    </Store>

        <Store>

    <StoreName>Bel Sanchez Photography Inc.</StoreName>

    <StoreCity>Margate</StoreCity>

    <StoreAddress>1799 North State Road 7</StoreAddress>

    <StoreState>Florida</StoreState>

    <StoreTelephone>(954) 856-1494</StoreTelephone>

    <StoreLocation>Margate</StoreLocation>

    </Store>

    <Store>

    <StoreName>Max Computer Doctor</StoreName>

    <StoreCity>Tamarac</StoreCity>

    <StoreAddress>5575 Florida 7</StoreAddress>

    <StoreState>Florida</StoreState>

    <StoreTelephone>(954) 399-4754</StoreTelephone>

  <StoreLocation>Tamarac</StoreLocation>

        </Store>

        </INFO>






Below format of NSDictionary data is required -
Code:
        {

  

        Store =     (

  

                    {

  

        StoreAddress = “4638 nw 58 CT ";

  

                StoreCity = Tamarac;
              
                StoreLocation = Tamarac;

  

                StoreName = "Colombian Jeans USA";

  

                StoreState = Florida;

  

                StoreTelephone = "(786) 290-5724";

  

              },

  

                    {

  

                StoreAddress = "7868 West Sample Road";

  

                StoreCity = Margate;

  

                StoreLocation = Margate;

  

                StoreName = "J.R. Pizza Bella Restaurant";

  

                StoreState = Florida;

  

                StoreTelephone = "(954) 753-1300";

  

                        

  

            },

  

                    {

  

                StoreAddress = "5575 Florida 7";

  

                StoreCity = Tamarac;

  

                StoreLocation = Tamarac;

  

                StoreName = "Max Computer Doctor";

  

                StoreState = Florida;

  

                StoreTelephone = "(954) 399-4754";

  

                          

  

            },

  

                  );

  

        "__name" = INFO;

  

        }
 
Last edited by a moderator:
If at all possible you should prefer JSON to xml/SOAP. Is it possible to get JSON from this server?

If not, I've used a generic XML parser to parse XML from a server that only provided XML. Your XML looks much simpler than the usual SOAP XML so this should work. A generic XML parser will parse most XML into strings, arrays, and dictionaries without any special knowledge of the XML format. The one I've used is this

// XMLReader.m
//
// https://github.com/Insert-Witty-Name/XML-to-NSDictionary
//
// http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/

This parser is in Objective-C but can be used in swift with no difficulties. Here is a swift github project of mine where I used this parser:

https://github.com/phoney/WeatherMan
 
  • Like
Reactions: page404
Thank you so much for your help ! i able to convert that into dictionary using bridge-header file.
 
Thank you so much for your help ! i able to convert that into dictionary using bridge-header file.
That's the fun with swift. You can wrap all those existing Objective-C libraries and use their functions. I fear the day I have to fix something in the Objective-C code though ;)
 
This particular library is one file and not very large. I spent some time trying to port it to swift with great difficulty. The problem is that the code uses mutable containers inside containers and swift containers are structs where assignment is a copy. I assume this can be implemented in some way but I wasn't able to do it (yet).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.