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 with0as paddingDeclaration
Swift
public static func crc16(string: String) -> StringParameters
stringString to generate crc for
Return Value
CRC16 in 4 digit hex code string format with
0as padding -
Checks if the qr string includes valid CRC16
Parameter
Parameter qrString: QR code stringReturns
trueif the CRC16 in the qrString is valid elsefalseDeclaration
Swift
public static func isValidCrc16(qrString: String) -> BoolParameters
qrStringQR code string
Return Value
trueif the CRC16 in the qrString is valid elsefalse
-
Valid luhn checksum of the string
Parameter
Parameter string: String to valid luhn checksum forReturns
trueif luhn checksum of the string is validPrecondition
stringshould be numeric otherwise this method returns falseDeclaration
Swift
public static func validateLuhnChecksum(_ string: String) -> BoolParameters
stringString to valid luhn checksum for
Return Value
trueif 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.invalidFormatif the the string is not numericPrecondition
Check digit should not be present in the stringDeclaration
Swift
public static func luhnChecksum(_ string: String) throws -> NSNumberParameters
stringString 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 digitis already present in the string or not.Returns
Integer luhn checksumThrows
MPQRError.invalidFormatif the the string is not numericDeclaration
Swift
public static func luhnChecksum(_ string: String, hasCheckDigit: Bool) throws -> NSNumberParameters
stringString to valid luhn checksum for
hasCheckDigitWhether
Check digitis already present in the string or not.Return Value
Integer luhn checksum
ChecksumUtility Class Reference