Marcus Ataide
Marcus Ataide

Reputation: 7550

Create a NSString from different class

I have a method that receive from a SOAP method a result as:

SDZPaymentResult* result = (SDZPaymentResult*)value;

If I use: NSLog(@"%@", result);

It shows:

<CXMLElement 0x20d9c950 [0x20dccc40] ns1:paymentResult 
<ns1:paymentResult>
<additionalData xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<authCode xmlns="http://payment.services.adyen.com">76419</authCode>
<dccAmount xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<dccSignature xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<fraudResult xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<issuerUrl xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<md xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<paRequest xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<pspReference xmlns="http://payment.services.adyen.com">8813677969778790</pspReference>
<refusalReason xmlns="http://payment.services.adyen.com" xsi:nil="true"/>
<resultCode xmlns="http://payment.services.adyen.com">Authorised</resultCode>
</ns1:paymentResult>>

Have a way to change result into a NSString?

Upvotes: 2

Views: 113

Answers (3)

Tony
Tony

Reputation: 4591

As @JustSid said, you can use another way:

NSLog(@"%@", result.description);

Your way and this way are the same, so if you want to change "result", you have to change return-value of description method, if you want to change it, you have to be owner of class of "result".

I think you have to inherit class of "result" and you can do anything you want!

Upvotes: 0

JustSid
JustSid

Reputation: 25318

The %@ format specifier calls the description method of the object, which will return the NSString you are looking for. But you might want to rethink your solution, that's not what the description is made for, and if it's not one of your classes, the returned value might change and break your code! Check if there isn't another method to get the data in a more reliable way.

Upvotes: 4

Alex Blundell
Alex Blundell

Reputation: 2104

Use an NSString formatter:

NSString *newString = [NSString stringWithFormat:@"%@", result];

Upvotes: -1

Related Questions