How ibireme/yymodel works
Project type and purpose
• This is an open-source, high-performance Objective-C model-to-JSON (and back) conversion framework (YYModel), complete with an example Benchmark app and test suite.
File structure
• Top-level components:
– /YYModel: core source (NSObject+YYModel.*, YYClassInfo.*, YYModel.*)
– /Framework: Xcode framework project (YYModel.xcodeproj) for building the library
– /Benchmark: iOS app (ModelBenchmark.xcodeproj) that measures conversion performance
– /YYModelTests: XCTest cases verifying correctness and edge cases
– Podspec, Carthage & manual installation config files
README for insights
• Exposes a simple API:
– yy_modelWithJSON: JSON → Model
– yy_modelToJSONObject: Model → JSON
• Supports mapping, nested models, container generics, custom transforms, NSCoding/NSCopying/Hash/Equal/Description
• Relies on ObjC runtime reflection (YYClassInfo) and Foundation JSON parsing/serialization
Main components & their interactions
A. Clients / Integrators
• CocoaPods, Carthage, Manual import
• Your application code or Benchmark App
→ calls
B. YYModel Public API Layer
• Category on NSObject: yy_modelWithJSON:, yy_modelToJSONObject, yy_modelEncodeWithCoder, etc.
→ orchestrates
C. Core Conversion Engine
1. JSON Parser / Serializer (Foundation’s NSJSONSerialization)
2. Reflection Module (YYClassInfo)
3. Property Mapper (modelCustomPropertyMapper)
4. Container Class Resolver (modelContainerPropertyGenericClass)
5. Custom Transform Hooks (modelCustomTransformFromDictionary / ToDictionary)
→ uses
D. Model Objects
• User-defined classes (e.g. GitHubUser, FEWeiboModel, SwiftGithubUser)
• Populated via KVC / direct ivar access
E. Output
• NSDictionary / JSON data
• NSCoding archive, copy, hash, equality, description
F. Quality & Packaging
• Test Suite (YYModelTests) runs through all feature cases
• Benchmark App measures performance
• Podspec / Carthage support / .xcodeproj for framework
Architectural patterns & design principles
• Modular separation – Public API vs. Conversion Engine vs. Model classes
• Non-intrusive categories – no base class requirement
• Reflection-driven mapping – runtime introspection via YYClassInfo
• Hook points – custom mapping, transform, whitelist/blacklist
• Layered approach – parse JSON, map to model, apply transforms, serialize back
Essential architectural elements
• Separation of concerns: parsing vs. mapping vs. custom logic
• Extension points where users plug in custom behavior
– Clearly reflect YYModel’s modular architecture
– Illustrate the flow from JSON input through conversion engine to model objects and back
– Demonstrate external integration points (apps, tests, package managers)
– Highlight the runtime-reflection backbone and customization hooks