Created
February 15, 2021 04:43
-
-
Save robertmryan/abd3b608b247c3307bd6d7d7484d9a8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// InvoiceLine.h | |
@import Foundation; | |
NS_ASSUME_NONNULL_BEGIN | |
@interface InvoiceItem : NSObject | |
@property (nonatomic, copy, nullable) NSString *title; | |
@property (nonatomic, copy, nullable) NSString *itemDescription; // because `description` has special meaning in `NSObject`, we’ll call this `itemDescription` | |
@property (nonatomic, copy, nullable) NSString *cost; | |
@property (nonatomic, copy, nullable) NSString *tax; | |
@end | |
NS_ASSUME_NONNULL_END |
And the .m file is pretty simple, too.
// InvoiceItem.m
#import "InvoiceItem.h"
@implementation InvoiceItem
- (NSString *)description {
return [NSString stringWithFormat:@"<InvoiceLine %p; title=%@; itemDescription=%@; cost=%@; tax=%@>", self, self.title, self.itemDescription, self.cost, self.tax];
}
@end
You don't need to implement description
, but it makes it so you can easily log it, e.g.
InvoiceItem *item = [[InvoiceItem alloc] init];
...
item.title = "foo";
NSLog(@"%@", item);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And you could use it like so: