nsstring

Swift how to compare string which come from NSString

喜你入骨 提交于 2019-12-13 08:21:00
问题 I get a return number(0 for success, 1 for failure) form sever made by php so I want get this number to judge my operation succeeded or not. I use this : var str1 :String = NSString(data: d, encoding: NSUTF8StringEncoding)! let str2 = "1" println(str1) // output is 1 println(str2) // output is 1 if(str1==str2){println("same")} //but the two is not same so I debug for this and I get this result: //str1 _countAndFlags UWord 13835058055282163717 -4611686018427387899 //str2 _countAndFlags UWord 1

What is the fastest way to convert a long long to NSString

[亡魂溺海] 提交于 2019-12-13 08:17:35
问题 I need to convert a lot of long long's to NSString. What is the fastest way to do this? I am aware of two ways to do this and I am wondering if there is anything else that would be faster. NSString* str = [NSString stringWithFormat:@"%lld", val]; And NSString* str = [[NSNumber numberWithLongLong:val] stringValue]; where val is a long long (64 bit int). The first method has the small overhead of parsing the string and the second has the overhead of allocating an additional object. Most likely

How to get a UIImage's image as an NSString?

回眸只為那壹抹淺笑 提交于 2019-12-13 07:37:07
问题 I need to get the value of a UIImage's image as a string. Previously I was doing: if(images[imageNo].image == [UIImage imageNamed:@"image1.png"]) { But now I have a lot more conditions so I would like to use a switch, doing: switch(images[imageNo].image) { case @"image1.png": break; } Is there a way to achieve this? Thanks! 回答1: Both of your approaches are incorrect. The first one relies on caching (which is not documented), meanwhile the second is a syntax error - the 'case' keywords expect

Objective-C constants in protocol

送分小仙女□ 提交于 2019-12-13 07:32:29
问题 In my objective-c project, I have a protocol like this: @protocol MyProtocol -(id) get:(NSString *) key; -(void) set:(NSString *) key withValue:(id) value; -(NSValue *) getSize; -(void) setSize:(NSValue *) value; -(NSValue *) getBounds; -(void) setBounds:(NSValue *) value; @end OBJC_EXPORT const NSString *MYPROTOCOL_SIZE; OBJC_EXPORT const NSString *MYPROTOCOL_BOUNDS; And basically, those specific methods ( getSize , getBounds , setSize , setBounds ) are supposed the value that is supposed to

How to use NSRange or NSScanner in iOS

流过昼夜 提交于 2019-12-13 07:14:34
问题 I have a string like: 1 this is my first text 2 his is my second 3 this is my third 4 this is my forth etc etc.. Each sentence is between the numeric characters like 1 2 3 4 etc When I tap the first sentence, it needs to dissect it and copy it in clipboard or something. How can we use he NSScanner or NSRange to calculate the string size or identify strings between the numeric characters. self.multiPageView.text =combined; the combined contains the text like above ,,so when i tap the first

Issue comparing NSString literal and constant

空扰寡人 提交于 2019-12-13 07:01:05
问题 I have an NSString , firstWord , that has the value of "First". It was defined like this: NSString *firstWord = [[NSString alloc] init]; firstWord = [textView text]; However, when I try to check its value, like so: if (firstWord == @"First"){} The comparison does not return true, or YES I guess in Objective-C. I know that it does have the same value as a string. So, from this I am pretty sure that the issue is that I am comparing pointers, which are not the same here, even though the strings

How to retrieve string from NSData stored in sqlite?

爷,独闯天下 提交于 2019-12-13 06:59:45
问题 Note: I have stored NSData in local database. I want to use it back from local database. But as it is stored in local database as text ,facing issue in converting back it into NSData . strDbData is object of type NSString here. I have one NSData stored in local database like <a3829c97 3b1efacb c7680f7e 7e7a95a2> Now I want to retrive it back, so I am doing as mentioned below but I am receiving error. 1) First way NSData *myData = (NSData*)strDbData; NSLog(@"%@",[myData class]); Error : -[_

Failure to write NSString to file on iPad

会有一股神秘感。 提交于 2019-12-13 06:42:37
问题 I'm using a text file to save the changes made by a user on a list (the reason that I'm doing this is so that I can upload the text file to a PC later on, and from there insert it into an Excel spreadsheet). I have 3 data structures: A NSMutableArray of keys, and a NSMutableDictionary who's key values are MSMutableArrays of NSStrings. I iterate through these data structures and compile a file string that looks much like this: (Key);(value)\t(value)\t(value):\n(Key);(value).. .so on. SO, onto

Trouble with newline character while programming for the iPhone

╄→гoц情女王★ 提交于 2019-12-13 06:38:04
问题 I'm storing text in a sqlite file and setting the text of a UITextView to be the value of that text. The only problem is that the UITextView isn't honoring the newline character. Instead, it's printing it out as text. Here's an example: Stored in fruit.sqlite and passed to theFruit object: requiredFruit = "apples\n oranges\n pears" NSString *theFruit = [NSString stringWithFormat:@"%@", theFruit.requiredFruit]; generalOutlet.text = theFruit; It Displays apples\n oranges\n pears but I want it

Cast NSString(contentsOfURL:…) to String?

99封情书 提交于 2019-12-13 06:01:08
问题 public convenience init(nsurl:NSURL) { var enc:NSStringEncoding = NSUTF8StringEncoding var err:NSError? let str:String? = NSString( contentsOfURL:nsurl, usedEncoding:&enc, error:&err ) if err != nil { self.init(err!) } else { self.init(string:str!) } } Swift is version 1.2, error message is: NSString? is not convertible to string 回答1: With Swift 1.2 automatic bridging between String and NSString has been removed. So you have to explicitly do the cast : let str = NSString(contentsOfURL:nsurl,