--------------- FKItem.h ---------------
#import
<Foundation/Foundation.h>
@interface
FKItem :
NSObject
@property (nonatomic , assign) double price;
- (void) info;
@property (nonatomic , assign) double price;
- (void) info;
@end
--------------- FKItem.m ---------------
#import
"FKItem.h"
@implementation FKItem
@implementation FKItem
@synthesize
price;
- (void) info
{
{
NSLog(@"这是一个普通的方法");
}
- (double) calDiscount:(double) discount
{
- (double) calDiscount:(double) discount
{
return
self.price * discount;
}
@end
---------------
main.m
---------------
#import
<Foundation/Foundation.h>
#import
"FKItem.h"
@interface
FKItem (fk)
- (double) calDiscount:(double)discount;
@end
int main()
{
FKItem* item = [[FKItem alloc] init];
item.price = 109;
@end
int main()
{
FKItem* item = [[FKItem alloc] init];
item.price = 109;
[item
info];
NSLog(@"物品打折的价格为:%g",
[item
calDiscount:.75]);
}
一、编写本节代码的具体步骤:
1.可仿照第二章001节的代码编写步骤,可以把类的接口文件,类的实现文件写在main.m文件中。
二、本节代码涉及到的知识点:
1.把方法写在@implementation部分,相当于写了一个私有方法。
2.如果想要调用私有方法,可以使用performSelector:来动态调用。
3.如此之外,我们也可以使用category的方式来调用类的私有方法。