Skip to content

Instantly share code, notes, and snippets.

@Angles
Created July 26, 2012 03:37
Show Gist options
  • Save Angles/3180099 to your computer and use it in GitHub Desktop.
Save Angles/3180099 to your computer and use it in GitHub Desktop.
iOS app "Obj-C" recent code stuff
#import <Foundation/Foundation.h>
#import <math.h>
// ver F4c.m
// *********
// begin auxilary test logging object
// *********
// APLogObj Interface
@interface APLogObj : NSObject {
NSString * _pre;
}
@property (nonatomic, retain) NSString *pre;
- (void) aplog:(const char *)funk msg:(NSString *)yo;
- (void) aplog:(const char *)funk ln:(int)line msg:(NSString *)yo;
- (void) flog:(const char *)funk cmsg:(const char *)cyo;
@end
// APLogObj Implementation
@implementation APLogObj
@synthesize pre = _pre;
- (NSString *) pre
{
// getter for pre - the preample to log output
if (!_pre) { _pre = [NSString stringWithString:@"(APLogObj: )"]; }
return _pre;
}
- (void) aplog:(const char *)funk msg:(NSString *)yo
{
// (preamble) method msg (no line here)
printf("%s in %s %s \n", [self.pre UTF8String], funk, [yo UTF8String]);
}
- (void) aplog:(const char *)funk ln:(int)line msg:(NSString *)yo
{
// (preamble) method.line msg
printf("%s in %s.%i %s \n", [self.pre UTF8String], funk, line, [yo UTF8String]);
}
// try more const char is easier?
- (void) flog:(const char *)funk cmsg:(const char *)cyo
{
//printf("%s in %s %s \n", [self.pre UTF8String], funk, [yo UTF8String]);
printf("flog in: %s says: %s \n", funk, cyo);
}
@end
// *********
// end auxilary test logging object
// *********
// *********
// everything below here was last working version i add above to
// *********
// begin main object
@interface mainObj : NSObject {
int _xyz;
NSArray *_pArray;
APLogObj *_loggObj;
}
@property (nonatomic) int xyz;
@property (nonatomic, retain) NSArray *pArray;
@property (nonatomic, retain) APLogObj *loggObj;
-(void)main;
-(void)primary;
-(void)other;
-(void)third;
-(void)busty;
-(void)loopy;
-(void)loggerTest;
@end
@implementation mainObj
@synthesize xyz = _xyz;
@synthesize pArray = _pArray;
@synthesize loggObj = _loggObj;
- (NSArray *) pArray
{
if (!_pArray) {
printf("at line %i lazy instantiation of property pArray\n", __LINE__);
_pArray = [NSArray arrayWithObjects: @"air", @"sky", @"cloud", @"blue", @"tree", @"factory", nil];
}
return _pArray;
}
- (APLogObj *) loggObj
{
if (!_loggObj) {
printf("at line %i in mainObj lazy instantiation of property (of type APLogObj) loggObj\n", __LINE__);
_loggObj = [[APLogObj alloc] init];
}
return _loggObj;
}
- (void) main
{
[self primary];
[self other];
[self third];
[self busty];
[self loopy];
[self loggerTest];
}
- (void) primary
{
NSString *str1 = @"hi there";
NSString *myTitle = [NSString stringWithFormat:@"%@ dude, wasssabe!", str1];
printf("at line %i str1 is: %s \n", __LINE__, [str1 UTF8String]);
printf("at line %i myTitle is: %s \n", __LINE__, [myTitle UTF8String]);
//printf(at line %i str1 is: %s and myTitle is %s \n", __LINE__, [str1 UTF8String], [myTitle UTF8String] );
// stacko: NSString* alphabetString = [NSString stringWithFormat:@"%c", 'A' + i];
// to go from c-str to an NSString ??????
NSString *stacko = [NSString stringWithFormat:@"%c %c", 'c', 65];
printf("at line %i stacko is %s \n", __LINE__, [stacko UTF8String]);
}
- (void) other
{
NSString *str2 = @"hi there from other";
printf("at line %i str2 is: %s \n", __LINE__, [str2 UTF8String]);
}
- (void) third
{
NSArray *colors = [NSArray arrayWithObjects: @"green", @"red", @"yellow", @"grey", nil];
printf("at line %i count of colors is: %i \n", __LINE__, [colors count]);
}
- (void) busty
{
// compare log methods
printf("at line %i count of property pArray is: %i \n", __LINE__, [self.pArray count]);
[self.loggObj aplog:__func__ ln:__LINE__ msg:[NSString stringWithFormat:@"count of property pArray is: %i", [self.pArray count]]];
NSString *thingy = [self.pArray objectAtIndex:0];
printf("at line %i thingy zero is: %s \n", __LINE__, [thingy UTF8String]);
NSString *zerois = @"thingy zero is: ";
[self.loggObj aplog:__func__ ln:__LINE__ msg:[zerois stringByAppendingString:thingy]];
printf("at line %i pArray at three is: %s \n", __LINE__, [[self.pArray objectAtIndex:3] UTF8String]);
zerois = @"pArray at three is: ";
[self.loggObj aplog:__func__ ln:__LINE__ msg:[zerois stringByAppendingString:[self.pArray objectAtIndex:3]]];
}
- (void) loopy
{
NSUInteger numItems = [self.pArray count];
NSInteger i = 0;
// old schoool iteration
//for(NSInteger i = 0; i < numItems; ++i)
for(i = 0; i < numItems; ++i)
{
printf("(loopy) iteration %i array object is: %s \n", i, [[self.pArray objectAtIndex:i] UTF8String]);
[self.loggObj aplog:__func__ ln:__LINE__ msg:[NSString stringWithFormat:@"iteration %i array object is: %@", i, [self.pArray objectAtIndex:i]]];
}
}
-(void) loggerTest
{
//printf("about to use loggObj \n");
// aplog:(char *)funk ln:(int)line msg:(NSString *)yo
[self.loggObj aplog:__FUNCTION__ ln:__LINE__ msg:@"1st time using this facility"];
[self.loggObj aplog:__FUNCTION__ ln:__LINE__ msg:[NSString stringWithString:@"2nd time using this facility"]];
[self.loggObj aplog:__FUNCTION__ ln:__LINE__ msg:@"Basic usage of APLog at least works."];
// use the no-line method
[self.loggObj aplog:__func__ msg:@"msg passed thru no line version of aplog method ."];
// use const char one
[self.loggObj flog:__func__ cmsg:"this less useful method, const char msg very plain"];
}
@end
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
printf(">> MAIN at line %i starting int main \n", __LINE__);
id obj=[[mainObj alloc] init];
[obj main];
//[obj other];
printf(">> MAIN at line %i exiting int main \n", __LINE__);
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment