本文介绍了Objective-C运行:是什么把尺寸为&放大器;对齐class_addIvar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的 Objective-C运行提供了class_addIvar C函数:

BOOL class_addIvar(Class cls, const char *name, size_t size, 
                   uint8_t alignment, const char *types)

我怎么把为尺寸对齐

我添加类型 UITextPosition * 的实例变量,但没有 UITextPosition 对象范围。对于尺寸,可我只是做的sizeof(个体经营),其中的UITextField ?即,我可以假设一个 UITextPosition 对象的大小为的UITextField 对象相同?

I'm adding an instance variable of type UITextPosition *, but no UITextPosition object is in scope. For size, can I just do sizeof(self), where self is a subclass of UITextField? I.e., can I assume that a UITextPosition object is the same size as a UITextField object?

我如何获得对齐

推荐答案

在这个东西的文档不是非常丰富,这也反映了一般你不应该用它来。但是,您可以要求对齐方式:

The documentation on this stuff is not very informative, which does reflect that generally you shouldn't be using it. However, you can ask for the alignment:

char *texPosEncoding = @encode(UITextPosition);
NSUInteger textPosSize, textPosAlign;
NSGetSizeAndAlignment(textPosEncoding, &textPosSize, &textPosAlign);
class_addIvar(yourClass, "yourIvarName", textPosSize, textPosAlign, textPosEncoding);

这篇关于Objective-C运行:是什么把尺寸为&放大器;对齐class_addIvar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:40