Skip to content

Commit 33a8469

Browse files
committed
Fixed a crash that happens when maxCount is less than or equal to objcString.length
1 parent f934f7a commit 33a8469

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

VSTwitterTextCounter/Classes/VSTwitterTextCounter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public class VSTwitterTextCounter: UIControl
361361
let objcString = NSString(string: textView.text)
362362

363363
// Find if last allowed index falls between a unicode character
364-
var lastAllowedCharacterIndex = maxCount // Last allowed character index
364+
var lastAllowedCharacterIndex = objcString.length > maxCount ? maxCount : objcString.length - 1 // Last allowed character index
365365
let rangeOfComposedCharacter = objcString.rangeOfComposedCharacterSequence(at: lastAllowedCharacterIndex)
366366
if rangeOfComposedCharacter.contains(lastAllowedCharacterIndex)
367367
{

0 commit comments

Comments
 (0)