无法在我的for循环中添加超过260个元素的NSmutableArray元素(Unable to add elements in NSmutableArray more than 260 elements from my for loop)
这是代码。 我们无法获得完整的数组元素。 它限制为260个元素,但有360个元素。
-(void)scheduleCal{ float monthlyPayment = 0.0; //monthly Payment float loanAmount = 100000; //Loan Amount int years = 30; float intRate = 6; float i = intRate / 1200; int n = years * 12;// 360 float rPower = pow(1+i, n); float mPayment = loanAmount*((i*(pow((1+i), n)))/((pow(1+i, n))-1)); monthlyPayment = loanAmount * i * rPower / (rPower -1); NSLog(@"Monthly Payment:%0.2f %f",mPayment,round(monthlyPayment)); float tempLoanAmount = loanAmount; self.array = [[NSMutableArray alloc] init]; for (int r = 1; r <= n; r++) { float interestPayment = tempLoanAmount *i; double principalPayment = mPayment - interestPayment; tempLoanAmount -= principalPayment; NSDictionary *dic = @{@"sno":[NSString stringWithFormat:@"%d",r],@"principal": [NSString stringWithFormat:@"%0.2f",principalPayment],@"interest":[NSString stringWithFormat:@"%0.2f",interestPayment],@"balance":[NSString stringWithFormat:@"%0.2f",tempLoanAmount]}; [self.array addObject:dic]; dic = nil; } NSLog(@"Array:%@ %ld",self.array,(unsigned long)self.array.count); }Here is the code. We are unable to get complete array elements. It's restricting to 260 elements but there are 360 elements.
-(void)scheduleCal{ float monthlyPayment = 0.0; //monthly Payment float loanAmount = 100000; //Loan Amount int years = 30; float intRate = 6; float i = intRate / 1200; int n = years * 12;// 360 float rPower = pow(1+i, n); float mPayment = loanAmount*((i*(pow((1+i), n)))/((pow(1+i, n))-1)); monthlyPayment = loanAmount * i * rPower / (rPower -1); NSLog(@"Monthly Payment:%0.2f %f",mPayment,round(monthlyPayment)); float tempLoanAmount = loanAmount; self.array = [[NSMutableArray alloc] init]; for (int r = 1; r <= n; r++) { float interestPayment = tempLoanAmount *i; double principalPayment = mPayment - interestPayment; tempLoanAmount -= principalPayment; NSDictionary *dic = @{@"sno":[NSString stringWithFormat:@"%d",r],@"principal": [NSString stringWithFormat:@"%0.2f",principalPayment],@"interest":[NSString stringWithFormat:@"%0.2f",interestPayment],@"balance":[NSString stringWithFormat:@"%0.2f",tempLoanAmount]}; [self.array addObject:dic]; dic = nil; } NSLog(@"Array:%@ %ld",self.array,(unsigned long)self.array.count); }最满意答案
代码没有错。 代码非常好。 数组包含360个元素。 它刚刚被控制在控制台上。 如果您需要检查或打印控制台上的全部内容,请使用以下任一方式。
for (NSDictionary *dict in self.array) { NSLog(@"Dict: %@ ",dict); } OR printf("%s", [NSString stringWithFormat: @"%@", array].UTF8String);Nothing wrong in the code. Code is perfectly fine. Array contains 360 elements. It's just got clipped on console. If you need to check or print the entire contents on console use any of the below way.
for (NSDictionary *dict in self.array) { NSLog(@"Dict: %@ ",dict); } OR printf("%s", [NSString stringWithFormat: @"%@", array].UTF8String);更多推荐
发布评论