ChecksumUtility
@objc public final class ChecksumUtility : NSObject
Utility for checksum generation and validation
-
Generate CRC16
Parameter
Parameter string: String to generate crc forReturns
CRC16 in 4 digit hex code string format with0
as paddingDeclaration
Swift
public static func crc16(string: String) -> String
Parameters
string
String to generate crc for
Return Value
CRC16 in 4 digit hex code string format with
0
as padding -
Checks if the qr string includes valid CRC16
Parameter
Parameter qrString: QR code stringReturns
true
if the CRC16 in the qrString is valid elsefalse
Declaration
Swift
public static func isValidCrc16(qrString: String) -> Bool
Parameters
qrString
QR code string
Return Value
true
if the CRC16 in the qrString is valid elsefalse
-
Valid luhn checksum of the string
Parameter
Parameter string: String to valid luhn checksum forReturns
true
if luhn checksum of the string is validPrecondition
string
should be numeric otherwise this method returns falseDeclaration
Swift
public static func validateLuhnChecksum(_ string: String) -> Bool
Parameters
string
String to valid luhn checksum for
Return Value
true
if luhn checksum of the string is valid -
Generate luhn checksum of the string.
Parameter
Parameter string: String to valid luhn checksum forReturns
Integer luhn checksumThrows
MPQRError.invalidFormat
if the the string is not numericPrecondition
Check digit should not be present in the stringDeclaration
Swift
public static func luhnChecksum(_ string: String) throws -> NSNumber
Parameters
string
String to valid luhn checksum for
Return Value
Integer luhn checksum
-
Generate luhn checksum of the string
Parameter
Parameter string: String to valid luhn checksum forParameter
Parameter hasCheckDigit: WhetherCheck digit
is already present in the string or not.Returns
Integer luhn checksumThrows
MPQRError.invalidFormat
if the the string is not numericDeclaration
Swift
public static func luhnChecksum(_ string: String, hasCheckDigit: Bool) throws -> NSNumber
Parameters
string
String to valid luhn checksum for
hasCheckDigit
Whether
Check digit
is already present in the string or not.Return Value
Integer luhn checksum