nsstring

Check for duplicate NSStrings on a NSMutableArray

眉间皱痕 提交于 2020-01-06 14:27:12
问题 I got a NSMutableArray which I want to add strings to. I need to check if that string already exists on the array before adding ths string to it. Does anyway know a good way to do it? Thanks! 回答1: If order doesn't matter, the simplest way would be to switch to using an NSMutableSet. Sets are unordered and NSSets and NSMutableSets can contain each object only once. Only a counted set (NSCountedSet) can contain the same object multiple times. If order does matter, continue using NSMutableArray,

Value of NSString returns null, but unsure why?

…衆ロ難τιáo~ 提交于 2020-01-06 13:52:35
问题 I've set the value of my NSString called "fid" to responseObject (see below). responseObject returns the data I want when NSLog'd, but for some reason when I NSLog fid further down, it's empty. Am I missing something? See code: .h @property (nonatomic, assign) NSString *fid; .m [DIOSFile fileSave:file success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"File uploaded!"); [file setObject:[responseObject objectForKey:@"fid"] forKey:@"fid"]; [file removeObjectForKey:@"file"]

Value of NSString returns null, but unsure why?

北战南征 提交于 2020-01-06 13:52:15
问题 I've set the value of my NSString called "fid" to responseObject (see below). responseObject returns the data I want when NSLog'd, but for some reason when I NSLog fid further down, it's empty. Am I missing something? See code: .h @property (nonatomic, assign) NSString *fid; .m [DIOSFile fileSave:file success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"File uploaded!"); [file setObject:[responseObject objectForKey:@"fid"] forKey:@"fid"]; [file removeObjectForKey:@"file"]

Obj-C, NSScanner: nil string argument, suddenly getting this warning, how do I fix it?

让人想犯罪 __ 提交于 2020-01-06 12:43:10
问题 I'm suddenly getting this warning NSScanner: nil string argument in the debug window. I say suddenly, but I've no idea from which code has caused it. How do I resolve this problem ? 回答1: You check if the string is nil before creating the NSScanner with it, as you are probably creating it with + (id)scannerWithString:(NSString *)aString or - (id)initWithString:(NSString *)aString There is no way of changing the NSScanner string, once it has been created, the compiler is just telling you that

Sharing immutable NSStrings

一个人想着一个人 提交于 2020-01-06 12:36:56
问题 I have a list of about 10k dictionaries, each dictionary contains about 50 keys. Keys are more or less the same for all dictionaries. The data is loaded using NSDictionary.alloc.initWithContentsOfFile. It seems that the key objects are reused between different dictionaries, and thus instead of having about 500k strings in memory, I have only one string per unique key, thus just a couple hundreds of them. So I wonder if it is an expected behavior of initWithContentsOfFile method and I can rely

Sharing immutable NSStrings

别来无恙 提交于 2020-01-06 12:36:16
问题 I have a list of about 10k dictionaries, each dictionary contains about 50 keys. Keys are more or less the same for all dictionaries. The data is loaded using NSDictionary.alloc.initWithContentsOfFile. It seems that the key objects are reused between different dictionaries, and thus instead of having about 500k strings in memory, I have only one string per unique key, thus just a couple hundreds of them. So I wonder if it is an expected behavior of initWithContentsOfFile method and I can rely

NSString compare is throwing exception SIGABT

大兔子大兔子 提交于 2020-01-06 08:01:18
问题 I have following code, where I'm comparing two string but its throwing exception. - (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d { NSLog(@"calendarMonthView didSelectDate %@",d); //[self papulateTable]; //[table reloadData]; //[self performSelector:@selector(papulateTable) withObject:nil afterDelay:1.0]; NSString *tempDate = (NSString*)d; NSString *selectedDate = @"2013-02-04 00:00:00 +0000"; if([tempDate isEqualToString:selectedDate]) {

Attributed UITextView doesn't work with Korean symbols

空扰寡人 提交于 2020-01-06 07:34:47
问题 Attributed UITextView doesn't work with Korean symbols. Steps to reproduce: Add UITextView to the form. Use the following code: NSDictionary *attributes = @{ NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue" size:15], NSForegroundColorAttributeName:[UIColor blackColor]}; [textView setAttributes:attributes range:NSMakeRange(0, textView.text.length)]; Run the application, type any text on Korean (에서 보냄) and tap or press Enter. The Korean text will disappear or will be replaced by

Problem with access to string from another class

孤人 提交于 2020-01-06 03:56:05
问题 Hi i have two view controller: FirstViewController and SecondViewController FirstViewController.h #import <UIKit/UIKit.h> @interface FirstViewController: { NSString *prStr; } -(IBAction)setString; @property (nonatomic, retain) NSString *prStr; @end FirstViewController.m #import"FirstViewController.h" @implementation FirstViewController @synthesize prStr; -(IBAction)setString{ prStr = [[NSString alloc]initWithFormat:@"1"]; } SecondViewController.h #import <UIKit/UIKit.h> @class

OC文件管理NSFileManager与文件读写NSFileHandle

喜你入骨 提交于 2020-01-05 23:54:22
/* 文件管理与读写操作 */ /* NSFileManager 类文件管理器常用操作 */ // 首先要创建一个文件管理器: NSFileManager * fm =[NSFileManager defaultManager ]; // 创建管理对象 浅度遍历目录,当前目录 - contentsOfDirectoryAtPath:error: 深度遍历目录 - subpathsOfDirectoryAtPath:error: 创建目录 - createDirectoryAtPath:withIntermediateDirectories:attributes:error: 创建文件 – createFileAtPath:contents:attributes: 删除文件(包括目录) - removeItemAtPath:error: 目录/文件拷贝 - (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error 移动/重命名文件或者目录 – moveItemAtPath:toPath:error: 测试文件是否存在 - (BOOL)fileExistsAtPath:(NSString *)path 获取文件信息 ( 属性和权限 ) -