IOS objective-c共通コードバックアップレコード


プロジェクトホームの取得
 NSString *homeDir = NSHomeDirectory();
 NSLog(@" :%@", homeDir);

プロジェクトドキュメントディレクトリの取得
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
NSLog(@" 
%@", documentsDirectoryPath);

データローカライズストレージを構成し、最終的にプロジェクトディレクトリ/Library/preferences/以下のplistファイルに格納します.
		NSMutableArray *mutArr = [[NSMutableArray alloc]initWithObjects:@"1", nil];

        // 

        [[NSUserDefaults standardUserDefaults] setObject:mutArr forKey:@"mutableArr"];

        [[NSUserDefaults standardUserDefaults] synchronize];

        //   

        NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"mutableArr"];

        NSLog(@" ====%@",arr);

弾窓
	    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@" " message:@" " preferredStyle:UIAlertControllerStyleAlert];//UIAlertControllerStyleAlert 
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@" " style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@" " style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
     
        NSString *str = [NSString stringWithFormat:
        @"https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8"];
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
         }];//https iTunes , App store 
         [alertController addAction:cancelAction];
         [alertController addAction:okAction];
        [self presentViewController:alertController animated:YES completion:nil];

辞書アクション
	NSMutableDictionary *hookConfig;
    hookConfig = [[NSMutableDictionary alloc] init];
	[hookConfig setObject:[NSNumber numberWithBool:isButtonOn] forKey:@"isRedEnvelopeSwitchEnable"];


印刷呼び出しスタック
	NSArray *syms = [NSThread  callStackSymbols];
    if ([syms count] > 1) {
     
        for (int i=0; i < [syms count]; i++) {
     
            NSLog(@"mytest====== %@ - caller: %@ ", [self class], self, NSStringFromSelector(_cmd),[syms objectAtIndex:i]);
        }
    } else {
     
         NSLog(@"mytest====== %@", [self class], self, NSStringFromSelector(_cmd));
    }

オブジェクトのすべてのプロパティを印刷
unsigned int count;
objc_property_t *properties = class_copyPropertyList([obj class], &count);
for(int i=0;i<count;i++){
     
    objc_property_t property = properties[i];
    NSString *key = [[NSString alloc]initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
    //kvc 
    NSString *value = [obj valueForKey:key];
    NSLog(@"%@->%@",key,value);
}