nsstring

NSString stringWithContentsOfURL is deprecated. What should I do?

允我心安 提交于 2019-12-05 04:06:07
I've written some code that uses stringWithContentsOfURL , but it turns out that it is now deprecated. Can you help me replace it? Here's my code: NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; NSArray *listItems = [locationString componentsSeparatedByString:@","]; Additionally, can someone have some sample code to show how it works? What encoding was the original code done in (in my 2 lines above)? I want to maintain compatibility so what should I choose for the encoding? What does error mean and what is it used for? Use stringWithContentsOfURL

NSPredicate to filter between two dates of NSString type

一个人想着一个人 提交于 2019-12-05 03:43:51
问题 I've some data (as NSDictionary in an NSMutableArray ), a sample data is like, Consider each row as NSDictionary and entire table is an NSMutableArray contains events. I want to result between two dates, so I'm using NSPredicate to filter my data. Here's my code snippet for this, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Date >= %@ AND Date <= %@", startDate,endDate]; NSArray *filter = [arrayEvents filteredArrayUsingPredicate:predicate]; Test filtration : Case 1: NSString

Dynamically format a float in a NSString

偶尔善良 提交于 2019-12-05 03:28:30
问题 Consider this: NSString *whatever=[NSString stringWithFormat:@"My float: %.2f",aFloat]; This will round my aFloat to 2 decimal places when building the string whatever Suppose I want the 2 in this statement to be assignable, such that, based on the value of aFloat I might have it show 2 or 4 decimal places. How can I build this into stringWithFormat ? I want to be able to do this without an if that simply repeats the entire line for different cases, but rather somehow dynamically change just

iOS开发中的sqlite数据库

血红的双手。 提交于 2019-12-05 02:55:58
1.iOS开发中的数据一般指sqlite,而如果连接服务器,那就另说,那就不是iOS开发直接操作其它数据库,譬如SqlSever,Mysql,Orical。要使用数据库sqlite,首先将libsqlite3.0.dylib加到项目中。5.0之后的版本导入数据库头文件变成了#import "sqlite3.h",之前还有指定路径user,这也说明苹果不断改进着。   2.iOS开发中有个沙箱的概念。什么是沙箱?简单的理解就是指在iOS开发中程序能操作的位置只能在指定目录,意思就是只能在沙箱中进行操作。譬如文件的写入写出,要传输的图片,都只能放在那个目录,当然你也可以在其中建立子目录。数据库的本质其实也是一个文件,所以也只能在目录中进行,那么数据库建立的路径也只能在这个目录下。   3.首先是数据库要保存的路径   NSArray *array=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   NSString *documentsPaths=[array objectAtIndex:0];   NSString *databasePaths=[documentsPaths stringByAppendingPathComponent:"test_DB"];   4

In Objective-C, how to print out N spaces? (using stringWithCharacters)

天涯浪子 提交于 2019-12-05 02:49:56
The following is tried to print out N number of spaces (or 12 in the example): NSLog(@"hello%@world", [NSString stringWithCharacters:" " length:12]); const unichar arrayChars[] = {' '}; NSLog(@"hello%@world", [NSString stringWithCharacters:arrayChars length:12]); const unichar oneChar = ' '; NSLog(@"hello%@world", [NSString stringWithCharacters:&oneChar length:12]); But they all print out weird things such as hello ÔÅÓñüÔÅ®Óñü®ÓüÅ®ÓñüÔ®ÓüÔÅ®world ... I thought a "char array" is the same as a "string" and the same as a "pointer to a character"? The API spec says it is to be a "C array of

stringByAppendingFormat not working

﹥>﹥吖頭↗ 提交于 2019-12-05 01:44:42
I have an NSString and fail to apply the following statement: NSString *myString = @"some text"; [myString stringByAppendingFormat:@"some text = %d", 3]; no log or error, the string just doesn't get changed. I already tried with NSString (as documented) and NSMutableString. any clues most welcome. Paul Lynch I would suggest correcting to ( documentation ): NSString *myString = @"some text"; myString = [myString stringByAppendingFormat:@" = %d", 3]; From the docs: Returns a string made by appending to the receiver a string constructed from a given format string and the following arguments. It's

Split string by delimiter

天涯浪子 提交于 2019-12-05 01:30:28
I really can't find this answer... I have multiline NSString called myString in XCode, and it is a HTML code. I need to navigate the string by lines, for example: myString = @"<html>" "<body>" "<head><title>My Page</title>"; How can I access line per line? like: LineOne = myString.Lines[0]; LineTwo = myString.Lines[1]; How can I do something like that in XCode??? I need something like the Memo component in Delphi... The most html strings will have (mostly invisible) newline delimiters for separating the line NSArray *lines = [myHtmlString componentsSeparatedByString: @"\n"]; NSString *lineOne

Confused by NSStringDrawingOptions item meaning

社会主义新天地 提交于 2019-12-05 01:08:57
iOS7 and later, we can use - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context to calculate the string size, but I'm confused with the comments on NSStringDrawingOptions enum. NSStringDrawingUsesLineFragmentOrigin It means specified origin is the line fragment origin, not the base line origin. But what mean of line fragment origin and baseline origin. Just like the WWDC 2013 Session 220 (Advanced Text Layouts and Effects with Text Kit) PDF on Page 95. If line fragment origin mean the blue dot,

NSString sizeWithAttributes: Inaccuracy

眉间皱痕 提交于 2019-12-05 00:30:32
问题 I want to know the width of an NSString displayed on the screen in pixels. So I can fit an NSTextField its bounds to be exactly the length of the string itself. So I used IB's "Label" NSTextField and for those who don't know what I mean, I got a label with title "Label", font "Lucida Grande 13px", not selectable, not editable, regular size, no background and according to IB its width is 38px wide. If I want to get its width programatically I use [@"Label" sizeWithAttributes: [NSDictionary

iOS开发之CoreImage框架使用

岁酱吖の 提交于 2019-12-05 00:13:34
iOS开发之CoreImage框架使用 CoreImage框架是一个专门用来对图片进行处理的框架,其中提供了许多高级功能,可以帮助开发者完成UIKit或者CoreGraphics框架无法完成的任务,并且使用CoreImage框架可以十分轻松的实现滤镜以及图像识别等流行技术。本篇博客主要介绍和总结CoreImage框架的使用,并提供范例代码。 一、图像过滤器 1.几组内置的过滤器 CIFilter是CoreImage中提供的图像过滤器,也可以将其理解为滤镜。许多美颜应用,图像处理应用等都是为原图添加了滤镜效果。本节我们着重看下与这个类相关的应用。首先,CoreImaghe默认提供了非常多的滤镜效果,但是并没有详细的文档介绍,有关滤镜效果可以分为下面几个类别: //通过改变图像的几何形状来创建3D效果,类似隆起 过滤器组 NSString * const kCICategoryDistortionEffect; //旋转扭曲相关过滤器组 NSString * const kCICategoryGeometryAdjustment; //混合过滤器组 对两个图像进行混合操作 NSString * const kCICategoryCompositeOperation; //一种色调过滤器组 类似报纸风格 NSString * const kCICategoryHalftoneEffect