nsstring

Check if key exists in NSDictionary is null or not

烂漫一生 提交于 2019-11-29 09:18:14
I did search on how to check if NSDictionary key exists or not and came up with the solution. But still it throws me an error saying adding null value to the key. I am not sure if my code is correct or not. If anyone has any idea about this can help me. NSDictionary *result; id myImageURL = [result objectForKey:@"url"]; if ((NSNull *)myImageURL == [NSNull null]) myImageURL = @""; id myImage = [result objectForKey:@"image"]; if ((NSNull *)myImage == [NSNull null]) myImage = @""; Check if null add nothing and if not add the value. But it still gives me an error dont know why. /****OUTPUT*****/

what is actual difference between NSString and NSMutableString in objective C with the help of example? [duplicate]

人盡茶涼 提交于 2019-11-29 09:01:54
This question already has an answer here: What is the purpose of having both NSMutableString and NSString? 4 answers What is the difference between NSString and NSMutableString? [duplicate] 4 answers what is actual difference between NSString and NSMutable String in Objective-C? I have searched a lot but not getting any answer..I understand that NSString is Immutable object and NSMutableString is Mutable object but I want to understand the difference between them with the help of an example..Please help me.. now question has solved.. Dharmbir Singh Immutable String..... NSString *str1 = @

Why does isEqualToString not work for NSString?

自作多情 提交于 2019-11-29 08:55:12
I am trying to code the login process for an iPhone app in XCode. The problem is with the NSString serverOutput below. When I print it using printf(serverOutput.UTF8String); it prints 'Yes' to the console. However when I compare serverOutput to "Yes" it doesn't work. Any help would be appreciated. Here's my code: - (IBAction) loginButton: (id) sender { // TODO: spawn a login thread indicator.hidden = FALSE; [indicator startAnimating]; NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",userName.text, password.text]; NSString *hostStr = @"http://10.243.1.184/connectDB.php?";

iOS文件操作

我是研究僧i 提交于 2019-11-29 08:36:40
1.NSFileManager创建文件夹/文件; 拷贝; 删除; 剪切(move) 处理⽂文件系统的Foundation的类,提供对⽂文件或⺫⽬目录等的各种操作 主要功能 • 向⽂文件写⼊入数据;从⽂文件中读取数据 • 创建、复制、移动和删除⽂文件/⺫⽬目录 • 测试⽂文件的存在性 • 读取/更改⽂文件的属性 获取⽂文件管理器对象 defaultManager 创建⽂文件/⺫⽬目录 createFileAtPath:contents:attributes: -createDirectoryAtPath:withIntermediateDirectories:attributes:error 移动/剪切⽂文件 moveItemAtPath:toPath:error: 删除⽂文件 removeItemAtPath:error: - removeItemAtURL:error: NSFileManager *fm = [NSFileManagerdefaultManager];//初始化一个NSFileManager 路径不能只给到文件夹级别应该具体到文件名 copy: [fm copyItemAtPath:sourcePath toPath:destinationPath error:nil]; move: [fm moveItemAtPath:sourcePath toPath

iOS沙盒

别等时光非礼了梦想. 提交于 2019-11-29 08:36:28
• iOS应⽤用程序只能对⾃自⼰己创建的⽂文件系统读取⽂文件,这个独⽴立、封闭、安全的空间称 做沙盒。 • 一般存放着程序包⽂文件(可执⾏行⽂文件)、图⽚片、⾳音频、视频、plist⽂文件、sqlite数据库 以及其他⽂文件 iOS沙盒 Bundle容器: 只读; xxx.app(图片/可执行文件/Info.plist等) [[NSBundle mainbundle] pathForResource:@“test”withType:@“png”]; Data容器: 读/写; /Documents/: iTunes备份 自动上传到iCloud /Library/Caches: iTunes不备份 下载的文件(音频、视频,) 不会copy到iCloud上 /Library/Preferences: 设置的文件 /tmp/ 一.iOS沙盒机制特性 1. 应⽤用程序有独⽴立的存储空间 (沙盒) 2. 程序之间不可以互相访问 3.针对每个应⽤用,系统都会为其创建唯⼀一的⽂文件夹 二. iOS模拟器沙盒路径例⼦子: /Users/tarena/Library/Developer/CoreSimulator/Devices/62B0D10D-D2AA-4FE5-B467-0C2A31BF21C9 /data/Containers/Data/Application/D6FFE5A8-D6B8

NSString to wchar_t*?

本秂侑毒 提交于 2019-11-29 07:47:38
I can't seem to find a good built-in way to convert an NSString to wchar_t... any tips on how to do this? Anything Apple exposes on the NSString class is for c-strings (char*) or for unichars, but nothing for wchar*. Remus Rusanu [urString cStringUsingEncoding:NSUTF16LittleEndianStringEncoding] wchar_t is compiler specific. Assuming you wan the Win32 wchar_t , then UTF16 little ending encoded will do it. For Unix wchar_t you may need the NSUTF32 encoding family, with your platform of choice endianess. Following code worked for me: (not sure if this will be applicable for wchar_t as well)

Special Characters in NSString from HTML

試著忘記壹切 提交于 2019-11-29 07:39:25
I'm fetching data from an XML source and parsing through it with tbxml. Everything is working fine until I get to a latin letter like the "é" it will display as: Code: é I don't see a proper method of NSString to do the conversion. Any ideas? BlueVoid This seems like a pretty common problem. Check out HTML character decoding in Objective-C / Cocoa Touch johne You can use a regex. A regex is a solution to, and cause of, all problems! :) The example below uses, at least as of this writing, the unreleased RegexKitLite 4.0. You can get the 4.0 development snapshot via svn: shell% svn co http:/

Objective-C creating a text file with a string

烂漫一生 提交于 2019-11-29 07:34:20
问题 I'm trying to create a text file with the contents of a string to my desktop. I'm not sure if I'm doing it right, I don't get errors but it doesn't work either... NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES); NSString *desktopDirectory=[paths objectAtIndex:0]; NSString *filename = [desktopDirectory stringByAppendingString: @"file.txt"]; [myString writeToFile:filename atomically:YES encoding: NSUTF8StringEncoding error: NULL]; 回答1: //Method

How can I escape unicode characters in a NSString?

孤人 提交于 2019-11-29 07:22:39
When I store a NSString inside some NSDictionary and log that dictionary to the console like this: NSString *someString = @"Münster"; NSDictionary *someDict = [ NSDictionary dictionaryWithObjectsAndKeys: someString, @"thestring" ]; NSLog ( @"someDict: %@", [ someDict description ] ); The console output looks like this: unicode_test[3621:903] someDict: { thestring = "M\U00fcnster"; } with the string's unicode character escaped. Is there any method to convert a NSString to this escaped representation? The problem could be solved using a loop on a UniChar-string representation of the given string

What is the different between NSCFString and NSConstantString?

蹲街弑〆低调 提交于 2019-11-29 06:38:39
I declare the object variable as a NSString But when I use the XCode to look into my object, I saw there are two type of String, it seems that the system automatically transfer to another: What are the different between them? Are they interchangeable to one and others. Also, what is the condition two change to another? Thanks. They're both concrete subclasses of NSString . __NSCFString is one created during runtime via Foundation or Core Foundation, while __NSCFConstantString is either a CFSTR("...") constant or an @"..." constant, created at compile-time. Their interfaces are private. Treat