English 中文(简体)
如何在目标C中确定两个物体之间的细微差别
原标题:How to Find fine differences between two Objects in Objective C

我如何发现两种同类物体之间的价值差异。 例 我有一个有X, y, width, 高地特性和两条直径的物体。 我如何发现(无论是从方案角度还是从任何视觉工具或图书馆等)一种混杂物的特性与第二个混杂物不同?

或者在青少年或档案中是否有任何获得物体的国家?

最佳回答

如果你真的know,则其他答案是公正的。 页: 1 如果不是这样,你仍然很幸运,因为目标C允许你在时间探讨贵物体的典型变量。 比较两个未知物体的假体代码可以是:

+ (BOOL) compareObject:(id)obj1 withObject:(id)obj2 {

  unsigned int varCount1, varCount2;
  if ([obj1 class] != [obj2 class]) return NO;

  Ivar *vars1 = class_copyIvarList([obj1 class], &varCount1);
  Ivar *vars2 = class_copyIvarList([obj2 class], &varCount2);
  BOOL match = YES;

  for (int i = 0; i < varCount1; i++) {
    Ivar var1 = vars1[i];

    for (int j = 0; i < varCount2; j++) {
      Ivar var2 = vars2[j];
        if (strcmp(ivar_getName(var1), ivar_getName(var2)) == 0) {
          if (object_getIvar(obj1, var1) != object_getIvar(obj2, var2)) {
            match = NO;
            break;
          }
        } 
    }

    if (!match) break;

  }

  free(vars1);
  free(vars2);

  return match;
}
问题回答

如果你印刷该物体的描述,你将了解这些数值。

For eg,

CGRect rect = CGRectMake(10,10,20,20);
Rectangle *rectObject = [[Rectangle alloc] initWithFrame:rect];
NSLog(@"Desc : %@",[rectObject description]);

而且,如果你想要比较,

页: 1

页: 1

同样,你也可以得到,,

NSLog(@"Width : %f", rectObject.frame.size.width);
NSLog(@"Height : %f", rectObject.frame.size.height);

如果Xy等值浮动,则假设为Rec1, 而Rect2为2个目标,则为2个。

NSLog(@"for Rect1 
x %f y %f 
For Rect2 
x %f y%f",Rect1.x,Rect1.y,Rect2.x,Rext2.y);

这将分别显示Ret1和Rect2的x和 y。

如果你要检查,如果两个变量点到same instance,则你可使用obj1= obj2对其进行比较。

如果你想要检查,如果你的班级有两种不同的成员价值,你必须自行检查每个数值。 (例如obj1.property1 = obj2.property2)。

如果你只想检查同样的问题,在偷窃时,就把注意力放在一个破碎点上,并看着X条码的 de。 你可以检查那里的所有生物物体。 只字不提你的目标。 当地变量(在散货时已有的)直接列出,成员被组合成自己。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签