Tag: nsstring

测量NSString中每个字符的大小

我们有[NSString sizeWithFont:]它返回整个string的大小。 如何获得string中每个单独字符的大小数组? 你会怎么做(除了标记string和每个调用sizeWithFont)? 最好,万斯

在Block运行之前返回的NSString值

我试图使用一个块(“fid”)内的一个块内生成的值。 问题是,在块运行之前,值正在被拉动,所以即使数据存在,值也会返回为(null)。 有谁知道我可以做这个工作? 见代码: 。H @property (nonatomic, strong) NSString *fid; .M [DIOSFile fileSave:file success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"File uploaded!"); [file setObject:[responseObject objectForKey:@"fid"] forKey:@"fid"]; [file removeObjectForKey:@"file"]; fid = [responseObject objectForKey:@"fid"]; NSLog(@"%@",responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Failed to upload file!"); }]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject: [NSString stringWithFormat:@"%@", fid] forKey:@"fid"]; NSLog(@"%@", fid); […]

我应该如何保存一个大string,就像用户协议一样?

我可以使用像@"content"string文字,但我认为这是浪费内存。 有这种情况的自定义解决scheme吗? 我是一个新的Xcoder,所以可能这不是一个好问题,但是我对使用NSString非常困惑…

使用值的NSArray有效地创build占位符模板NSString

我正在尝试为FMDB提供一个实用方法,它将取值为NSArray,并根据数组中值的数量返回一个IN语句中使用的占位符的string。 我想不出创build这个string的优雅方式,我是否缺less一些NSString实用工具方法: // The contents of the input aren't important. NSArray *input = @[@(55), @(33), @(12)]; // Seems clumsy way to do things: NSInteger size = [input count]; NSMutableArray *placeholderArray = [[NSMutableArray alloc] initWithCapacity:size]; for (NSInteger i = 0; i < size; i++) { [placeholderArray addObject:@"?"]; } NSString *output = [placeholderArray componentsJoinedByString:@","]; // Would return […]

应用程序崩溃与exc_bad_access代码exception

让我介绍一下我的App的function,我使用推送通知和地址簿和CoreTelephony框架。 我在我的应用程序中做的是,当我得到推送通知,我保存在一个Appdelegatevariables(Incoming_NO)有效载荷的数字,如果没有这样的联系与这个数字,我会创build新的联系人并保存它。 当我收到呼叫时,同样的联系人名称会出现在我之前添加的,后来我允许用户编辑联系人,如果他想保存联系人或删除,当他编辑联系人,稍后当我收到推通知相同的号码我得到exc_bad_access (Incoming_NO)我已经启用僵尸,我得到了断点错误在同一地点.. 任何人都可以帮助我什么是问题。 Received notification: { aps = { alert = "Please help me-+918884718240"; sound = "beep.caf"; }; } 代码: NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"]; NSRange range=[alertValue rangeOfString:@":"]; NSString *param,*msg; NSRange range1=[alertValue rangeOfString:@":"]; if (range1.location != NSNotFound) { param = [alertValue substringFromIndex:range1.location + range1.length]; msg=[alertValue substringToIndex:range.location + range.length-1]; } else { range1=[alertValue […]

如何使用NSDateFormatter将NSString转换为NSDate?

我从Web服务获取date,如“2012-07-03 07:26:48”。 从webserviceparsing后,我保存在NSString中。 在将下面的代码中使用的NSString转换为NSDate时, NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSString *dateStr = @"2012-07-03 07:26:48"; NSDate *date = [dateFormatter1 dateFromString:dateStr]; NSLog(@"Date : %@", date); The NSLog value is "2012-07-03 01:56:48 +0000"; NSLog的值是“2012-07-03 01:56:48 +0000”; 我不知道为什么时间变了。 任何人都可以请帮我做这个?

CFStringRef到NSString ARC泄漏。 为什么?

我一直在寻找从CFStringRef到ARC的NSString的正确方法,以避免内存泄漏,一些主要投票答案build议: NSString * string = (__bridge NSString *)cfString; 我在这里使用这种方法,但是在分析应用程序时,我仍然在这个小方法中发现内存泄漏[见附图]。 所以,我不知道如何解决这个问题。 有人有解决这个问题? 谢谢 所以,显然在返回之前添加了CFRelease(ext)修复了漏洞。 问题是我不认为我完全理解了原因。 我认为这一行: NSString * extension = (__bridge NSString*)ext 将获得核心基金会分机string的所有权,并处理该版本。 任何人都可以解释这里究竟发生了什么?

UITextView中的不同颜色

我尝试在我的UITextView中添加不同颜色的string。 我写了这个代码 NSMutableAttributedString* attString = [[NSMutableAttributedString alloc]initWithString:view.text]; //view is my UITextView [attString addAttribute:(NSString*)kCTForegroundColorAttributeName value:[UIColor greenColor] range:(NSRange){attString.length-8, 8}]; view.attributedText = attString; 也许这是不正确的属性,你能告诉我什么属性改变文字颜色?

NSString到SecKeyRef

我正在使用此代码: https : //stackoverflow.com/a/19221754/849616 ,但不是一切都清楚。 我想使用公钥NSString *pubKey = "1111"来encryptionNSString *msg = "0000" NSString *pubKey = "1111" 。 因此,我正在更新常量: static const UInt8 publicKeyIdentifier[] = 1111; // i want to encrypt only, so private key doesn't matter and I'm not posting it here 在函数testAsymmetricEncryptionAndDecryption我已经更新: const char inputString[] = 0000 但结果是错误的。 是publicKeyIdentifier一个正确的地方把我的关键string..? 我应该怎么做,如果我的做法是错误的..?

localizedCaseInsensitiveContainsString在Swift中不可用

我试图使用iOS 8中引入的localizedCaseInsensitiveContainsString()方法: let match = text.localizedCaseInsensitiveContainsString(searchText) Swift编译器说: 'String'没有名为'localizedCaseInsensitiveContainsString'的成员 文档说: Swift在Stringtypes和NSString类之间自动桥接。 那么,这是怎么回事? 我知道我可以使用(title as NSString) 。 我只是想知道为什么。