nsstring

iOS 数据库操作(使用FMDB)

房东的猫 提交于 2020-01-25 17:47:36
iOS 数据库操作(使用FMDB) iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便。于是,就出现了一系列将SQLite API进行封装的库,例如FMDB、PlausibleDatabase、sqlitepersistentobjects等,FMDB ( https://github.com/ccgus/fmdb ) 是一款简洁、易用的封装库,这一篇文章简单介绍下FMDB的使用。 在FMDB下载文件后,工程中必须导入如下文件,并使用 libsqlite3.dylib 依赖包。 FMDB同时兼容ARC和非ARC工程,会自动根据工程配置来调整相关的内存管理代码。 FMDB常用类: FMDatabase : 一个单一的SQLite数据库,用于执行SQL语句。 FMResultSet :执行查询一个FMDatabase结果集,这个和android的Cursor类似。 FMDatabaseQueue :在多个线程来执行查询和更新时会使用这个类。 创建数据库: [cpp] view plain copy print ? db = [FMDatabase databaseWithPath:database_path]; 1、当数据库文件不存在时,fmdb会自己创建一个。 2、 如果你传入的参数是空串:@"" ,则fmdb会在临时文件目录下创建这个数据库,数据库断开连接时

Need help fixing memory leak - NSMutableString

对着背影说爱祢 提交于 2020-01-25 08:05:06
问题 Have been playing around with instruments with not much luck in figuring out how to solve this memory leak. Firstly the code: -(NSString *) randomizeHint:(NSString *) wordToShuffle{ NSMutableString * outputstring = [NSMutableString stringWithCapacity:[wordToShuffle length]]; NSMutableSet * usedNumberSet = [NSMutableSet setWithCapacity:[wordToShuffle length]]; for (int i=0; i<[wordToShuffle length]; i++) { int randomnum = arc4random()%[wordToShuffle length]; while ([usedNumberSet

NSString,NSData,char的转换

天大地大妈咪最大 提交于 2020-01-25 03:43:11
1. NSString转化NSData NSData* aData = [@"a nsstring" dataUsingEncoding: NSUTF8StringEncoding]; 2.NSData转化NSString NSString* aString = [[NSString alloc] initWithData:aData encoding:NSUTF8StringEncoding]; 3.NSString转化char char cstr[10]; cstr =[aString UTF8String]; 4.NSData转化char char* cstr=[aData bytes]; 5.char转化NSString - (id)initWithUTF8String:(const char *)bytes NSString *bString = [[NSString alloc] initWithUTF8String:cstr]; 6.char转化NSData NSData *data = [NSData dataWithBytes:cstr length:strlen(cstr)]; 来源: https://www.cnblogs.com/javawebsoa/archive/2013/04/03/2998509.html

How to convert NSString to NSDate using NSDateFormatter?

限于喜欢 提交于 2020-01-24 21:35:07
问题 I getting the date from the webservice like "2012-07-03 07:26:48". I have saved in NSString after parsing from webservice. While convert the NSString to NSDate used below code, NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSString *dateStr = @"2012-07-03 07:26:48"; NSDate *date = [dateFormatter1 dateFromString:dateStr]; NSLog(@"Date : %@", date); The NSLog value is "2012-07-03 01:56:48 +0000"; The NSLog value is "2012

iOS 组件化方案探索

对着背影说爱祢 提交于 2020-01-24 21:24:35
看了 Limboy( 文章1 文章2 ) 和 Casa ( 文章 ) 对 iOS 组件化方案的讨论,写篇文章梳理下思路。 首先我觉得”组件”在这里不太合适,因为按我理解组件是指比较小的功能块,这些组件不需要多少组件间通信,没什么依赖,也就不需要做什么其他处理,面向对象就能搞定。而这里提到的是较大粒度的业务功能,我们习惯称为”模块”。为了方便表述,下面模块和组件代表同一个意思,都是指较大粒度的业务模块。 一个 APP 有多个模块,模块之间会通信,互相调用,例如微信读书有 书籍详情 想法列表 阅读器 发现卡片 等等模块,这些模块会互相调用,例如 书籍详情要调起阅读器和想法列表,阅读器要调起想法列表和书籍详情,等等,一般我们是怎样调用呢,以阅读器为例,会这样写: #import "WRBookDetailViewController.h" #import "WRReviewViewController.h" @implementation WRReadingViewController + (void)gotoDetail { WRBookDetailViewController *detailVC = [[WRBookDetailViewController alloc] initWithBookId:self.bookId]; [self.navigationController

How to purge / flush cache of NSString

别等时光非礼了梦想. 提交于 2020-01-24 15:21:05
问题 Currently I am doing simple tests of my app (written in xCode for MAC OS X) and I noticed that there are some issues when it comes to getting data from internet. So I am requesting some text data: NSString *dataFromInternet = [[NSString alloc] initWithContentsOfURL:url usedEncoding:&encoding error:&error]; Now: If internet works then everything is awesome. If internet disconnected then I am getting error in "error" however "dataFromInternet" still returns the very same data as if there was

return string inside block of NSURLConnection - Incompatible block pointer types sending

柔情痞子 提交于 2020-01-24 13:17:51
问题 I am trying to isolate logic responsible for authentication and retriving the TOKEN inside the function. I have the problem with returning the string with token from BLOCK of NSURLConnetcion. It causues semantic error : Incompatible block pointer types sending 'NSString *(^)(NSURLResponse *__strong, NSData *__strong, NSError *__strong)' to parameter of type 'void (^)(NSURLResponse *__strong, NSData *__strong, NSError *__strong)' I am completly newbie to Objective-C, so please be forgiving.

Determine if UTF-8 encoded NSData contains a null-terminated string

痞子三分冷 提交于 2020-01-24 10:48:33
问题 I have the NSData-to-NSString conversion in an NSData Category, because I'm always using the NSString method: initWithData:encoding: . But, according to this answer, https://stackoverflow.com/a/2467856/1231948, it is not that simple. So far, I have this method in my NSData Category, in an effort to keep consistent with methods in other data objects that return a string from a method with the same name: - (NSString *) stringValue { return [[NSString alloc] initWithData:self encoding

How can I underline part of the text like iPhone SMS?

醉酒当歌 提交于 2020-01-24 10:13:23
问题 I use an UILabel to show my text, in a multi-line and UILineBreakModeWordWrap mode, and the maximum width is 200. For example, here is the text: I really really want to underline first word and second word, could you help me? And I want to underline "first word" and "second word". If the text is shown in a single-line mode, with sizeWithFont method of NSString, I can easily calculate the position of "first word" and then override - (void)drawTextInRect:(CGRect)rect to draw the line. But in

iOS 组件化方案探索

≡放荡痞女 提交于 2020-01-23 14:40:05
首先我觉得”组件”在这里不太合适,因为按我理解组件是指比较小的功能块,这些组件不需要多少组件间通信,没什么依赖,也就不需要做什么其他处理,面向对象就能搞定。而这里提到的是较大粒度的业务功能,我们习惯称为”模块”。为了方便表述,下面模块和组件代表同一个意思,都是指较大粒度的业务模块。 一个 APP 有多个模块,模块之间会通信,互相调用,例如微信读书有 书籍详情 想法列表 阅读器 发现卡片 等等模块,这些模块会互相调用,例如 书籍详情要调起阅读器和想法列表,阅读器要调起想法列表和书籍详情,等等,一般我们是怎样调用呢,以阅读器为例,会这样写: #import "WRBookDetailViewController.h" #import "WRReviewViewController.h" @implementation WRReadingViewController + (void)gotoDetail { WRBookDetailViewController *detailVC = [[WRBookDetailViewController alloc] initWithBookId:self.bookId]; [self.navigationController.pushViewController:detailVC animated:YES]; } + (void