Heliograph 0.1.0

Heliograph 0.1.0

测试已测试
语言 Obj-CObjective C
许可协议 MIT
发布最新发布2016年1月

Leo Schweizer维护。



Heliograph 是一个面向对象的、基于反射的可扩展封装,用于 Objective-C 的运行时反射功能。

构建

将 Heliograph 包含到您的项目中最简单的方法是通过 CocoaPods

pod 'Heliograph'

使用

进入反射世界的核心入口是 reflect 函数

#import <Heliograph/Heliograph.h>

HGClassMirror *classMirror = reflect([NSString class]);
HGProtocolMirror *protocolMirror = reflect(@protocol(NSSecureCoding));
HGObjectMirror *objectMirror = reflect(@"Heliograph");

有趣的事实:您可以使用 Heliograph 来理解 Heliograph 的功能!

#import <Heliograph/Heliograph.h>

HGClassMirror *class = reflect([HGClassMirror class]);
for (HGMethodMirror *each in [class methods]) {
    NSLog(@"- %@", NSStringFromSelector([each selector]));
}
for (HGMethodMirror *each in [[class classMirror] methods]) {
    NSLog(@"+ %@", NSStringFromSelector([each selector]));
}

// =>
// - adoptedProtocols
// - adoptProtocol:
// - instanceVariableNamed:
// - methodNamed:
// - subclasses
// - addInstanceVariableNamed:withEncoding:
// - addMethodNamed:withImplementation:andEncoding:
// ...
// + allClasses

HGMethodMirror *method = [class methodNamed:@selector(addMethodNamed:withImplementation:andEncoding:)];
for (id<HGTypeMirror> each in [method argumentTypes]) {
    NSLog(@"%@", [each typeDescription]);
}

// =>
// SEL
// ^
// unknown type

示例片段

注意:Heliograph 与 OpinionatedC 密不可分,因此这里列出的片段中许多都使用了 Heliograph 和 OpinionatedC!

贡献

如果您有任何问题、评论、想法或改进建议,请随时在打开一个问题。如果您即将创建一个拉取请求,只需注意以下几点:

  • 首先提出一个问题描述,如果您不确定您的想法是否会受到青睐
  • 使用制表符缩进,而不是空格
  • 编写单元测试,争取实现 100% 覆盖率

贡献者

许可协议

The MIT License (MIT)

Copyright (c) 2016 Leo Schweizer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.