# rakdev7/iqkeyboardmanager architecture

> Architecture diagram of the GitHub repository rakdev7/iqkeyboardmanager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rakdev7/iqkeyboardmanager
- Repository: https://github.com/rakdev7/iqkeyboardmanager

## Overview

##### Project Type and Purpose
- This is an open-source iOS library/framework (IQKeyboardManager) that automatically manages keyboard interactions for UITextField/UITextView.
- It ships with two core modules in parallel:
- IQKeyboardManager (Objective-C source)
- IQKeyboardManagerSwift (Swift source)
- A Demo app (Objective-C and Swift targets) illustrates usage.

##### File-Structure Analysis
- Top-level directories:
- Demo/Objective_C_Demo & Demo/Swift_Demo – sample apps
- IQKeyboardManager – Objective-C library source (Categories, Constants, Core Manager, Toolbar, ReturnKeyHandler, Resources)
- IQKeyboardManagerSwift – Swift library source (same logical sub-modules)
- DemoObjCUITests – UI tests
- Podspecs, Xcode project files, CI configs
- Key architectural clues:
- “Categories” folder indicates use of Obj-C/Swift extensions for method swizzling and adding functionality to existing UIKit classes.
- “IQKeyboardManager.m” – likely the singleton core that observes keyboard notifications.
- “IQKeyboardReturnKeyHandler” – module that wires Return/Next/Previous buttons.
- “IQToolbar” – manages the custom UIToolbar placed above the keyboard.

##### README Insights
- Core functionality: no manual setup, no subclassing, no imports.
- Implementation: listens to UIKeyboard notifications, identifies the current firstResponder, adjusts view frames or contentInset on scroll views, injects a toolbar with navigation buttons.
- Integrations: CocoaPods, Carthage, direct source-drag-and-drop.
- Architecture patterns hinted:
- Observer pattern (NSNotificationCenter)
- Singleton (sharedManager)
- Categories/Extensions (monkey-patching UIKit classes)

a. Main Components
- Host App (Demo or any client app)
- IQKeyboardManager Core Module (Singleton, Notification Handler)
- IQKeyboardReturnKeyHandler Module
- IQToolbar Module
- UIKit Components: UITextField/UITextView, UIScrollView
- NSNotificationCenter (iOS Keyboard notifications)
- iOS System Keyboard
b. Relationships & Data Flow
1. Host App → AppDelegate → enable IQKeyboardManager.sharedManager
2. iOS System Keyboard → Posts UIKeyboardWillShow/Hide notifications → NSNotificationCenter
3. IQKeyboardManager (Observer) → receives notifications → determines active firstResponder via UIResponder+Category → calculates required view offset
4. IQKeyboardManager → adjusts UIScrollView.contentInset or view.frame via UIScrollView+Additions and UIViewController+Additions
5. IQToolbar Module → if enabled, attaches a UIToolbar with Next/Previous/Done buttons to the inputAccessoryView of the firstResponder
6. IQKeyboardReturnKeyHandler → intercepts Return key events → moves focus to next text input or dismisses keyboard
c. Architectural Patterns & Principles
- Observer (Keyboard notifications)
- Singleton API (sharedManager) for global state
- Extension (Categories/Swift extensions) on UIView, UIScrollView, UIViewController, UITextField, UITextView to avoid subclassing
- Modular separation: Core vs. Toolbar vs. ReturnKeyHandler vs. Constants vs. Resources
d. Key Technologies & Frameworks
- Foundation, UIKit, Objective-C Categories, Swift extensions
- CocoaPods/Carthage integration points
- Xcode build targets (static library / framework)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Apps
    subgraph "Client Applications"
        direction TB
        HostOC["Host App\n(Obj-C Demo)"]:::client
        HostSwift["Host App\n(Swift Demo)"]:::client
        HostOC --> AppDelegate
        HostSwift --> AppDelegate
    end

    AppDelegate["AppDelegate\n(enable sharedManager)"]:::client

    %% System Services
    subgraph "iOS System"
        direction TB
        iOSKeyboard["iOS System Keyboard"]:::system
        NotificationCenter["NSNotificationCenter"]:::system
    end

    iOSKeyboard -->|"posts UIKeyboardWillShow/Hide"| NotificationCenter
    NotificationCenter -->|"observer"| Core

    %% Objective-C Library Modules
    subgraph "Objective-C Library Modules"
        direction TB
        Core["IQKeyboardManager Core\n(singleton)"]:::library
        ReturnKey["IQKeyboardReturnKeyHandler Module"]:::library
        Toolbar["IQToolbar Module"]:::library
        CategoriesObjC["Categories/Extensions"]:::extension
        Constants["Constants"]:::library
        TextViewSub["IQTextView Subclass"]:::library
        Resources["Resources Bundle"]:::library
    end

    AppDelegate -->|"enable sharedManager"| Core
    Core --> ReturnKey
    Core --> Toolbar
    Core --> CategoriesObjC
    Core --> Constants
    Core --> TextViewSub
    Core --> Resources

    %% Toolbar Subcomponents
    subgraph "IQToolbar Subcomponents"
        direction TB
        BarButton["Bar Button Items"]:::library
        PrevNext["Previous/Next Controls"]:::library
        TitleItem["Title Item"]:::library
        UIViewCat["UIView Category\n(toolbar attach)"]:::extension
    end

    Toolbar --> BarButton
    Toolbar --> PrevNext
    Toolbar --> TitleItem
    Toolbar --> UIViewCat

    %% Categories Details
    subgraph "Categories Details"
        direction TB
        UIScrollViewAdd["UIScrollView+Additions"]:::extension
        UIViewControllerAdd["UIViewController+Additions"]:::extension
        TextFieldAdd["UITextField/UITextView+Additions"]:::extension
        ViewHierarchy["UIView+Hierarchy"]:::extension
        WindowHierarchy["UIWindow+Hierarchy"]:::extension
        ArraySort["NSArray+Sort"]:::extension
    end

    CategoriesObjC --> UIScrollViewAdd
    CategoriesObjC --> UIViewControllerAdd
    CategoriesObjC --> TextFieldAdd
    CategoriesObjC --> ViewHierarchy
    CategoriesObjC --> WindowHierarchy
    CategoriesObjC --> ArraySort

    %% Swift Library Modules
    subgraph "Swift Library Modules"
        direction TB
        SwiftCore["IQKeyboardManager Swift Core"]:::library
        SwiftReturnKey["IQKeyboardReturnKeyHandler Swift"]:::library
        SwiftToolbar["IQToolbar Swift"]:::library
        SwiftCategories["Swift Categories/Extensions"]:::extension
        SwiftConstants["Swift Constants"]:::library
        SwiftTextView["IQTextView Swift Subclass"]:::library
        SwiftResources["Swift Resources Bundle"]:::library
    end

    AppDelegate --> SwiftCore
    SwiftCore --> SwiftReturnKey
    SwiftCore --> SwiftToolbar
    SwiftCore --> SwiftCategories
    SwiftCore --> SwiftConstants
    SwiftCore --> SwiftTextView
    SwiftCore --> SwiftResources

    %% Podspecs and Projects
    subgraph "Integration & Build"
        direction TB
        Podspecs["CocoaPods Podspecs"]:::library
        XcodeProjOC["Obj-C Framework XcodeProj"]:::library
        XcodeProjSwift["Swift Framework XcodeProj"]:::library
    end

    Podspecs --> Core
    Podspecs --> SwiftCore
    XcodeProjOC --> Core
    XcodeProjSwift --> SwiftCore

    %% User Inputs and Adjustments
    FirstResponder["UITextField/UITextView\n(FirstResponder)"]:::system
    ReturnKey -->|"intercepts Return key"| FirstResponder
    Toolbar -->|"attaches UIToolbar to"| FirstResponder
    Core -->|"calculates offset & adjusts"| UIScrollViewAdd

    %% Click Events
    click HostOC "https://github.com/rakdev7/iqkeyboardmanager/tree/master/Demo/Objective_C_Demo"
    click HostSwift "https://github.com/rakdev7/iqkeyboardmanager/tree/master/Demo/Swift_Demo"
    click Core "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQKeyboardManager.h"
    click ReturnKey "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQKeyboardReturnKeyHandler.h"
    click Toolbar "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQToolbar/IQToolbar.h"
    click BarButton "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQToolbar/IQBarButtonItem.h"
    click PrevNext "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQToolbar/IQPreviousNextView.h"
    click TitleItem "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQToolbar/IQTitleBarButtonItem.h"
    click UIViewCat "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQToolbar/IQUIView+IQKeyboardToolbar.h"
    click UIScrollViewAdd "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Categories/IQUIScrollView+Additions.h"
    click UIViewControllerAdd "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Categories/IQUIViewController+Additions.h"
    click TextFieldAdd "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Categories/IQUITextFieldView+Additions.h"
    click ViewHierarchy "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Categories/IQUIView+Hierarchy.h"
    click WindowHierarchy "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Categories/IQUIWindow+Hierarchy.h"
    click ArraySort "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Categories/IQNSArray+Sort.h"
    click Constants "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Constants/IQKeyboardManagerConstants.h"
    click TextViewSub "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/IQTextView/IQTextView.h"
    click Resources "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager/Resources/IQKeyboardManager.bundle"
    click SwiftCore "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/IQKeyboardManager.swift"
    click SwiftReturnKey "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/IQKeyboardManager/IQKeyboardReturnKeyHandler.swift"
    click SwiftToolbar "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/IQToolbar/IQToolbar.swift"
    click SwiftCategories "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/Categories/IQUIScrollView+Additions.swift"
    click SwiftConstants "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/Constants/IQKeyboardManagerConstants.swift"
    click SwiftTextView "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/IQTextView/IQTextView.swift"
    click SwiftResources "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift/Resources/IQKeyboardManager.bundle"
    click Podspecs "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager.podspec.json"
    click XcodeProjOC "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManager.xcodeproj"
    click XcodeProjSwift "https://github.com/rakdev7/iqkeyboardmanager/blob/master/IQKeyboardManagerSwift.xcodeproj"

    %% Styles
    classDef system fill:#AED6F1,stroke:#2E86C1,color:#1B4F72
    classDef library fill:#ABEBC6,stroke:#27AE60,color:#1E8449
    classDef client fill:#F9E79F,stroke:#D4AC0D,color:#7D6608
    classDef extension fill:#F5CBA7,stroke:#D35400,color:#7E5109
```
