image range fix & silence warnings
This commit is contained in:
parent
3765c771ec
commit
bac00ad0fa
@ -326,7 +326,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor])
|
let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font.updateSize(standardFontSize), NSAttributedString.Key.foregroundColor: textColor as UIColor])
|
||||||
|
|
||||||
for attribute in attributes {
|
for attribute in attributes {
|
||||||
guard let range = validateAttribute(range: NSRange(location: attribute.location, length: attribute.length) , in: attributedString)
|
guard let range = validateAttribute(range: NSRange(location: attribute.location, length: attribute.length) , in: attributedString, type: attribute.type)
|
||||||
else { continue }
|
else { continue }
|
||||||
|
|
||||||
switch attribute {
|
switch attribute {
|
||||||
@ -461,7 +461,7 @@ public typealias ActionBlock = () -> ()
|
|||||||
guard let attributeType = attribute.optionalStringForKey(KeyType),
|
guard let attributeType = attribute.optionalStringForKey(KeyType),
|
||||||
let location = attribute["location"] as? Int,
|
let location = attribute["location"] as? Int,
|
||||||
let length = attribute["length"] as? Int,
|
let length = attribute["length"] as? Int,
|
||||||
let range = validateAttribute(range: NSRange(location: location, length: length), in: attributedString)
|
let range = validateAttribute(range: NSRange(location: location, length: length), in: attributedString, type: attributeType)
|
||||||
else { continue }
|
else { continue }
|
||||||
|
|
||||||
switch attributeType {
|
switch attributeType {
|
||||||
@ -1001,15 +1001,15 @@ extension Label {
|
|||||||
// MARK: - Validations
|
// MARK: - Validations
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
func validateAttribute(range: NSRange, in string: NSAttributedString) -> NSRange? {
|
func validateAttribute(range: NSRange, in string: NSAttributedString, type: String = "") -> NSRange? {
|
||||||
guard range.location >= 0 && range.location < string.length else {
|
guard range.location >= 0 && range.location <= string.length else {
|
||||||
if let loggingHandler = MVMCoreLoggingHandler.shared(), loggingHandler.responds(to: #selector(MVMCoreLoggingHandler.addError(toLog:))) {
|
if let loggingHandler = MVMCoreLoggingHandler.shared(), loggingHandler.responds(to: #selector(MVMCoreLoggingHandler.addError(toLog:))) {
|
||||||
loggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, messageToLog: "Attribute starting location \(range.lowerBound) is out of bounds for '\(string.string)'. Attribute is discarded.", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: "\(#file): \(#function)")!)
|
loggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, messageToLog: "Attribute starting location \(range.lowerBound) is out of bounds for '\(string.string)'. Attribute is discarded.", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: "\(#file): \(#function)")!)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if range.upperBound > string.length {
|
if type != "image" && range.upperBound > string.length {
|
||||||
let newRange = NSRange(location: range.location, length: string.length - range.location)
|
let newRange = NSRange(location: range.location, length: string.length - range.location)
|
||||||
if let loggingHandler = MVMCoreLoggingHandler.shared(), loggingHandler.responds(to: #selector(MVMCoreLoggingHandler.addError(toLog:))) {
|
if let loggingHandler = MVMCoreLoggingHandler.shared(), loggingHandler.responds(to: #selector(MVMCoreLoggingHandler.addError(toLog:))) {
|
||||||
loggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, messageToLog: "Attribute ending location \(range.upperBound) is out of bounds for '\(string)'. Adjusting to \(newRange.upperBound).", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: "\(#file): \(#function)")!)
|
loggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, messageToLog: "Attribute ending location \(range.upperBound) is out of bounds for '\(string)'. Adjusting to \(newRange.upperBound).", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: "\(#file): \(#function)")!)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user