VoucherMedia
@interface VoucherMedia : NSObject <NSCoding>
VoucherMedia
is the model for all Media items inside of a Voucher
.
It represents all of the different Media types:
Image - Any kind of photo (eg. png, jpg).
Animation - Any kind of animated photo (eg. gif).
Sound - Any kind of sound (eg. mp3).
Youtube - A youtube video.
Video - Any kind of video (eg. m4a).
Note - Any kind of text.
-
The type of
VoucherMedia
.Declaration
Objective-C
@property (readonly, nonatomic) VoucherMediaType mediaType;
Swift
var mediaType: VoucherMediaType { get }
-
The id of the
VoucherMedia
. This id is unique for allVoucherMedia
s and will be set by the Vouchr Server.Declaration
Objective-C
@property (assign, readwrite, nonatomic) long mediaId;
Swift
var mediaId: Int { get set }
-
The title of the
VoucherMedia
.Declaration
Objective-C
@property (readonly, strong, nonatomic, nullable) NSString *title;
Swift
var title: String? { get }
-
The url to get the media item.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) NSString *mediaUrlString;
Swift
var mediaUrlString: String? { get set }
-
The url to show a thumbnail image.
Declaration
Objective-C
@property (readwrite, strong, nonatomic, nullable) NSString *thumbnailUrlString;
Swift
var thumbnailUrlString: String? { get set }
-
Initializer to create a
VoucherMedia
from an NSDictionary. The Initializer will try to be smart about returning the proper subclass ofVoucherMedia
(eg.ImageMedia
when it is a photo).Declaration
Objective-C
- (nonnull instancetype)initWithDictionary:(nonnull NSDictionary *)dictionary;
Swift
init(dictionary: [AnyHashable : Any])
Parameters
dictionary
- the dictionary representation of a
VoucherMedia
.Return Value
Instance of
VoucherMedia
. -
Initializer to create a
VoucherMedia
from properties. The Initializer will try to be smart about returning the proper subclass ofVoucherMedia
(eg.ImageMedia
when it is a photo).Declaration
Objective-C
- (nonnull instancetype)initWithType:(VoucherMediaType)mediaType title:(nullable NSString *)title mediaUrlString:(nullable NSString *)mediaUrlString thumbnailUrlString:(nullable NSString *)thumbnailUrlString;
Swift
init(type mediaType: VoucherMediaType, title: String?, mediaUrlString: String?, thumbnailUrlString: String?)
Parameters
mediaType
- the type of
VoucherMedia
.title
- the title of the
VoucherMedia
.mediaUrlString
- the url to the
VoucherMedia
item.thumbnailUrlString
- the thumbnail of the
VoucherMedia
item.Return Value
Instance of
VoucherMedia
. -
Creates an array of
VoucherMedia
s from an Array of NSDictionary versions ofVoucherMedia
s. Internally callsinitWithDictionary:
for eachVoucherMedia
.Declaration
Objective-C
+ (nonnull NSArray<VoucherMedia *> *)voucherMediasFromArray: (nonnull NSArray *)mediasJson;
Swift
class func voucherMedias(from mediasJson: [Any]) -> [VoucherMedia]
Parameters
mediasJson
- Array of NSDictionary
VoucherMedia
s.Return Value
Array of
VoucherMedia
objects. -
Static Initializer to create a
VoucherMedia
from an NSDictionary. The Initializer will try to be smart about returning the proper subclass ofVoucherMedia
(eg.ImageMedia
when it is a photo).Declaration
Objective-C
+ (nonnull instancetype)voucherMediaWithDictionary: (nonnull NSDictionary *)dictionary;
Parameters
dictionary
- the dictionary representation of a
VoucherMedia
.Return Value
Instance of
VoucherMedia
. -
Static Initializer to create a
VoucherMedia
from properties. The Initializer will try to be smart about returning the proper subclass ofVoucherMedia
(eg.ImageMedia
when it is a photo).Declaration
Objective-C
+ (nonnull instancetype)voucherMediaWithType:(VoucherMediaType)mediaType title:(nullable NSString *)title mediaUrlString:(nullable NSString *)mediaUrlString thumbnailUrlString: (nullable NSString *)thumbnailUrlString;
Parameters
mediaType
- the type of
VoucherMedia
.title
- the title of the
VoucherMedia
.mediaUrlString
- the url to the
VoucherMedia
item.thumbnailUrlString
- the thumbnail of the
VoucherMedia
item.Return Value
Instance of
VoucherMedia
. -
Converts a
VoucherMedia
to an NSDictionary that can be used for sending to the server.Declaration
Objective-C
- (nonnull NSDictionary *)dictionaryRepresentationWithoutMediaData;
Swift
func dictionaryRepresentationWithoutMediaData() -> [AnyHashable : Any]
Return Value
dictionary - Dictionary form of a
VoucherMedia
without the media data. -
Converts a
VoucherMedia
to an NSDictionary that can be used for caching.Declaration
Objective-C
- (nonnull NSDictionary *)dictionaryRepresentation;
Swift
func dictionaryRepresentation() -> [AnyHashable : Any]
Return Value
dictionary - Dictionary form of a
VoucherMedia
. -
Helper to convert a
VoucherMediaType
to a string valueDeclaration
Objective-C
+ (nonnull NSString *)mediaStringFromMediaType:(VoucherMediaType)mediaType;
Swift
class func mediaString(from mediaType: VoucherMediaType) -> String
Parameters
mediaType
- the mediaType that is being converted
Return Value
string form of a mediaType.
-
Updates all properties of this instance of
VoucherMedia
with the properties of media.Declaration
Objective-C
- (void)updateWithMedia:(nonnull VoucherMedia *)media;
Swift
func update(with media: VoucherMedia)
Parameters
media
- the properties that should be set on this
VoucherMedia
. -
Updates the type of this instance of
VoucherMedia
with specifiedVoucherMediaType
.Declaration
Objective-C
- (void)updateMediaType:(VoucherMediaType)type;
Swift
func updateMediaType(_ type: VoucherMediaType)
Parameters
type
- the type that should be set on this
VoucherMedia
. -
Indicates whether the
VoucherMedia
has been uploaded to theVoucher
server.Declaration
Objective-C
- (BOOL)hasBeenUploadedToServer;
Swift
func hasBeenUploadedToServer() -> Bool