nsstring

How do you convert an NSUInteger into an NSString?

有些话、适合烂在心里 提交于 2019-12-10 12:28:28
问题 How do you convert an NSUInteger into an NSString ? I've tried but my NSString returned 0 all the time. NSUInteger NamesCategoriesNSArrayCount = [self.NamesCategoriesNSArray count]; NSLog(@"--- %d", NamesCategoriesNSArrayCount); [NamesCategoriesNSArrayCountString setText:[NSString stringWithFormat:@"%d", NamesCategoriesNSArrayCount]]; NSLog(@"=== %d", NamesCategoriesNSArrayCountString); 回答1: When compiling with support for arm64 , this won't generate a warning: [NSString stringWithFormat:@"

Convert NSData [UIImage] to a NSString

假装没事ソ 提交于 2019-12-10 12:00:45
问题 I am aware this question has been asked several times, but I was unable to find a definate answer that would best fit my situation. I want the ability to have the user select an image from the library, and then that image is converted to an NSData type. I then have a requirement to call a .NET C# webservice via a HTTP get so ideally I need the resulting string to be UTF8 encoded. This is what I have so far: NSData *dataObj = UIImageJPEGRepresentation(selectedImage, 1.0); [picker

stringWithContentsOfURL cookie jar in El Capitan

坚强是说给别人听的谎言 提交于 2019-12-10 11:34:20
问题 I have a small open source application. I used [NSString stringWithContentsOfURL] to download website's html and check if user has been logged in in Safari. Before El Capitan everything was working fine: stringWithContentsOfURL used sharedCookiesStorage (Safari ones) and returned the html of the page as logged in user. But in El Capitan this is not working this way: stringWithContentsOfURL returns the html of the page, where the user is not logged in. So it doesn't use Safari's cookies

Parse Query String into a Structured NSDictionary

荒凉一梦 提交于 2019-12-10 11:33:40
问题 I have a query string: a=1&b=2&c[1]=3&c[2]=4 etc… I want a NSDictionary where a => 1 , b => 2, c => [3,4] . Notice that that the value for c is an array. It should also be able to handle something like c[1][2]=5 to make an array of arrays c => [[5]] . Of course I can do it myself by splitting on the & and = , but what about other cases such as arrays and arrays of arrays. I want a structured NSDictionary from a POST request queryString and do not want to rewrite the wheel if this already

Shorten an NSString?

£可爱£侵袭症+ 提交于 2019-12-10 11:27:49
问题 I have a very simple question. Is there a built in method to shorten strings? If not can someone provide an example of doing that in ObjC ? For example: ThisIsAVeryLongString should become ThisIsAV... It needs to check if the string is over a certain amount of characters and if it is shorten it. 回答1: It's pretty straightforward... NSString *originalString = @"SomethingVeryLong"; int newLength = 9; if (originalString.length > newLength) NSString *shortString = [originalString substringToIndex

Objective-C中实现“多继承”

╄→гoц情女王★ 提交于 2019-12-10 11:14:20
当单继承不够用,很难为问题域建模时,我们通常都会直接想到多继承。多继承是从多余一个直接基类派生类的能力,可以更加直接地为应用程序建模。但是Objective-C不支持多继承,由于消息机制名字查找发生在运行时而非编译时,很难解决多个基类可能导致的二义性问题。不过其实 Objective-C 也无需支持多继承,我们可以找到如下几种间接实现多继承目的的方法: 1)消息转发 2)delegate和protocol 3)类别 1、利用消息转发实现见本人另一篇博客 http://my.oschina.net/Jacedy/blog/625343 ; 2、 委托是Objective-C中最常用的一种回调机制,没什么好说的; 3、 类别是个强大的东西,它可以为类添加方法,虽然它不能直接为类添加属性,但可以使用 runtime 中的objc_setAssociatedObject 和 objc_getAssociatedObject 方法间接为类添加属性。 Person类为一新建的空类,现在利用类别为Person类添加 (nonatomic, copy) NSString *addr 属性: // Person+Teacher.h #import "Person.h" @interface Person (Teacher) - (void)setAddr:(NSString *)addr; -

Convert NSString to NSArray [duplicate]

一曲冷凌霜 提交于 2019-12-10 11:08:31
问题 This question already has answers here : Comma-separated string to NSArray in Objective-C (2 answers) Closed 6 years ago . I have one string as follows: NSString *str = @"abcd,efgh"; Now I want to convert this string into NSMutableArray like NSMutableArray *arr = {abcd,efgh}; then how can I do this? any help would be appreciated. 回答1: NSArray *arr = [@"abcd,efgh" componentsSeparatedByString:@","]; should do the job. 来源: https://stackoverflow.com/questions/15271450/convert-nsstring-to-nsarray

Drawing a checkmark NSString with UIKit doesn't respect fill color

允我心安 提交于 2019-12-10 10:49:49
问题 I'm trying to draw a checkmark in green with UIKit, but it is drawn in black instead. Here is the code: [[UIColor greenColor] set]; [@"✔" drawAtPoint:CGPointZero withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; Other strings are properly drawn in green with this method. I suspect that the checkmark glyph contains color information that overrides my choice of fill color, but drawing the same glyph with color in an UIWebView works. Is there a way to get the checkmark drawn in green

Encrypt NSString using AES-128 and a key

雨燕双飞 提交于 2019-12-10 10:43:48
问题 I have a basic notes app, and I want to allow the user to have encrypted or secure notes. I have an UI whipped up, but right now, I can't seem to get encryption working. Either it returns me a bunch of garbage or nothing at all. This is what I use to en/decrypt: - (BOOL) encryptWithAES128Key: (NSString *) key { // 'key' should be 16 bytes for AES128, will be null-padded otherwise char * keyPtr[kCCKeySizeAES128+1]; // room for terminator (unused) bzero(keyPtr, sizeof(keyPtr)); // fill with

NSString strip regular \ escape characters how?

荒凉一梦 提交于 2019-12-10 10:43:25
问题 I need an efficient piece of code that strips escape characters. This is regular escapes not HTML escape characters. Example: "\"", "\\\\", "\", "\\" I want a general algorithm to strip any kind of escape sequences. Could use any utility like regular expression. (NSString*) unescape:(NSString*) string { .... } This is the answer I wrote: -(NSString*) unescape:(NSString*) string { for(int i = 0; i < string.length; i++) { char a = [string characterAtIndex:i]; if([string characterAtIndex:i] == '