nsstring

CamelCase to underscores and back in Objective-C

回眸只為那壹抹淺笑 提交于 2019-12-04 08:03:57
问题 I'm looking for a simple, efficient way to convert strings in CamelCase to underscore notation (i.e., MyClassName -> my_class_name) and back again in Objective C. My current solution involves lots of rangeOfString , characterAtIndex , and replaceCharactersInRange operations on NSMutableStrings, and is just plain ugly as hell :) It seems that there must be a better solution, but I'm not sure what it is. I'd rather not import a regex library just for this one use case, though that is an option

iOS App 内购 Demo

你。 提交于 2019-12-04 08:01:49
/*注意事项: 1.沙盒环境测试appStore内购流程的时候,请使用没越狱的设备。 2.请务必使用真机来测试,一切以真机为准。 3.项目的Bundle identifier需要与您申请AppID时填写的bundleID一致,不然会无法请求到商品信息。 4.如果是你自己的设备上已经绑定了自己的AppleID账号请先注销掉,否则你哭爹喊娘都不知道是怎么回事。 5.订单校验 苹果审核app时,仍然在沙盒环境下测试,所以需要先进行正式环境验证,如果发现是沙盒环境则转到沙盒验证。 识别沙盒环境订单方法: 1.根据字段 environment = sandbox。 2.根据验证接口返回的状态码,如果status=21007,则表示当前为沙盒环境。 苹果反馈的状态码: 21000App Store无法读取你提供的JSON数据 21002 订单数据不符合格式 21003 订单无法被验证 21004 你提供的共享密钥和账户的共享密钥不一致 21005 订单服务器当前不可用 21006 订单是有效的,但订阅服务已经过期。当收到这个信息时,解码后的收据信息也包含在返回内容中 21007 订单信息是测试用(sandbox),但却被发送到产品环境中验证 21008 订单信息是产品环境中使用,但却被发送到测试环境中验证 */ 开发内购功能,首先需要一个开发者账号,在 App store connect ->

converting an NSString with accented characters to a CString

核能气质少年 提交于 2019-12-04 07:49:18
I have an NSString with a value of Jose (an accent on the e). I try to convert it to a C string as follows: char str [[myAccentStr length] + 1]; [myAccentStr getCString:str maxLength:[myAccentStr length] + 1 encoding:NSUTF32StringEncoding]; but str ends up being an empty string. What gives? I tried UTF8 and UTF16 too. It gets passed to another function later on and when that funcsion calls lstrlen on it, the size comes out as zero. Sam The docs for NSString getCString:maxLength:encoding says: You can use canBeConvertedToEncoding: to check whether a string can be losslessly converted to

How to capitalize the first word of the sentence in Objective-C?

与世无争的帅哥 提交于 2019-12-04 07:40:20
问题 I've already found how to capitalize all words of the sentence, but not the first word only. NSString *txt =@"hi my friends!" [txt capitalizedString]; I don't want to change to lower case and capitalize the first char. I'd like to capitalize the first word only without change the others. 回答1: Here is another go at it: NSString *txt = @"hi my friends!"; txt = [txt stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[txt substringToIndex:1] uppercaseString]]; For Swift language: txt

static NSStrings in Objective-C

谁都会走 提交于 2019-12-04 07:36:18
I frequently see a code snippet like this in class instance methods: static NSString *myString = @"This is a string."; I can't seem to figure out why this works. Is this simply the objc equivalent of a #define that's limited to the method's scope? I (think) I understand the static nature of the variable, but more specifically about NSStrings, why isn't it being alloc'd, init'd? Thanks~ For the part of NSString alloc, init: I think first, it can be thought as a convenience, but it is not equally the same for [[NSString alloc] init]. I found a useful link here. You can take a look at that

NSString to NSDate conversion getting the wrong result [duplicate]

偶尔善良 提交于 2019-12-04 07:33:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Wrong time from NSDateFormatter NSDate is 5 hours off I am trying to convert NSString to NSDate with the code result = @"2012-02-09"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *dateFromString = [[NSDate alloc] init]; dateFromString = [dateFormatter dateFromString:result]; [dateFormatter release]; NSLog(@"date: %@", dateFromString); But

NSData to NString conversion problem

人盡茶涼 提交于 2019-12-04 07:25:01
I'm getting an HTML file as NSData and need to extract some parts of it. For that I need to convert it to NSString with UTF8 encoding. The thing is that this conversion fails, probably because the NSData contains bytes that are invalid for UTF8. I have tried to get the byte array of the data and go over it, but each time I come across non ASCII character (hebrew letters for example) I get jibrish. Help will be appreciated. UPDATE: To Gordon - the NSData generated like that: NSData *theData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];

“sending 'const NSString *' to parameter of type 'NSString *' discards qualifiers” warning

家住魔仙堡 提交于 2019-12-04 07:18:51
问题 I have Constants NSString, that I want to call like: [newString isEqualToString:CONSTANT_STRING]; Any wrong code here? I got this warning: sending 'const NSString *' to parameter of type 'NSString *' discards qualifiers How should these be declared? 回答1: You should declare your constant string as follows: NSString * const kSomeConstantString = @""; // constant pointer instead of: const NSString * kSomeConstantString = @""; // pointer to constant // equivalent to NSString const *

Reading a RTF file and parse plaintext

旧巷老猫 提交于 2019-12-04 06:33:10
问题 I am doing this to get the content of a file using NSOpenPanel, but I am getting a lot of weird stuff returned from the .rtf file I select. My panel code: var panel: NSOpenPanel = NSOpenPanel() var fileTypesArray: NSArray = ["txt", "rtf", "nil"] panel.canChooseFiles = true panel.allowedFileTypes = fileTypesArray as [AnyObject] panel.allowsMultipleSelection = false if panel.runModal() == NSModalResponseOK { var url = panel.URL!.path println(url) let path = url let expandedPath = path!

Core Data not saving NSString

本秂侑毒 提交于 2019-12-04 06:24:12
问题 Currently seeing an issue in my Core Data saving. For some reason a NSString isn't being saved properly, always returning 0 regardless. Below is my current code. appDelegate =(NotaciousAppDelegate *) [[UIApplication sharedApplication] delegate]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext]; NSArray *fetchedNotes; NSArray *notes = [object valueForKey:@"result"]; for (NSDictionary *singleNote in notes){