简体   繁体   English

这个Objective-C陈述是什么意思?

[英]What does this Objective-C statement mean?

I can usually decipher unfamiliar code, given a few minutes, but what is this: 几分钟后,我通常可以解密不熟悉的代码,但这是什么:

    NSNumber *one = [NSNumber numberWithInt:rand()%60+20];

It's from XYPieChart. 来自XYPieChart。

Thanks! 谢谢!

rand() Returns a pseudo-random integral number in the range between 0 and RAND_MAX. rand()返回介于0到RAND_MAX之间的伪随机整数。 see this link 看到这个链接

% is modulo operator and finds the remainder of division of one number by another. 是取模运算符,可找到一个数除以另一数的余数。 See this link 看到这个链接

rand() % 60 = Number in range 0 to 59 rand()%60 = 0到59之间的数字

rand()%60+20 = Number in range 20 to 79 rand()%60 + 20 = 20到79之间的数字

NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type. NSNumber是NSValue的子类,它提供作为任何C标量(数字)类型的值。

+ (NSNumber *)numberWithInt:(int)value

Above class method of NSNumber creates and returns an NSNumber object containing a given value, treating it as a signed int. 上面的NSNumber类方法创建并返回一个包含给定值的NSNumber对象,将其视为带符号的int。

NSNumber *one = [NSNumber numberWithInt:rand()%60+20];

So the above statement is initialising "one" with NSNumber initialised with random integer between 20 to 79. 因此,以上语句将NSNumber初始化为“ 1”,其中NSNumber初始化为20到79之间的随机整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM