nsstring

week reference to autoreleased object not getting deallocated in case of NSString

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why temp object is not released and set to nil even though it is declared as __week . But in case of Person object its working as expected. Do NSString objects memory life cycle is handled differently? How? @interface Person : NSObject @property(nonatomic, strong) NSString *name; - (instancetype)initWithName:(NSString *)name; + (Person *)personWithName:(NSString *)name; @end @implementation Person - (instancetype)initWithName:(NSString *)name { if (self = [super init]) { self.name = name; } return self; } + (Person *)personWithName:(NSString

Objective-C: NSString not being entirely decoded from UTF-8

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm querying a web server which returns a JSON string as NSData . The string is in UTF-8 format so it is converted to an NSString like this. NSString *receivedString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; However, some UTF-8 escapes remain in the outputted JSON string which causes my app to behave erratically. Things like \u2019 remain in the string. I've tried everything to remove them and replace them with their actual characters. The only thing I can think of is to replace the occurances of UTF-8

Convert NSString into byte array iphone

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Hi I want to convert the NSString into Byte array. if I have string like "Hello" then it convert into byte like this {65,23,56,56,56}. thanks 回答1: Use -[NSString UTF8String] which returns const char* . Read the reference . A general tip: if you want to find if a class has a method which does something, look up the official reference! I mean, on the web, there's not only Stack Overflow, but the API provider's (i.e. Apple's or Microsoft's) official documentations! 回答2: NSData * bytes = [ test dataUsingEncoding : NSUTF8StringEncoding

Send JSON request with iOS

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having an issue when i'm trying to send JSON request with an iOS app. I have to send something like this : http://url/User/Create/{"newsletter" : 1,"password" : "sdsd", ...} But the request isn't valid when doing this on the app : NSURL *url = [NSURL URLWithString:@"http://url/User/Create/"]; NSData *jsonData; NSDictionary *dic = @{ @"login" : @"sdsd", @"password" : @"sdsd", @"newsletter" : @1, @"firstname" : @"sdsd", @"lastname" : @"sdsd", @"email" : @"sdsd@hotmail.fr"}; jsonData = [NSJSONSerialization dataWithJSONObject:dic options:0

Check iOS Simulator type and version

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have following code snip to detect the iOS Device. NSString * platformNSString () { size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *machine = malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0); NSString *platform = [NSString stringWithUTF8String:machine]; free(machine); return platform; } NSString * platformString () { NSString *platform = platformNSString(); // iphones if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G"; if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; if (

Issue with NSMakeCollectable when converting to ARC

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to convert my code to ARC and I have problem with NSMakeCollectable in the ASIRequest library. - (NSString*)encodeURL:(NSString *)string { NSString *newString = NSMakeCollectable([(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding([self stringEncoding])) autorelease]); if (newString) { return newString; } return @""; } It is giving me this error: NSMakeCollectable is unavailable: not available in

How to determine if an NSString is latin based?

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to determine if a string is latin based or Japanese. I've tried something like the following but it returns YES for Japanese strings as well: NSCharacterSet *alphaSet = [NSCharacterSet alphanumericCharacterSet]; BOOL isAlpha = [[myStr stringByTrimmingCharactersInSet:alphaSet] isEqualToString:@""]; A string might be a word like "café" or something like "カフェ" or "吃茶店". 回答1: Use the canBeConvertedToEncoding: method. For example: BOOL isLatin = [myString canBeConvertedToEncoding:NSISOLatin1StringEncoding]; Available encodings are here

Get directory contents in date modified order

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Is there an method to get the contents of a folder in a particular order? I'd like an array of file attribute dictionaries (or just file names) ordered by date modified. Right now, I'm doing it this way: get an array with the file names get the attributes of each file store the file's path and modified date in a dictionary with the date as a key Next I have to output the dictionary in date order, but I wondered if there's an easier way? If not, is there a code snippet somewhere which will do this for me? Thanks. 回答1: nall's code

sqlite3_prepare_v2 != SQLITE_OK

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wanna ask about my function below. It print NOT AVAILABLE when I call this function. Could you help me please?? static sqlite3 *database = nil; static sqlite3_stmt *statement = nil; - (BOOL) findNews:(NSString *)caption{ const char *dbpath = [databasePath UTF8String]; if (sqlite3_open(dbpath, &database) == SQLITE_OK) { NSLog(@"CAPTION ID : %@", caption); NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM dbase WHERE CONTENT_ID = \"%@\"", caption]; const char *query_stmt = [querySQL UTF8String]; if (sqlite3_prepare_v2(database,

HTTP Post Request in Objective-C Not Working

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing an HTTP Post request, but for some reason the parameters are not being added correctly, and I can't for the life of me figure out what I'm doing wrong. Here's what I have: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; [request setHTTPShouldHandleCookies:NO]; [request setTimeoutInterval:30]; [request setHTTPMethod:@"POST"]; NSString *boundary = @"---------------------------14737809831466499882746641449"; // set Content-Type in HTTP header