小编Dee*_*pak的帖子

NSCopying和继承

请看下面的代码:-------.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)

objective-c

5
推荐指数
2
解决办法
2769
查看次数

iPhone内存管理(特别针对属性)

我有一个非常明确的问题:

//.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].

iphone cocoa cocoa-touch

1
推荐指数
1
解决办法
467
查看次数

标签 统计

cocoa ×1

cocoa-touch ×1

iphone ×1

objective-c ×1