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======<%@ %p> %@ - caller: %@ ", [self class], self, NSStringFromSelector(_cmd),[syms objectAtIndex:i]);
        }
    } else {
         NSLog(@"mytest======<%@ %p> %@", [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);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值