nsstring

Why dereferencing a NSString pointer is not necessary?

做~自己de王妃 提交于 2019-11-27 01:59:33
问题 In the example NSString *message = @"Hello"; message = @"World"; If message is just a pointer why don't I need to explicitly say whatever is in message is now equal to string or *message = @"World"; like in C? 回答1: DISCLAIMER The discussion below gives a general idea on why you never dereferenciate a pointer to an object in Objective-C. However, concerning the specific case of NSString literals, this is not what's happening in reality. While the structure described below is still sound and it

ios drawRect NSString 绘制

隐身守侯 提交于 2019-11-27 01:56:17
- (void)drawRectFor7 { #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0 UIFont *font = [UIFont boldSystemFontOfSize:_fontSize]; NSDictionary *attributes = nil; NSDictionary *strokeAttributes = nil; if (_useLightText) { strokeAttributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, _strokeColor, NSStrokeColorAttributeName, @-10.0, NSStrokeWidthAttributeName, nil]; attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, _lightColor, NSForegroundColorAttributeName, nil]; } else { attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,

How to convert NSString HTML markup to plain text NSString?

 ̄綄美尐妖づ 提交于 2019-11-27 01:55:24
问题 Been searching the net for an example of how to convert HTML string markup into Plain text. I get my information from a feed which contains HTML , I then display this information in a Text View. does the UITextView have a property to convert HTML or do I have to do it in code. I tried: NSString *str = [NSString stringWithCString:self.fullText encoding:NSUTF8StringEndcoding]; but doesn't seem to work. Anyone got any ideas? 回答1: You can do it by parsing the html by using NSScanner class -

Compare two NSStrings

主宰稳场 提交于 2019-11-27 01:50:15
问题 In my app there is a mechanism that requires that at a certain point two NSString s will be the same to do something; for some reason when I compare the two, even when they are the same, it still doesn't recognize that. The code is something like this: NSString * aString = [self someMethodThatGetsAString]; NSString * bString; BOOL areStringsTheSame = NO; while (areStringsTheSame != YES) { bString = [self someMethodThatTakesNSStringsFromAnArrey]; if (bString == aString) { areStringsTheSame =

What is the maximum length of an NSString object?

喜你入骨 提交于 2019-11-27 01:48:42
What is the maximum sized string that can be held in a NSString object? Does this change dynamically? I would assume the hard limit for NSString would be NSUIntegerMax characters, since NSString's index and size-related methods return an NSUInteger. Since all devices currently capable of running iOS are 32 bit, this means NSUIntegerMax is 2^32 - 1 and NSString can hold a little over 4.2 billion characters. As others have pointed out, though, the practical limit is much smaller - on an iOS device especially, you'll run out of memory long before you hit any hard limit in NSString. NSString is

NSString initWithData returns null

风格不统一 提交于 2019-11-27 01:47:46
问题 I am pulling data from a website via NSURLConnection and stashing the received data away in an instance of NSMutableData . In the connectionDidFinishLoading delegate method the data is convert into a string with a call to NSString's appropriate method: NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] The resulting string turns out to be a null. If I use the NSASCIIStringEncoding , however, I do obtain the appropriate string, albeit with unicode characters

sizeWithFont doesn't give correct height for UITextView if there is a long string in the text being wrapped

浪尽此生 提交于 2019-11-27 01:43:00
问题 Is there a way to get the correct size of an NSString using: - (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode that doesnt get thrown off by 2 or 3 hundred character strings. At the moment if I try to use this method on these long strings it incorrectly calculates them and I end up with lots of whitespace at the bottom of the UITextView. I've tried using UILineBreakModeWordWrap and UILineBreakModeCharacterWrap. the resizing is being

Can't convert NSData to NSString in swift

旧城冷巷雨未停 提交于 2019-11-27 01:41:12
问题 This is my function. First println print correct hash to console but in the next row program crashes. Can you help me? func sha256(string: NSString) -> NSString { var data : NSData! = string.dataUsingEncoding(NSUTF8StringEncoding) var hash = [UInt8](count: Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0) CC_SHA256(data.bytes, CC_LONG(data.length), &hash) let res = NSData(bytes: hash, length: Int(CC_SHA256_DIGEST_LENGTH)) println(res) let resstr = NSString(data: res, encoding:

iOS - Most efficient way to find word occurrence count in a string

女生的网名这么多〃 提交于 2019-11-27 01:39:55
问题 Given a string, I need to obtain a count of each word that appears in that string. To do so, I extracted the string into an array, by word, and searched that way, but I have the feeling that searching the string directly is more optimal. Below is the code that I originally wrote to solve the problem. I'm up for suggestions on better solutions though. NSMutableDictionary *sets = [[NSMutableDictionary alloc] init]; NSString *paragraph = [[NSString alloc] initWithContentsOfFile:[[NSBundle

How to create subscript characters that's not in Unicode in iOS

拜拜、爱过 提交于 2019-11-27 01:37:53
I've been trying for a while now to create a NSString with subscripted character without success. Is it even possible to do this in iOS? I need a way to change characters in a string to subscript or superscript, and I can't use the Unicode for this as Unicode doesn't have all the letters. My guess could be to use the HTML tags <sub> and <sup> but I haven't find a way to convert said HTML tags to a NSString. Subscript and superscript are not character traits. With few exceptions (e. g. ², ³, ª), this is the way regular characters are rendered - in a smaller font and above/below the regular