请看下面的代码:-------.h
@interface BankAccount : NSObject<NSCopying>
{
double accountBalance;
long accountNumber;
NSString *CustomerName;
NSString *AccountType;
}
-(void) setAccount: (long) y andBalance: (double) x;
-(void) setCustomerName: (NSString*) name andAccountType: (NSString*) type;
-(id)copyWithZone:(NSZone *)zone;
@end
@interface Savings : BankAccount
{
int number;
NSString *Offer;
}
-(void) setSavingNumber: (uint8_t) num andOffer: (NSString*) offer;
-(id)copyWithZone:(NSZone *)zone;
@end
Run Code Online (Sandbox Code Playgroud)
---------- .m
@implementation BankAccount
-(void) setAccount: (long) y andBalance: (double) x
{
accountNumber = y;
accountBalance = x;
}
-(void) setCustomerName: (NSString*) name andAccountType: (NSString*) type
{
CustomerName …Run Code Online (Sandbox Code Playgroud) 我有一个非常明确的问题:
//.h file
@property (nonatomic, retain)NSMutableString * retainString;
@property (nonatomic, copy)NSMutableString * copyString;
//.m file
@synthesis retainString, copyString;
-(void)Process
{
NSMutableString *test = [[NSMutableString alloc]inti];//retain count should be 1
self.retainString = test;
self.copyString = test;
}
Run Code Online (Sandbox Code Playgroud)
条件.1-> //保留两者的计数应该是2.因为它们指向具有保留计数2的相同内存位置,所以应该如何写入释放.
条件.2-> // //保留测试计数为1,copyString为2.由于两者都保持不同的内存位置.但我们可以写[copyString release].