             return nil
         }
 
-        let range = NSMakeRange(0, textStorage.length)
         var rangeOfAttachment: NSRange?
-        
-        textStorage.enumerateAttribute(NSAttachmentAttributeName, inRange: range, options: []) { (object, range, stop) in
-            guard let attachment = object as? AztecTextAttachment where attachment == targetAttachment else {
+
+        enumerateAttachments(ofType: AztecTextAttachment.self) { (attachment, range) in
+            guard attachment == targetAttachment else {
                 return
             }
 

    /// AztecTextAttachments found in textStorage and asks the delegate for a
    /// custom view for the attachment.
    ///
    private func enumerateAttachments() {
        resetAttachmentManager()

        guard let textStorage = layoutManager.textStorage else {
            assertionFailure("Unable to enumerate attachments. No NSTextStorage.")
            return
        }

        let range = NSMakeRange(0, textStorage.length)
        textStorage.enumerateAttribute(NSAttachmentAttributeName, inRange: range, options: []) { (object, range, stop) in
            guard let attachment = object as? AztecTextAttachment else {
                return
            }

            self.attachments.append(attachment)

            guard let view = self.delegate?.attachmentManager(self, viewForAttachment: attachment) else {
                return
            }

            self.attachmentViews[attachment.identifier] = AztecAttachmentView(view: view, identifier: attachment.identifier, exclusionPath: nil)
            self.resizeViewForAttachment(attachment, toFitInContainer: self.textView.textContainer)
            self.textView.addSubview(view)
        }

        layoutAttachmentViews()
    }



    /// whenever the text in the textView changes.
    ///
    public func updateAttachmentLayout() {
        reloadAttachments()
    }


