PSPDFJSONAdapter


@interface PSPDFJSONAdapter : NSObject

Converts a PSPDFModel object to and from a JSON dictionary.

  • The model object that the receiver was initialized with, or that the receiver parsed from a JSON dictionary.

    Declaration

    Objective-C

    @property (readonly, nonatomic) PSPDFModel<PSPDFJSONSerializing> *_Nonnull model;

    Swift

    var model: PSPDFModel { get }
  • Attempts to parse a JSON dictionary into a model object.

    Returns an instance of modelClass upon success, or nil if a parsing error occurred.

    Declaration

    Objective-C

    + (nullable __kindof PSPDFModel *)
          modelOfClass:(nonnull Class)modelClass
    fromJSONDictionary:(nonnull NSDictionary<NSString *, id> *)JSONDictionary
                 error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func model(of modelClass: AnyClass, fromJSONDictionary JSONDictionary: [String : Any]) throws -> PSPDFModel

    Parameters

    modelClass

    The PSPDFModel subclass to attempt to parse from the JSON. This class must conform to <PSPDFJSONSerializing

    . This argument must not be nil.

    JSONDictionary

    A dictionary representing JSON data. This should match the format returned by NSJSONSerialization. If this argument is nil, the method returns nil.

    error

    If not NULL, this may be set to an error that occurs during parsing or initializing an instance of modelClass.

  • Converts a model into a JSON representation.

    Returns a JSON dictionary, or nil if a serialization error occurred.

    Declaration

    Objective-C

    + (nullable NSDictionary<NSString *, id> *)JSONDictionaryFromModel:
        (nonnull PSPDFModel<PSPDFJSONSerializing> *)model;

    Swift

    class func jsonDictionary(from model: PSPDFModel) -> [String : Any]?

    Parameters

    model

    The model to use for JSON serialization. This argument must not be nil.

  • Initializes the receiver by attempting to parse a JSON dictionary into a model object.

    Returns an initialized adapter upon success, or nil if a parsing error occurred.

    Declaration

    Objective-C

    - (nullable instancetype)
    initWithJSONDictionary:(nonnull NSDictionary<NSString *, id> *)JSONDictionary
                modelClass:(nonnull Class)modelClass
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    init(jsonDictionary JSONDictionary: [String : Any], modelClass: AnyClass) throws

    Parameters

    JSONDictionary

    A dictionary representing JSON data. This should match the format returned by NSJSONSerialization. If this argument is nil, the method returns nil.

    modelClass

    The PSPDFModel subclass to attempt to parse from the JSON. This class must conform to <PSPDFJSONSerializing

    . This argument must not be nil.

    error

    If not NULL, this may be set to an error that occurs during parsing or initializing an instance of modelClass.

  • Initializes the receiver with an existing model.

    Declaration

    Objective-C

    - (nullable instancetype)initWithModel:
        (nonnull PSPDFModel<PSPDFJSONSerializing> *)model;

    Swift

    init?(model: PSPDFModel)

    Parameters

    model

    The model to use for JSON serialization. This argument must not be nil.

  • Serializes the receiver’s model into JSON.

    Returns a JSON dictionary, or nil if a serialization error occurred.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable)
        NSDictionary<NSString *, id> *JSONDictionary;

    Swift

    var jsonDictionary: [String : Any]? { get }