Skip to content

Methods setting values

Danilo edited this page Jun 7, 2020 · 2 revisions

Overview

List and types of methods available in the framework to set the values ​​to be post to the service.

Methods

Method name Type
setDoubleValue double
setFloatValue float
setImage UIImage
setIntegerValue NSInteger
setLongValue long
setValue NSObject

Remarks

All methods require as input, in addition to the value, the name of the html tag for that value:

[soap setDoubleValue:0 forKey:"tag-name"];

The setValue method accepts as input any type of value, even complex objects such as NSDictionary or NSSet, or custom objects derived from NSObject:

@interface MyObject: NSObject {
	@property (strong) NSString* value;
	@property (string) NSDictionary* dict;
}

MyObject object = [[MyObject alloc] init];
object.value = "123";

[soap setValue:object forKey:"tag-name"];

The setValue method also has more extensive parameters for defining attributes and sub-keys. An example to generate an html tag called text with value ABCD and that has an attribute xmlns with value http://tempuri.org:

NSDictionary *attr = @{"xmlns" : "http://tempuri.org"};
[soap setValue:"ABCD" forKey:"text" attributes:attr];

this will generate an xml similar to this below:

<text xmlns="http://tempuri.org">ABCD</text>

instead for a subkey:

[soap setValue:"ABCD" forKey:"text" subKeyName:"value"];

this will generate an xml similar to this below:

<text><value>ABCD</value></text>

here is a more complex example:

NSArray *param3 = @[
    @{@"description": @"i am a description"},
    @{@"name": @"i am a name"},
    @{@"subdata": @{
              @"name": @"i am a name too",
              @"profession": @"worker"
              }
      },
    @{@"subdata": @{
              @"name": @"just another name",
              @"profession": @"worker"
              }
      }
    ];

[soap setValue:param3 forKey:@"param3"];

this will generate an xml similar to this below:

<param3>
  <description>i am a description</description>
  <name>i am a name</name>
  <subdata>
    <name>i am a name too</name>
    <profession>worker</profession>
  </subdata>
  <subdata>
    <name>just another name</name>
    <profession>worker</profession>
  </subdata>
</param3>