A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Baklava in Objective C page! Here, you'll find the source code for this program as well as a description of how the program works.
#import <Foundation/Foundation.h>
// Source:
// https://stackoverflow.com/questions/260945/create-nsstring-by-repeating-another-string-a-given-number-of-times
@interface NSString (Baklava)
- (NSString *) repeatString: (NSUInteger) times;
@end
@implementation NSString (Baklava)
- (NSString *) repeatString: (NSUInteger) times {
return [
@""
stringByPaddingToLength: [self length] * times
withString:self startingAtIndex: 0
];
}
@end
int main(int argc, const char * argv[]) {
NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
int i;
for (i = -10; i <= 10; i++) {
int numSpaces = abs(i);
int numStars = 21 - 2 * numSpaces;
printf(
"%s%s\n",
[[@" " repeatString: numSpaces] UTF8String],
[[@"*" repeatString: numStars] UTF8String]
);
}
[pool drain];
return 0;
}
Baklava in Objective C was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.