嗨,我正在尝试创建我的计算的 plist,但结果列表是空的....请帮助这里是我的代码。除了这个之外,还有其他方法可以将字符串写入文件...
-(float)calculate
{
if(!self.operatorLabel.text.length)
return self.operand2;
float result=0;
switch([self.operatorLabel.text characterAtIndex:0])
{
case '+':result=self.self.operand1+self.operand2;
break;
case '-':result=self.operand1-self.operand2;
break;
case '*':result=self.operand1*self.operand2;
break;
case '/':if(self.operand2==0)
divideByZeroFlag=true;
else
result=self.operand1/self.operand2;
break;
default:self.operand1=0;
result=self.operand2;
break;
}
if(!divideByZeroFlag&&self.operand1!=0)
{
NSString *data=[NSString stringWithFormat:@"%g%@%g=%g",self.operand1,self.operatorLabel.text,self.operand2,result];
NSMutableDictionary *dat;
[dat setObject:data forKey:@"nthing"];
[dat writeToFile:@"memory.plist" atomically:YES];
}
return result;
}