Skip to content

Remove tagged user by one back space is not working properly  #4

@SandeepiO

Description

@SandeepiO

Hi,

I have gone through your code and this is wonderful code.
But you need to change the code little bit from this

          for att in attr! {
                if att.key == NSAttributedStringKey.foregroundColor {
                    if att.value as! UIColor == UIColor.systemBlue() {
                        setupBackspace(cursorPosition: cursorPosition-1, length: length+1)
                        return
                    } else {
                        length > 0 ? removeText(length: length+1) : removeText(length: 0)
                        return
                    }
                } else {
                    length > 0 ? removeText(length: length+1) : removeText(length: 0)
                    return
                }
            }

To

          if attr?.contains(where: {$0.key == NSAttributedStringKey.foregroundColor}) ?? false, let att 
          = attr?.filter({$0.key == NSAttributedStringKey.foregroundColor}){
                if att[NSAttributedStringKey.foregroundColor] as! UIColor == UIColor.systemBlue() {
                    
                    setupBackspace(cursorPosition: cursorPosition-1, length: length+1)
                    return
                    
                }else {
                    length > 0 ? removeText(length: length+1) : removeText(length: 0)
                    return
                }
            
            }else{
                
                length > 0 ? removeText(length: length+1) : removeText(length: 0)
                return
                
            }

because this is not compulsory that the on the first index you get NSAttributedStringKey.foregroundColor every time.
So check it whether exists in the array or not.
Happy Coding ...
Thank You for the code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions