VJson

Undocumented

  • This notification is posted when the value of an item was updated due to a key/value update cycle.

    Declaration

    Swift

    public static let KVO_VALUE_UPDATE = Notification.Name(rawValue: "KVO_ValueUpdateNotification")
  • Set this option to ‘true’ to help find unwanted type conversions (in the debugging phase?).

    A type conversion occures if -for example- a string is assigned to a JSON item that contains a BOOL. If this flag is set to ‘true’, such a conversion will result in a fatal error. If this flag is set to ‘false’, the conversion will happen silently.

    Conversion to and from NULL are always possible, if it is necessary to force a type change irrespective of the value of this flag make two changes, first to NULL then to the desired type.

    Declaration

    Swift

    public static var fatalErrorOnTypeConversion = true
  • The JSON type of this object.

    Declaration

    Swift

    public fileprivate(set) var type: JType
  • The name of this object if it is part of a name/value pair.

    Declaration

    Swift

    public fileprivate(set) var name: String?
  • The value if this is a JSON BOOL.

    Declaration

    Swift

    public fileprivate(set) var bool: Bool?
  • The value if this is a JSON NUMBER.

    Declaration

    Swift

    public fileprivate(set) var number: NSNumber?
  • The value if this is a JSON STRING.

    Declaration

    Swift

    public fileprivate(set) var string: String?
  • The container for all children if self is .array or .object.

    Declaration

    Swift

    public fileprivate(set) var children: Children?
  • The parent of a child

    A VJson object cannot have more than one parent. For that reason the parent is stricktly managed: when adding an object, the parent of that object must be nil. When removing an object, the parent of that object will be set to nil.

    Declaration

    Swift

    public fileprivate(set) var parent: VJson?
  • Creates an empty VJson hierarchy

    Declaration

    Swift

    public convenience override init()
  • Undocumented

  • Undocumented

  • The custom string convertible protocol.

    Declaration

    Swift

    override public var description: String
  • Override the KVO ‘setValue’ to update the members.

    If an update is made, the KVO_VALUE_UPDATE notification is sent for the VJson item that was updated.

    Declaration

    Swift

    public override func setValue(_ value: Any?, forKey key: String)
  • Retrieves the value from a child item.

    Declaration

    Swift

    public override func value(forKey key: String) -> Any?
  • Implementation note: does not check the parent and the createdBySubscript members.

    Declaration

    Swift

    public static func == (lhs: VJson, rhs: VJson) -> Bool
  • The JSON types.

    See more

    Declaration

    Swift

    public enum JType
  • True if this object contains a JSON NULL object.

    Declaration

    Swift

    public var isNull: Bool
  • True if this object contains a JSON BOOL object.

    Note

    If the Apple Parser was used, all JSON bools will have been converted into a NUMBER.

    Declaration

    Swift

    public var isBool: Bool
  • True if this object contains a JSON NUMBER object.

    Note

    If the Apple Parser was used, all JSON bools will have been converted into a NUMBER.

    Declaration

    Swift

    public var isNumber: Bool
  • True if this object contains a JSON STRING object.

    Declaration

    Swift

    public var isString: Bool
  • True if this object contains a JSON ARRAY object.

    Declaration

    Swift

    public var isArray: Bool
  • True if this object contains a JSON OBJECT object.

    Declaration

    Swift

    public var isObject: Bool
  • Checks if a type change is allowed.

    Declaration

    Swift

    public static func typeChangeIsAllowed(from old: JType, to new: JType) -> Bool

    Parameters

    from

    The type to change from.

    to

    The type to change to

    Return Value

    True when the type change is allowed false otherwise.

  • Raises a fatal error is a type change is not allowed.

    Declaration

    Swift

    public static func fatalIfTypeChangeNotAllowed(from old: JType, to new: JType)

    Parameters

    from

    The type to change from.

    to

    The type to change to

    Return Value

    When the type change is allowed it will return, otherwise a fatal error will be raised.

  • Accessor for the name of this item if it is a name/value pair. Nil otherwise.

    Declaration

    Swift

    public var nameValue: String?
  • True if this object is a name/value pair. False otherwise.

    Declaration

    Swift

    public var hasName: Bool
  • True if this item contains a JSON NULL, nil otherwise. Note that conversions to and from NULL are always allowed.

    Declaration

    Swift

    public var nullValue: Bool?
  • True if this object contains a JSON NULL, false otherwise.

    Declaration

    Swift

    public var asNull: Bool
  • Creates a VJson item containing a JSON NULL.

    Declaration

    Swift

    public static func null(_ name: String? = nil) -> VJson

    Parameters

    name

    The name for this item (optional)

    Return Value

    A new VJson NULL item.

  • Accessor for the bool value of this object if the type is a JSON BOOL value. Nil otherwise.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non BOOL will result in a fatal error.

    Declaration

    Swift

    public var boolValue: Bool?
  • The value of this object interpreted as a bool.

    A NULL reads as false, a NUMBER 1(.0) reads as true, other numbers read as false, STRING true reads as true, all other strings read as false. ARRAY and OBJECT both read as false.

    Declaration

    Swift

    public var asBool: Bool
  • Creates a new VJson item with a JSON BOOL with the given value.

    Declaration

    Swift

    public convenience init(_ value: Bool?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • The number as an NSNumber if this is a JSON NUMBER item, nil otherwise.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var numberValue: NSNumber?
  • The value of this item interpretated as a number.

    For a NUMBER it returns a copy of that number, for NULL, OBJECT and ARRAY it returns a NSNumber with the value 0, for STRING it tries to read the string as a number (if that fails, it is regarded as a zero) and for a BOOL it creates a NSNumber with the bool as its value.

    Declaration

    Swift

    public var asNumber: NSNumber
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var intValue: Int?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var int8Value: Int8?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var int16Value: Int16?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var int32Value: Int32?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var int64Value: Int64?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var uintValue: UInt?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var uint8Value: UInt8?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var uint16Value: UInt16?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var uint32Value: UInt32?
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var uint64Value: UInt64?
  • The integer value of this item interpretated as a number.

    For a NUMBER it returns the integer value of that number, for NULL, OBJECT and ARRAY it returns 0, for STRING it tries to read the string as a number (if that fails, it is regarded as a zero) and for a BOOL it is either 0 or 1.

    Declaration

    Swift

    public var asInt: Int
  • Convenience accessor if this item is a JSON NUMBER.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non number will result in a fatal error.

    Declaration

    Swift

    public var doubleValue: Double?
  • The double value of this item interpretated as a number.

    For a NUMBER it returns the double value of that number, for NULL, OBJECT and ARRAY it returns 0, for STRING it tries to read the string as a number (if that fails, it is regarded as a zero) and for a BOOL it is either 0 or 1.

    Declaration

    Swift

    public var asDouble: Double
  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Int?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: UInt?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Int8?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: UInt8?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Int16?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: UInt16?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Int32?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: UInt32?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Int64?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: UInt64?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Float?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(_ value: Double?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • Creates a new VJson item with a JSON NUMBER with the given value.

    Declaration

    Swift

    public convenience init(number: NSNumber?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • The string value if this is a JSON STRING item, nil otherwise.

    If the VJson.fatalErrorOnTypeConversion is set to ‘true’ (default) then assigning a non string will result in a fatal error.

    Declaration

    Swift

    public var stringValue: String?
  • The value of this item interpretated as a string.

    NUMBER and BOOL return their string representation. NULL it returns null for OBJECT and ARRAY it returns an empty string.

    Declaration

    Swift

    public var asString: String
  • Creates a new VJson item with a JSON STRING with the given value.

    Declaration

    Swift

    public convenience init(_ string: String?, name: String? = nil)

    Parameters

    value

    The value for the new item.

    name

    The name for the value (optional).

  • A wrapper for the child items, used only for ARRAYs and OBJECTs

    See more

    Declaration

    Swift

    public class Children
  • Returns a copy of the child items in this object if this object contains a JSON ARRAY or JSON OBJECT. An empty array for all other JSON types.

    Declaration

    Swift

    public var arrayValue: Array<VJson>
  • Returns a copy of the children in a dictionary if this object contains a JSON OBJECT. An empty dictionary for all other JSON types.

    Declaration

    Swift

    public var dictionaryValue: Dictionary<String, VJson>
  • True if this item contains any childeren. False if this item does not have any children.

    Declaration

    Swift

    public var hasChildren: Bool
  • The number of child items this object contains.

    Declaration

    Swift

    public var nofChildren: Int
  • Removes all children from either ARRAY or OBJECT

    Declaration

    Swift

    public func removeAllChildren()
  • Removes the child items from self that are equal to the given item. Self must be an ARRAY or OBJECT.

    Note

    The parent is not compared when testing for equal.

    Declaration

    Swift

    public func remove(childrenEqualTo item: VJson?) -> Int

    Parameters

    childrenEqualTo

    The item to compare against.

    Return Value

    The number of child items removed.

  • Turns the JSON ARRAY in this object into a JSON OBJECT. Note that this can only succeed if all child items have a name. (I.e. are name/value pairs)

    Declaration

    Swift

    public func arrayToObject() -> Bool

    Return Value

    true if the conversion was successful. False otherwise.

  • Turns the JSON OBJECT in this object into a JSON ARRAY.

    Note that the names will be preserved until the array is saved. Then they will be discarded.

    Declaration

    Swift

    public func objectToArray() -> Bool

    Return Value

    True if succesful.

  • Controls the status of the dictionary cache for JSON OBJECTs. The dictionary cache can be used to speed up subscript access. As a ROM when looking for an OBJECT members 3 times or more, the cache will pay back its overhead. In some cases 2 times may be enough. More than 3 times is generally always quicker with cache enabled.

    Note

    The dictionary cache will speed up access for OBJECT members, but will lose members with duplicate names. I.e. a {one:1, one:2} object will only contain {one:2} when caching is enabled. However the lost member is still present in the children array and will be saved (or be part of the generated code).

    Declaration

    Swift

    public var enableCacheForObjects: Bool
  • Creates an empty JSON ARRAY item with the given name (if any).

    Declaration

    Swift

    public static func array(_ name: String? = nil) -> VJson

    Parameters

    name

    The name for the item (optional).

    Return Value

    The new VJson item containing a JSON ARRAY.

  • Creates an empty JSON OBJECT item with the given name (if any).

    Declaration

    Swift

    public static func object(_ name: String? = nil) -> VJson

    Parameters

    name

    The name for the item (optional).

    Return Value

    The new VJson item containing a JSON OBJECT.

  • Returns a new VJson object with a JSON ARRAY containing the given items. Only those items that have their ‘parent’ member set to ‘nil’ will be included.

    Declaration

    Swift

    public convenience init(_ items: [VJson?], name: String? = nil, includeNil: Bool = false)

    Parameters

    items

    An array with VJson objects to be added as children, only those with parent == nil.

    name

    The name for the JSON ARRAY item.

    includeNil

    If true (default = false) then nil items in the array will be included as JSON NULL items.

  • Returns a new VJson object with a JSON ARRAY containing the given items.

    Declaration

    Swift

    public convenience init(_ items: [VJsonSerializable?], name: String? = nil, includeNil: Bool = false)

    Parameters

    items

    An array with VJson objects to be added as children.

    name

    The name for the contained item (optional).

    includeNil

    If true (default = false) then nil items in the array will be included as JSON NULL items.

  • Returns a new VJson object with a JSON OBJECT containing the items from the dictionary. Only those items that have their ‘parent’ member set to ‘nil’ will be included.

    Declaration

    Swift

    public convenience init(items: [String:VJson], name: String? = nil)

    Parameters

    items

    A dictionary with the name/value pairs to be included as children.

    name

    The name for the contained item (optional).

  • Returns a new VJson object with a JSON OBJECT containing the items from the dictionary.

    Declaration

    Swift

    public convenience init(_ items: [String:VJsonSerializable], name: String? = nil)

    Parameters

    items

    A dictionary with the name/value pairs to be included as children.

    name

    The name for the contained item (optional).

  • Returns the child at the given index if it exists. Self must be a JSON ARRAY item.

    Declaration

    Swift

    public func child(at index: Int) -> VJson?

    Parameters

    at

    The index of the requested child.

    Return Value

    The object or nil if no object exists at the given index. If self is not an array, it also returns nil.

  • The index of the given child. Self must be a JSON ARRAY item.

    Declaration

    Swift

    public func index(ofChild child: VJson?) -> Int?

    Parameters

    ofChild

    The child to find the index of.

    Return Value

    The index of the child if it is present. Nil if none was found.

  • The indicies of the children with identical contents as the given child. An empty array if no comparable child is found. Self must be a JSON ARRAY item.

    Declaration

    Swift

    public func index(ofChildrenEqualTo item: VJson?) -> [Int]

    Parameters

    ofChildEqualTo

    The child to compare the content with.

    Return Value

    The indicies of the child items with the same content. An empty array if none was found.

  • Removes the given object from self. Self must be an array.

    Declaration

    Swift

    public func remove(child item: VJson?) -> VJson?

    Parameters

    child

    The child object to remove.

    Return Value

    Nil on failure, the item that was removed on success.

  • Replaces the child at the given index with the given child. Self must be a JSON ARRAY item.

    Declaration

    Swift

    public func replace(childAt index: Int, with child: VJson?) -> VJson?

    Parameters

    childAt

    The index of the child to be replaced.

    with

    The VJson object to be inserted.

    Return Value

    The inserted child, or nil if an error occured.

  • Inserts the given child at the given index. Self must be a JSON ARRAY item.

    Declaration

    Swift

    public func insert(_ child: VJson?, at index: Int) -> VJson?

    Parameters

    child

    The VJson object to be inserted.

    at index

    The index at which it will be inserted. Must be >= 0 && < nofChildren to succeed.

    Return Value

    The inserted child, or nil if an error occured.

  • Appends the given object to the end of the array. Self must be a JSON ARRAY.

    Declaration

    Swift

    public func append(_ child: VJson?) -> VJson?

    Parameters

    child

    The VJson object to be appended.

    Return Value

    The appended child, or nil if an error occured.

  • Appends the given object to the end of the array. Self must be a JSON ARRAY.

    Declaration

    Swift

    public func append(_ item: VJsonSerializable?) -> VJson?

    Parameters

    child

    The VJson object to be appended.

    Return Value

    The appended child, or nil if an error occured.

  • Appends the given objects to the end of the array. Self must be a JSON ARRAY.

    Declaration

    Swift

    public func append(children items: [VJson?]?, includeNil: Bool = false)

    Parameters

    children

    The items to add.

    includeNil

    If true, a NULL will be added for each ‘nil’ in the array.

  • Appends the given objects to the end of the array. Self must be a JSON ARRAY.

    Declaration

    Swift

    public func append(children items: [VJsonSerializable?]?, includeNil: Bool = false)

    Parameters

    children

    The items to add.

    includeNil

    If true, a NULL will be added for each ‘nil’ in the array.

  • Returns the child with the requested name, if any.

    Declaration

    Swift

    public func child(with name: String) -> VJson?

    Parameters

    name

    The name of the requested child.

    Return Value

    The requested child if it is present, nil otherwise.

  • Declaration

    Swift

    public func children(with name: String) -> [VJson]

    Return Value

    An array with the found child items, may be empty.

  • Add a new item with the given name or replace a current item with that same name (when replace = ‘true’). Self must contain a JSON OBJECT item or a NULL. If it is a NULL it will be converted into an OBJECT.

    Declaration

    Swift

    public func add(_ child: VJson?, for name: String? = nil, replace: Bool = true) -> VJson?

    Parameters

    child

    The child that should replace or be appended. The child must have a name or a name must be provided in the parameter “for name”. If a name is provided in “for name” then that name will take precedence and replace the name contained in the child item.

    name

    If nil, the child must already have a name. If non-nil, then this name will be used and the name of the child (if present) will be overwritten.

    replace

    If ‘true’ (default) it will replace all existing items with the same name. If ‘false’, then the child will be added and no check on duplicate names will be performed.

    Return Value

    The child that was added or nil on failure.

  • Add a new item with the given name or replace a current item with that same name (when replace = ‘true’). Self must contain a JSON OBJECT item or a NULL. If it is a NULL it will be converted into an OBJECT.

    Declaration

    Swift

    public func add(_ item: VJsonSerializable?, for name: String? = nil, replace: Bool = true) -> VJson?

    Parameters

    child

    The child that should replace or be appended. The child must have a name or a name must be provided in the parameter “for name”. If a name is provided in “for name” then that name will take precedence and replace the name contained in the child item.

    name

    If nil, the child must already have a name. If non-nil, then this name will be used and the name of the child (if present) will be overwritten.

    replace

    If ‘true’ (default) it will replace all existing items with the same name. If ‘false’, then the child will be added and no check on duplicate names will be performed.

    Return Value

    The child that was added or nil on failure.

  • Removes all children with the given name from this object only. Self must contain a JSON OBJECT.

    Declaration

    Swift

    public func remove(childrenWith name: String) -> Int

    Parameters

    childrenWith

    The name of the child items to be removed.

    Return Value

    The number of children removed.

  • Looks for a specific item in the hierachy.

    Declaration

    Swift

    public func item(of type: JType, at path: [String]) -> VJson?

    Parameters

    of

    The JSON TYPE of object to look for.

    at path

    An array of strings describing the path at which the item should exist. Note that integer indexing will convert the string into an index before using. Hence a path of [“12”] can refer to the item at index 12 as well as the item for name “12”.

    Return Value

    the item at the given path if it exists and is of the given type. Otherwise nil.

  • Looks for a specific item in the hierachy.

    Declaration

    Swift

    public func item(of: JType, at path: String ...) -> VJson?

    Parameters

    of

    The JSON TYPE of object to look for.

    at path

    A set of strings describing the path at which the item should exist. Note that integer indexing will convert the string into an index before using. Hence a path of “12” can refer to the item at index 12 as well as the item for name “12”.

    Return Value

    the item at the given path if it exists and is of the given type. Otherwise nil.

  • Updates the content of this object with the content of the object to be merged. Child members with the same name in self as in other will be made identical to the member in other.

    This merge function was designed to support the outline view. When members are merged the original member will remain, only its data content will change. This also applies to array items.

    After merging the two hierarchies will not share objects, i.e. all shared data is duplicated.

    Note

    This operation can change the types of the content in self to and from null. Other type conversions are only possible if VJson.fatalErrorOnTypeConversion is set to ‘false’

    Note

    If other has two children with the same name, the order in which they appear will be preserved

  • Parameters

    • with: The object to be merged into self.
  • Declaration

    Swift

    public func merge(with other: VJson)
  • The generator for the VJson object.

    See more

    Declaration

    Swift

    public struct MyGenerator: IteratorProtocol
  • defines the struct used as the iterator

    Declaration

    Swift

    public typealias Iterator = MyGenerator
  • Creates an iterator

    Declaration

    Swift

    public func makeIterator() -> Iterator

    Return Value

    A new iterator.

  • Assigns/retrieves based on the given index.

    Only valid for VJson objects containing a JSON ARRAY.

    Note

    Can result in a fatal error if the VJson.fatalErrorOnTypeConversion is set to ‘true’ (= default)

    Declaration

    Swift

    public subscript(index: Int) -> VJson
  • Assigns/retrieves based on the given key.

    Only valid for VJson objects containing a JSON OBJECT.

    Note

    Can result in a fatal error if the VJson.fatalErrorOnTypeConversion is set to ‘true’ (= default)

    Declaration

    Swift

    public subscript(key: String) -> VJson
  • Returns a full in-depth copy of this JSON object. I.e. all child elements are also copied.

    Declaration

    Swift

    public var duplicate: VJson
  • Replaces the content of self with the content of the given object, but it does not change the parent reference and the createdBySubscript will be set to false.

    Note

    A fatalError is raised if a type change is attempeted but not supported.

    Declaration

    Swift

    public func replaceContent(with other: VJson?) -> Bool

    Parameters

    with other

    The VJson object from which to copy the data.

    Return Value

    True if the operation was sucessful, false otherwise.

  • Replaces self with other in the parent of self. The parent of other must be nil.

    Note

    A fatalError is raised if a type change is attempeted but not supported.

    Declaration

    Swift

    public func replaceSelfInParent(with other: VJson?) -> Bool

    Parameters

    with other

    The VJson object which to replace self with.

    Return Value

    True if the operation was sucessful, false otherwise.

  • This error type gets thrown if errors are found during parsing.

    • reason: The details of the error.
    See more

    Declaration

    Swift

    public enum Exception: Error, CustomStringConvertible
  • A general purpose wrapper for function results that return ParseFunctionResult’s

    Recommended use: let json = VJson.parse(data(from: myJsonCode)){ … error handler … }

    Declaration

    Swift

    public typealias parseErrorSignature = (_ code: Int, _ incomplete: Bool, _ message: String) -> Void
  • Error info from the parser for the parse operations that do not throw.

    See more

    Declaration

    Swift

    public struct ParseError
  • Parsing a JSON hierarchy stored in a file

    Declaration

    Swift

    public static func parse(file: URL, onError: parseErrorSignature) -> VJson?

    Parameters

    from

    The URL of a file.

    Return Value

    A ParseFunctionResult

  • Create a VJson hierarchy from the contents of the given file.

    Throws

    Either an VJson.Error.reason or an NSError if the VJson hierarchy could not be created or the file not be read.

    Declaration

    Swift

    public static func parse(file: URL) throws -> VJson

    Parameters

    file

    The URL that designates the file to be read.

    Return Value

    A VJson hierarchy with the contents of the file.

  • Create a VJson hierarchy with the contents of the given file.

    Declaration

    Swift

    public static func parse(file: URL, errorInfo: inout ParseError?) -> VJson?

    Parameters

    file

    The URL that designates the file to be read.

    errorInfo

    A (pointer to a) struct that will contain the error info if an error occured during parsing (i.e. when the result of the function if nil).

    Return Value

    On success the VJson hierarchy. On error a nil for the VJson hierarchy and the structure with error information filled in.

  • Parsing a JSON hierarchy stored in a buffer

    Declaration

    Swift

    public static func parse(buffer: UnsafeBufferPointer<UInt8>, onError: parseErrorSignature) -> VJson?

    Parameters

    from

    The buffer to parse.

    Return Value

    A ParseFunctionResult

  • Create a VJson hierarchy with the contents of the given buffer.

    Throws

    A VJson.Error.reason if the parsing failed.

    Declaration

    Swift

    public static func parse(buffer: UnsafeBufferPointer<UInt8>) throws -> VJson

    Parameters

    buffer

    The buffer containing the data to be parsed.

    Return Value

    A VJson hierarchy with the contents of the buffer.

  • Create a VJson hierarchy with the contents of the given buffer.

    • Parameters

      • buffer: The buffer containing the data to be parsed.
      • errorInfo: A (pointer to a) struct that will contain the error info if an error occured during parsing (i.e. when the result of the function if nil).

    Declaration

    Swift

    public static func parse(buffer: UnsafeBufferPointer<UInt8>, errorInfo: inout ParseError?) -> VJson?

    Return Value

    On success the VJson hierarchy. On error a nil for the VJson hierarchy and the structure with error information filled in.

  • Parsing a JSON hierarchy stored in a string.

    Declaration

    Swift

    public static func parse(string: String, onError: parseErrorSignature) -> VJson?

    Parameters

    from

    The string to parse.

    Return Value

    A ParseFunctionResult

  • Create a VJson hierarchy with the contents of the given string.

    Throws

    A VJson.Error.reason if the parsing failed.

    Declaration

    Swift

    public static func parse(string: String) throws -> VJson

    Parameters

    string

    The string containing the data to be parsed.

    Return Value

    A VJson hierarchy with the contents of the buffer.

  • Create a VJson hierarchy with the contents of the given buffer.

    • Parameters

      • string: The string containing the data to be parsed.
      • errorInfo: A (pointer to a) struct that will contain the error info if an error occured during parsing (i.e. when the result of the function if nil).

    Declaration

    Swift

    public static func parse(string: String, errorInfo: inout ParseError?) -> VJson?

    Return Value

    On success the VJson hierarchy. On error a nil for the VJson hierarchy and the structure with error information filled in.

  • Parsing a JSON hierarchy stored in a Data object

    Declaration

    Swift

    public static func parse(data: inout Data, onError: parseErrorSignature) -> VJson?

    Parameters

    from

    The data to parse.

    Return Value

    A ParseFunctionResult

  • Create a VJson hierarchy with the contents of the given data object.

    Throws

    A VJson.Error.reason if the parsing failed.

    Declaration

    Swift

    public static func parse(data: inout Data) throws -> VJson

    Parameters

    data

    The data object containing the data to be parsed.

    Return Value

    A VJson hierarchy with the contents of the data object.

  • Create a VJson hierarchy with the contents of the given data object.

    • Parameters

      • data: The data object containing the data to be parsed.
      • errorInfo: A (pointer to a) struct that will contain the error info if an error occured during parsing (i.e. when the result of the function if nil).

    Declaration

    Swift

    public static func parse(data: inout Data, errorInfo: inout ParseError?) -> VJson?

    Return Value

    On success the VJson hierarchy. On error a nil for the VJson hierarchy and the structure with error information filled in.

  • Returns the JSON code that represents the hierarchy of this item.

    Declaration

    Swift

    public var code: String
  • Tries to saves the contents of the JSON hierarchy to the specified file.

    Declaration

    Swift

    public func save(to: URL) -> String?

    Parameters

    to

    The URL of the file location where to save this hierarchy.

    Return Value

    Nil on success, Error description on fail.

  • This parser uses the Apple NSJSONSerialization class to parse the given data.

    Note

    Parser differences: Apple’s parser is usually faster (about 2x). However Apple’s parser cannot parse multiple key/value pairs with the same name and Apple’s parser will create a VJson NUMBER items for BOOL’s.

    Throws

    The error thrown by NSJSONSerialization. Error code 100 should be impossible.

    Declaration

    Swift

    public static func parseUsingAppleParser(_ data: Data) throws -> VJson

    Return Value

    A VJson hierarchy

  • Scans a memory area for a JSON formatted message as defined by opening and closing braces. Scanning for the opening brace starts at the first byte. Scanning continues until either the closing brace or the end of the range is encountered. Braces inside strings are not evaluated.

    Note

    This function does not guarantee that the JSON code between the braces is valid JSON code.

    Note

    When a buffer is returned, the start of the buffer is the location of the opening brace, which is not necessarily equal to the start-pointer.

    Declaration

    Swift

    public static func findPossibleJsonCode(start: UnsafeMutableRawPointer, count: Int) -> UnsafeBufferPointer<UInt8>?

    Parameters

    start

    A pointer to the start of an area that must be scnanned for a JSON message.

    count

    The number of bytes that must be scanned.

    Return Value

    Nil if no (complete) JSON message was found, otherwise an UnsafeBufferPointer covering the area with the JSON message. Note that the bufer is not copied. Hence make sure to process the JSON message before removing or moving the data in that area.