nsstring

iOS SecKeyRef from NSString

柔情痞子 提交于 2019-12-10 17:52:36
问题 I need to encrypt a user password to base64 string using a public key. The public key is a NSString. Something like this: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCgWO7p1AvCaHUeaM6rSczBBAqt mKObHxGW3VgTom2zGwswGj9t/Hr7NdJQCGAiq0ijcW9/oYnM/JobbsyEijHKqIQm OVMsV4JRoG68PEDszH/ebkqWhzu7vG9IQ6VYIkaKHqk7cg+mQ1qFDoigOooFJ2Pf Uzbmg+Z/DuYDuwg+bwIDAQBC" How do I make a SecKeyRef from it ? I found a tutorial here But I couldn't make it work because SecCertificateCreateWithData always return nil. This is

encoded nsdata utf8 json, with accented char in ios

风流意气都作罢 提交于 2019-12-10 17:45:15
问题 i make a post request to a webserver that answer me with a JSON, this is the header of the response : Cache-Control: private Content-Length: 826 Content-Type: application/json; charset=utf-8 Date: Wed, 04 Feb 2015 05:53:59 GMT Server: Microsoft-IIS/8.5 Set-Cookie: ASP.NET_SessionId=0w0mile5232yoqqdlcdomwgf; path=/; HttpOnly X-Aspnet-Version: 4.0.30319 X-Powered-By: ASP.NET i parse the data response (NSURLConnection) and serialize the json : NSArray *arrayFromServer = [NSJSONSerialization

IOS 字典模型互转框架 MJExtension

点点圈 提交于 2019-12-10 16:58:59
详细轻参考: https://github.com/CoderMJLee/MJExtension 功能很牛掰 能做什么? MJExtension是一套 字典和模型之间互相转换 的超轻量级框架 MJExtension能完成的功能 字典(JSON) --> 模型(Model) 模型(Model) --> 字典(JSON) 字典数组(JSON Array) --> 模型数组(Model Array) 模型数组(Model Array) --> 字典数组(JSON Array) 详尽用法主要参考 main.m中的各个函数 以及 NSObject+MJKeyValue.h MJExtension和JSONModel、Mantle等框架的区别 转换速率: 最近一次测试表明: MJExtension > JSONModel > Mantle 各位开发者也可以自行测试 具体用法: JSONModel :要求所有模型类 必须 继承自JSONModel基类 Mantle :要求所有模型类 必须 继承自MTModel基类 MJExtension : 不需要 你的模型类继承任何特殊基类,毫无污染,毫无侵入性 如何使用MJExtension cocoapods导入: pod 'MJExtension' 手动导入: 将 MJExtensionExample/MJExtensionExample

Convert UIImage to NSString (and vice-versa)

梦想与她 提交于 2019-12-10 16:14:06
问题 I need a method to convert a UIImage in a NSString and then convert the NSString back to a UIImage. Thanks. 回答1: for >= IOS 7 - (NSString *)imageToNSString:(UIImage *)image { NSData *imageData = UIImagePNGRepresentation(image); return [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; } - (UIImage *)stringToUIImage:(NSString *)string { NSData *data = [[NSData alloc]initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters];

Objective-C NSString Question

核能气质少年 提交于 2019-12-10 16:08:02
问题 I need to return a NSString from a function: NSString myfunc ( int x ) { // do something with x NSString* myString = [NSString string]; myString = @"MYDATA"; // NSLog(myString); return *myString; } So, I call this function and get *myString. Is that a pointer to the data? How can I get to the data "MYDATA"? 回答1: I would rewrite this function the following way: NSString* myfunc( int x ) { NSString *myString = @"MYDATA"; // do something with myString return myString; } In Objective-C it is more

MFMessageComposeViewController not working

谁都会走 提交于 2019-12-10 15:45:05
问题 I have a simple method that gets one argument and then sends a message. It is not working. Code: - (void)sendSMS:(NSString *)text { MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init]; viewController.body = text; viewControllerM.mailComposeDelegate = self; [self presentViewController:viewController animated:YES completion:nil]; } What's wrong? 回答1: You need to set the delegate: MFMessageComposeViewController *controller = [[

How do I use % character in NSString stringWithFormat

╄→尐↘猪︶ㄣ 提交于 2019-12-10 15:11:44
问题 How do I use the % character literal in an NSString stringWithFormat ? I am trying to do: [NSString stringWithFormat:@"%%@,%@",string1,string2]; The first % does not show up. 回答1: [NSString stringWithFormat:@"%%%@,%@",string1,string2]; 回答2: Two percent charicters, %%, will print as one %. From the String Format Specifiers list. 回答3: Try this: [NSString stringWithFormat:@"%@%%",str1]; 回答4: Using % two times (as escape character) should give you what you need. An example printing %foo,bar would

What does the \? (backslash question mark) escape sequence mean?

我的梦境 提交于 2019-12-10 14:24:17
问题 I'm writing a regular expression in Objective-C. The escape sequence \w is illegal and emits a warning, so the regular expression /\w/ must be written as @"\\w" ; the escape sequence \? is valid, apparently, and doesn't emit a warning, so the regular expression /\?/ must be written as @"\\?" (i.e., the backslash must be escaped). Question marks aren't invisible like \t or \n , so why is \? a valid escape sequence? Edit: To clarify, I'm not asking about the quantifier, I'm asking about a

How to determine which part of an nsstring fits into a rect?

人走茶凉 提交于 2019-12-10 13:41:40
问题 This is about PDF formatting using core graphics. But it could be about any type of paging when it comes to printing a string on two pages. I need to spread a string over several pages. For smaller strings this is no real problem. For those I use the NSString UIKit extensions sizeWithFont to determine, whether the full text fits on the current page or not. If it does, then I print it with drawInRect and if it does not then I move it to the next page. Works fine but is not suitable for longer

String literals without having to escape special characters?

大城市里の小女人 提交于 2019-12-10 13:16:51
问题 Is there a string literal form in Objective-c that does not require escaping special characters? In other words, I'm looking for an equivalent to the Python triple quote. I'm trying to put some HTML into an NSString , and would like to avoid having to escape the quotes from all the HTML attributes. 回答1: There's no equivalent to the triple-quote; string literals must always use escapes for special characters. Perhaps the best thing to do would be to put your HTML into a file separate from your