我正在学习Objective C,我试图在我的BNRItem类中覆盖我的超类(NSObject)描述方法。虽然看起来我做的一切都是对的,但我的NSLog似乎没有使用我的覆盖描述方法。相反,我在description方法的定义中看到了Thread 1 Breakpoint 1.1,更准确地说,我在定义descriptionString的地方看到了。
这是我的控制台输出。
2015-08-30 20:49:00.622 RandomItems[46034:1002101] Zero
2015-08-30 20:49:00.623 RandomItems[46034:1002101] One
2015-08-30 20:49:00.623 RandomItems[46034:1002101] Two
2015-08-30 20:49:00.623 RandomItems[46034:1002101] Three
(lldb)
我的主。m文件:
#import <Foundation/Foundation.h>
#import "BNRItem.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Create a mutable array object, store its address in items variable...
NSMutableArray *items = [[NSMutableArray alloc] init];
//Send the message addObject: to the NSMutableArray pointed
//by the variable item, passing a string each time
[items addObject:@"One"];
[items addObject: @"Two"];
[items addObject: @"Three"];
// Send another message, insertObject:atIndex;, to that same array object
[items insertObject:@"Zero" atIndex:0];
// For every item in the items array ...
for (NSString *item in items){
//Log the description of item
NSLog(@"%@", item);
}
// Create a BNRItem instance and log its instance variables in the console
BNRItem *item = [[BNRItem alloc] init];
// Set item name to Red Sofa
item.itemName = @"Red Sofa";
item.serialNumber= @"A1B2C";
item.valueInDollards = 100;
//
NSLog(@"%@", item);
//Destroy the mutable array object
items = nil ;
}
return 0;
}
My header file:
#import <Foundation/Foundation.h>
@interface BNRItem : NSObject
{
NSString *_itemName;
NSString *_serialNumber;
int _valueInDollards;
NSDate *_dateCreated;
}
- (void)setItemName:(NSString *)str;
- (NSString *)itemName;
- (void)setSerialNumber:(NSString *)str;
- (NSString *)serialNumber;
- (void)setValueInDollards:(int)v;
- (int)valueInDollards;
- (NSDate *)dateCreated;
@end
最后,我的实现文件:
#import "BNRItem.h"
@implementation BNRItem
- (void)setItemName:(NSString *)str
{
_itemName = str;
}
- (NSString *)itemName
{
return _itemName;
}
- (void)setSerialNumber:(NSString *)str
{
_serialNumber = str;
}
- (NSString *)serialNumber
{
return _serialNumber;
}
- ( void )setValueInDollards:(int)v
{
_valueInDollards = v;
}
- ( int )valueInDollards
{
return _valueInDollards;
}
-( NSDate * )dateCreated
{
return _dateCreated;
}
- ( NSString * )description
{
NSString *descriptionString = [[NSString alloc] initWithFormat:@"%@ (%@): Worth %d, recorded on %@", self.itemName, self.serialNumber, self.valueInDollards, self.dateCreated];
return descriptionString;
}
@end
听起来您只是在-description
方法的一行上设置了一个断点。调试器在断点处停止程序。没有实际错误的指示。
如果你在Xcode中点击继续按钮,你的程序可能会正常运行。
你可以禁用断点,告诉Xcode忽略所有的断点,或者删除断点,如果你不想在那里中断。断点看起来像代码左侧空白处的一个蓝色箭头。右键单击或ctrl -click查看选项。
要使Xcode忽略断点,请切换调试工具栏中的断点按钮。它看起来也像一个向右的箭头。如果启用了断点,它将被填充为蓝色。