NWSimpleObject

public class NWSimpleObject : NSObject, NSCoding

A simple aggregate of key:value, not nested, used mainly in Analytic events.

Important

The value types a simple Object can carry are limited to String, Int, Float, Double, Bool, Null

Attention

There are limits to the memory that a Simple Object can occupy. Moreover Strings value cannot be more than 512 characters each.
  • Undocumented

    Declaration

    Swift

    public static let MAX_STR_LENGTH: Int
  • Undocumented

    Declaration

    Swift

    public static let MAX_SO_SIZE: Int
  • JSON String representing the SimpleObject

    Declaration

    Swift

    public override var description: String { get }
  • Create a Simple Object from a Dictionary

    Example of creation:

        var dict: [String: Any] = [
           "aString": "bar",
           "aNumber": 10,
           "aFloat": Float(4.79),
           "aDouble": 99.171829398254932,
           "aBool": true,
           "aNull": NSNull()]
        let so = NWSimpleObject(fromDictionary: dict)
    

    Attention

    If a string value is longer than MAX_STR_LENGTH it will be truncated

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes initialization will fail

    Declaration

    Swift

    public init?(fromDictionary dict: [String : Any])

    Parameters

    fromDictionary

    The dictionary

  • Create a Simple Object from a JSON String

    Example of creation:

            let json = "{\"aString\": \"bar\", \"aNumber\": 10, \"aFloat\": 4.3, \"aDouble\": 99.171829398254932, \"aBool\": true, \"aNull\": null}"
            let so = NWSimpleObject(fromJSONString: json)
    

    Note

    When creating a Simple Object with a Float or a Double value inside pay attention to cast it to the appropriate type. If you’re not sure cast it to Double values.

    Attention

    If a string value is longer than MAX_STR_LENGTH it will be truncated

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes initialization will fail

    Declaration

    Swift

    public convenience init?(fromJSONString jsonStr: String)

    Parameters

    fromDictionary

    The dictionary

  • JSON String representing the SimpleObject

    Throws

    SimpleObjectSerializationError in case Serialization fails

    Declaration

    Swift

    public func toJSONString() throws -> String

    Return Value

    the String

  • Deserialization initializer

    Declaration

    Swift

    public required convenience init?(coder aDecoder: NSCoder)
  • Serialization of SimpleObject

    Declaration

    Swift

    public func encode(with aCoder: NSCoder)

    Parameters

    aCoder

    the serializer

  • Set a String value inside the Simple Object

    Attention

    If the string is longer than MAX_STR_LENGTH it will be truncated

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes an exception will be thrown

    Throws

    SimpleObjectCreationError in case the constraints are not met

    Declaration

    Swift

    public func setString(key: String, value: String) throws

    Parameters

    key

    the key name

    value

    the String value. Constraint are max 512 char

  • Set a Int value inside the Simple Object

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes an exception will be thrown

    Throws

    SimpleObjectCreationError in case the constraints are not met

    Declaration

    Swift

    public func setInt(key: String, value: Int) throws

    Parameters

    key

    the key name

    value

    the Int value

  • Set a Float value inside the Simple Object

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes an exception will be thrown

    Throws

    SimpleObjectCreationError in case the constraints are not met

    Declaration

    Swift

    public func setFloat(key: String, value: Float) throws

    Parameters

    key

    the key name

    value

    the Float value

  • Set a Double value inside the Simple Object

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes an exception will be thrown

    Throws

    SimpleObjectCreationError in case the constraints are not met

    Declaration

    Swift

    public func setDouble(key: String, value: Double) throws

    Parameters

    key

    the key name

    value

    the Double value

  • Set a Bool value inside the Simple Object

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes an exception will be thrown

    Throws

    SimpleObjectCreationError in case the constraints are not met

    Declaration

    Swift

    public func setBool(key: String, value: Bool) throws

    Parameters

    key

    the key name

    value

    the Bool value

  • Set a Null value inside the Simple Object

    Warning

    If Simple Object’s size exceed the maximum of MAX_SO_SIZE bytes an exception will be thrown

    Throws

    SimpleObjectCreationError in case the constraints are not met

    Declaration

    Swift

    public func setNull(key: String) throws

    Parameters

    key

    the key name

  • Conversion to Swift Dictionary creates a copy af Simple Object internal dictionary

    Warning

    If a Simple Object has a Float or a Double value inside, please pay attention to access to its dictionary and cast it to the appropriate type. If you’re not sure cast it to Double values.

    Declaration

    Swift

    public func getDictionary() -> [String : Any]

    Return Value

    the Swift Dictionary