nsstring

ios9 字符串与UTF-8 互相转换

穿精又带淫゛_ 提交于 2020-01-22 20:50:23
在数据网路请求或其他情况下,需要将字符串转换成UTF-8编码 ios9后对其方法进行了修改 NSString *str = @"北京"; 把这个转成UTF8以前我们使用的是 NSString *str3 = [str stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; 但是在ios9这个方法废弃了 用如下方法转 NSString *str1 = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 那如果想转成“北京”这个字符串怎么办呢 ,不用担心有方法的 还是说以前我们用的方法是 NSString *str3 = [str1stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; ios9同样废弃了这个方法 现在使用 NSString *str2 = [str1 stringByRemovingPercentEncoding]; iOS9现在使用的转码方法: NSString *str = @"http://www.test.com/你好.jpg"; NSString

抖音app开发时,在录制视频添加背景音乐功能实现流程

爱⌒轻易说出口 提交于 2020-01-22 17:32:47
抖音app之所以“横扫”整个短视频领域,最主要的还是占据了短视频玩法的“先机”,其中在录制视频时添加背景音乐,是很多用户都非常喜欢的步骤,但是在 抖音app开发 时,添加背景音乐的功能也是需要技术实现的。今天就来分享下关于这一功能的大概实现流程。 1.在录制界面点击音乐,绘制UI 添加搜索框 -(UIView *)searchBg { if (!_searchBg) { _searchBg = [[UIView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight,_window_width,44)]; _searchBg.backgroundColor = [UIColor whiteColor]; _search = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0, _window_width,44)]; _search.backgroundImage = [PublicObj getImgWithColor:[UIColor whiteColor]]; _search.placeholder = @"搜索歌曲名称"; _search.delegate = self; UITextField *textField ; if (@available(iOS 13.0,*)) {

“contentsOfFile” returning nil, possible cause

↘锁芯ラ 提交于 2020-01-22 15:01:50
问题 The following returns nil when getting the content of a csv file. However, reducing the csv table to 10 rows will work properly, outputting the content of the csv file. The original csv has about 400,000 characters arranged in 500 rows and 11 columns. What could be causing it to return nil with the original csv? let dbPath = "/Volumes/Gios2TWD/myDB.csv" var error: NSError? let csvContent = NSString(contentsOfFile: dbPath, encoding:NSUTF8StringEncoding, error: &error) as String! println

“contentsOfFile” returning nil, possible cause

安稳与你 提交于 2020-01-22 15:01:27
问题 The following returns nil when getting the content of a csv file. However, reducing the csv table to 10 rows will work properly, outputting the content of the csv file. The original csv has about 400,000 characters arranged in 500 rows and 11 columns. What could be causing it to return nil with the original csv? let dbPath = "/Volumes/Gios2TWD/myDB.csv" var error: NSError? let csvContent = NSString(contentsOfFile: dbPath, encoding:NSUTF8StringEncoding, error: &error) as String! println

Transfer NSString between two devices via bluetooth in iOS

╄→尐↘猪︶ㄣ 提交于 2020-01-22 06:58:33
问题 I want to transfer NSString between two iOS device, via bluetooth. Can anybody please help how to do transfer NSString via bluetooth? I searched for specific answer and for sample code, but couldn't find it. Please guide me. Thanks in Advance.!! 回答1: I'm going to comment more extensively on how you can use MCSession for this sort of simple case since when I was first familiarizing myself with MCSession , I was amazed at how little information was available on how to utilize a simple MCSession

Transfer NSString between two devices via bluetooth in iOS

旧巷老猫 提交于 2020-01-22 06:53:46
问题 I want to transfer NSString between two iOS device, via bluetooth. Can anybody please help how to do transfer NSString via bluetooth? I searched for specific answer and for sample code, but couldn't find it. Please guide me. Thanks in Advance.!! 回答1: I'm going to comment more extensively on how you can use MCSession for this sort of simple case since when I was first familiarizing myself with MCSession , I was amazed at how little information was available on how to utilize a simple MCSession

Transliterate/transpose the characters in the NSString

☆樱花仙子☆ 提交于 2020-01-22 05:51:26
问题 I want to transliterate a cyrillic string to it's closest latin equivalent. E.g. "матрешка" => "matreshka", "водка" => "vodka". So ideally I want some ready to use method on the NSString or somewhere else that already knows everything about the alphabets and can do the conversation. But if such functionality doesn't exist in the iOS APIs then I will be totally happy with something like ruby's tr method that just replaces the characters in a string using a simple mapping specified as a

iOS进阶之两个模型数组的去重方法

陌路散爱 提交于 2020-01-22 04:06:46
  经常会遇到两个数组去对比然后进行去重的计算,看了网上很多文章,都是简单的两个数组的情况,很少有介绍两个模型数组的去重,于是自己写一点自己的经验吧。   首先准备一个模型对象,这里以Person为例,对象拥有name属性: @interface Person : NSObject /** 姓名 */ @property(nonatomic, copy) NSString *name; @end   然后分别准备两个模型数组,存放一些模型数据: NSMutableArray *arr_1 = [NSMutableArray array]; for (NSInteger i = 0; i < 1000; i++) { Person *p = [[Person alloc] init]; p.name = [NSString stringWithFormat:@"name_%zd", i]; [arr_1 addObject:p]; } NSMutableArray *arr_2 = [NSMutableArray array]; for (NSInteger i = 0; i < 1000; i++) { if (i % 2 == 0) { Person *p = [[Person alloc] init]; p.name = [NSString stringWithFormat:@

使用dSYM分析App崩溃日志

狂风中的少年 提交于 2020-01-21 22:25:04
前言 我们在开发App过程中,因为连接到控制台,所以遇到问题会很容易找到问题代码。但是对于线上的App出现Crash的时候,我们不可能通过这种方式,也不现实,所以我们只能通过收集Crash信息,来解决Bug。而这种收集Crash信息并且分析定位到具体代码的第三方SDK很多。但是今天我们来自己实现一下。 收集 Crash 信息 Apple 提供了 NSException 类来帮助我们收集异常信息。 NSException is used to implement exception handling and contains information about an exception — Apple Documentation. 点击这里 来查看官方文档具体内容。 我们的确可以通过 NSException 来收集信息,但是,我们怎么把这个信息保存下来,并且上传到我们后台服务器,收集起来呢。这就需要用到另一个函数: NSUncaughtExceptionHandler Sets the top- level error-handling function where you can perform last-minute logging before the program terminates. http://www.90168.org/