nsstring

Using NSPredicate to determine if a string equals another string

十年热恋 提交于 2019-11-29 02:50:23
I have an NSArray of CalEvents returned with the [CalCalendarStore eventPredicateWithStartDate] method. From the events returned, I am trying to keep only those in which the title of the event == @"on call" (case-insensitive). I am able to keep in the array those events whose title includes @"on call" with the following code (where 'events' is a 'NSArray' populated with CalEvents ): NSPredicate *onCallPredicate = [NSPredicate predicateWithFormat:@"(SELF.title CONTAINS[c] 'on call')"]; [events filteredArrayUsingPredicate:onCallPredicate]; I've tried using a predicate format string like: @"SELF

NSString stringWithFormat adding a percent [duplicate]

╄→гoц情女王★ 提交于 2019-11-29 02:49:38
This question already has an answer here: How to add percent sign to NSString 7 answers How can I add a percent to my stringWithFormat function? For example, I'd like to have the following: float someFloat = 40.233f; NSString *str = [NSString stringWithFormat:@"%.02f%",someFloat]; This should cause the string to be: 40.23% But it is not the case. How can I achieve this? % being the character beginning printf-style formats, it simply needs to be doubled: float someFloat = 40.233f; NSString *str = [NSString stringWithFormat:@"%.02f%%",someFloat]; spolu The escape code for a percent sign is “%%”,

Position of a character in a NSString or NSMutableString

半城伤御伤魂 提交于 2019-11-29 02:47:48
问题 I have searched for hours now and haven't found a solution for my problem. I have a NSString which looks like the following: "spacer": ["value1", "value2"], "spacer": ["value1", "value2"], ... What I want to do is to remove the [ ] characters from the string. It's seems to be impossible with objective-c. Most other programming languages offer functions like strpos or indexOf which allow me to search for a character or string and locate the position of it. But there seems nothing to be like

When not to alloc and init an NSString

房东的猫 提交于 2019-11-29 02:32:51
Whenever I need to create a new NSString variable I always alloc and init it. It seems that there are times when you don't want to do this. How do you know when to alloc and init an NSString and when not to? Whenever I need to create a new NSString variable I always alloc and init it. No, that doesn't make sense. The variable exists from the moment the program encounters the point where you declare it: NSString *myString; This variable is not an NSString. It is storage for a pointer to an NSString. That's what the * indicates: That this variable holds a pointer. The NSString object exists only

how to Check NSString is null or not [duplicate]

拥有回忆 提交于 2019-11-29 02:14:53
问题 This question already has answers here : How to detect if NSString is null? (5 answers) Closed 6 years ago . I want to check weather a NSString is null or not. Im assigning from an JSON array. After assigning that string value is <null> . Now I want to check this string is null or not. So I put like this if (myStringAuthID==nil) but this if statement always false. How I can check a string for null. Please help me Thanks 回答1: Like that: [myString isEqual: [NSNull null]]; 回答2: There are three

Easiest way to concatenate NSString and int

旧城冷巷雨未停 提交于 2019-11-29 01:52:38
问题 Is there a general purpose function in Objective-C that I can plug into my project to simplify concatenating NSString s and int s? 回答1: Both answers are correct. If you want to concatenate multiple strings and integers use NSMutableString's appendFormat. NSMutableString* aString = [NSMutableString stringWithFormat:@"String with one int %d", myInt]; // does not need to be released. Needs to be retained if you need to keep use it after the current function. [aString appendFormat:@"... now has

What is the equivalent of NSLineBreakMode in iOS 7 attributed strings drawing methods?

心不动则不痛 提交于 2019-11-29 01:42:10
问题 There was a method - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment; which I must replace now for iOS 7. I get as far as NSDictionary *attributes = @{NSFontAttributeName: font}; [self drawInRect:rect withAttributes:attributes]; but how to specify the line break mode like word wrap? I searched documentation of Attributed string drawing symbols but no mention of line break mode. Is this automartically

Getting Optional(“”) when trying to get value from KeyChain

一世执手 提交于 2019-11-29 01:32:49
When I try to get my keyChain value, it return a string containing: Optional("[thing in the KeyChain]") so, I tried to remove "Optional" by using a loop: var str = KeychainService.loadToken() for(var i = 0; i < 9 ; i++) { str[i] = "" } But i get a error: NSString does not have a member named 'subscript' The KeychainService class: import Foundation import Security let serviceIdentifier = "MySerivice" let userAccount = "authenticatedUser" let accessGroup = "MySerivice" // Arguments for the keychain queries let kSecClassValue = kSecClass.takeRetainedValue() as NSString let kSecAttrAccountValue =

Get from AnyObject(NSString) to String

倾然丶 夕夏残阳落幕 提交于 2019-11-29 00:59:17
问题 I am reading a plist key (NSArray with n NSDictionaries): let regionsToMonitor = NSBundle.mainBundle().infoDictionary["Regions"] as Array<Dictionary<String,AnyObject>> now I iterate over it: for regionToMonitor in regionsToMonitor { and now I want to to get uuidString of the regionToMonitor in ObjC: NSString *uuidString = regionToMonitor[@"uuidString"]; in swift I try: let uuidString = regionToMonitor["uuid"]!.stringValue; the above does compile but the string is always nil in swift.

How do I save an NSString as a .txt file on my apps local documents directory?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 00:45:38
问题 How do I save an NSString as a .txt file on my apps local documents directory (UTF-8)? 回答1: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory NSError *error; BOOL succeed = [myString writeToFile:[documentsDirectory stringByAppendingPathComponent:@"myfile.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error]; if (!succeed){ // Handle error here } 回答2: