nsstring

Convert NSString of a math equation to a value

折月煮酒 提交于 2019-12-29 00:07:06
问题 I would like to know how to evaluate a string representation of an equation as if it were a real equation: if(@"15+14==23") { //True statement... } else { //False statement.... } I want to return "false" because 15+14 does not equal 23. How can I get this to work? 回答1: Here is an example how to do it with NSPredicate : NSPredicate *p = [NSPredicate predicateWithFormat:@"1+2==3"]; NSLog(@"%d", [p evaluateWithObject:nil]); p = [NSPredicate predicateWithFormat:@"1+2==4"]; NSLog(@"%d", [p

NSPredicate for an NSManagedObject's string attribute's length

和自甴很熟 提交于 2019-12-28 18:29:52
问题 Could someone please help me define a predicate that returns only NSManagedObject's who's "letters" attribute length is within a certain range? Here's the example I've been trying, I've got a feeling it's the letters.length notation, I've also tried the kvc letters.@length with no success.. What am I doing wrong? NSManagedObjectContext *context = ...; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Word"

Get the extension of a file contained in an NSString

≯℡__Kan透↙ 提交于 2019-12-28 11:50:11
问题 I have an NSMutable dictionary that contains file IDs and their filename+extension in the simple form of fileone.doc or filetwo.pdf. I need to determine what type of file it is to correctly display a related icon in my UITableView. Here is what I have done so far. NSString *docInfo = [NSString stringWithFormat:@"%d", indexPath.row]; //Determine what cell we are formatting NSString *fileType = [contentFiles objectForKey:docInfo]; //Store the file name in a string I wrote two regex to determine

Reliable way to compare two NSURL or one NSURL and an NSString?

让人想犯罪 __ 提交于 2019-12-28 11:47:06
问题 I recently had a problem when comparing two NSURLs and compare one NSURL with an NSString(which is a URL address), the situation is I got an NSURLRequest from somewhere, I may or may not know the URL address it points to, and I have an URL NSString, say "http://m.google.com", now I need to check if the URL in that NSURLRequest is the same as the URL string I had: [[request.URL.absoluteString lowercaseString] isEqualToString: [self.myAddress lowercaseString]]; this returns NO as the

NSPredicate

爷,独闯天下 提交于 2019-12-28 10:09:12
一、简介   NSPredicate 指定数据被获取或者过滤的方式,是一个Foundation类。   Cocoa框架中的NSPredicate用于指定过滤器的条件(即查询),它的原理和用法都像SQL的 WHERE 和正则表达式一样,作用相当于数据库的过滤器。   最常用到的函数:+ predicateWithFormat: 创建谓词串 + (NSPredicate *)predicateWithFormat:(NSString *)predicateFormat, ...; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == 'Herbie'"]; //注意:如果谓词串中的文本块未被引用,则被看做是键路径,即需要用引号表明是字符串,单引号,双引号均可.键路径可以在后台包含许多强大的功能    二、谓词语法 范例数据源: 索引 0 1 2 3 名 Alice Bob Charlie Quentin 姓 Smith Jones Smith Alberts 年龄 24 27 33 31 背景: @interface Person : NSObject @property NSString *firstName; @property NSString *lastName; @property

iOS中的谓词(NSPredicate)使用

[亡魂溺海] 提交于 2019-12-28 10:08:30
iOS中的谓词(NSPredicate)使用 首先,我们需要知道何谓谓词,让我们看看官方的解释: The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering. NSPredicate类是用来定义逻辑条件约束的获取或内存中的过滤搜索。 可以使用谓词来表示逻辑条件,用于描述对象持久性存储在内存中的对象过滤。其实意思就是: 我是一个过滤器,不符合条件的都滚开 。 一、NSPredicate的基本语法 我们使用一门语言,无论是外语还是计算机语言,总是从语法开始的,这样我们才能正确的把握逻辑。所以我们从语法开始说起。在这部分我们仅关心其语法的使用 只要我们使用 谓词(NSPredicate) 都需要为谓词定义 谓词表达式 ,而这个表达式必须是一个返回BOOL的值。 谓词表达式由表达式、运算符和值构成。 1.比较运算符 比较运算符如下 =、==:判断两个表达式是否相等,在谓词中=和==是相同的意思都是判断,而没有赋值这一说 NSNumber *testNumber = @123; NSPredicate *predicate = [NSPredicate predicateWithFormat

How to get iOS appStoreReceiptURL into Base 64 Encoded String?

给你一囗甜甜゛ 提交于 2019-12-28 08:12:49
问题 I want to use appStoreReceiptURL to see which version of the app someone purchased. How can I get this into a string? I'm testing this by downloading the app from the store, then running a new version of the app from Xcode. Here is what I've tried: NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL]; NSLog(@"receiptUrl %@",[receiptUrl path]); if ([[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]]) { NSLog(@"exists"); NSError *error; NSString *receiptString = [

How to convert std::string to NSString?

我的未来我决定 提交于 2019-12-28 08:02:11
问题 Hi I am trying to convert a standard std::string into an NSString but I'm not having much luck. I can convert successfully from an NSString to a std::string with the following code NSString *realm = @"Hollywood"; std::string REALM = [realm cStringUsingEncoding:[NSString defaultCStringEncoding]]; However I get a compile time error when I try the following NSString *errorMessage = [NSString stringWithCString:REALM encoding:[NSString defaultCStringEncoding]]; The error I get is Cannot convert

iOS项目开发—文件下载功能的实现

寵の児 提交于 2019-12-28 04:59:38
一、简单说明 1.思路 把下载的data追加到文件的尾部,直到所有的数据下载完为止。 1.在连通了服务器的时候,创建一个空的文件到沙盒中NSFileManager(文件管理类) 2.创建写数据的文件句柄 3.在接收到服务器返回的数据后,把data写入到创建的空文件中,但是不能使用writeTofile(会覆盖) 3.1移动到文件的尾部 3.2从当前移动的位置,写入数据 4.服务器的数据加载完毕后关闭连接,不再输入数据在文件中 二、代码示例 1.代码: 新建一个类,让其继承自NSObject类,一个文件下载器只下载一个文件。 自定义类的TXFileDownloader.h代码: 1 // 2 // TXFileDownloader.h 3 // 文件下载 4 // 5 // Created by 鑫 on 14/12/23. 6 // Copyright (c) 2014年 梁镋鑫. All rights reserved. 7 // 8 9 #import <Foundation/Foundation.h> 10 11 @interface TXFileDownloader : NSObject 12 //下载的远程url(连接到服务器的路径) 13 @property(nonatomic,strong)NSString *url; 14 //下载后的存储路径(文件下载到什么地方)

Number of Occurrences of a Character in NSString

半腔热情 提交于 2019-12-28 02:06:04
问题 I have an NSString or NSMutableString and would like to get the number of occurrences of a particular character. I need to do this for quite a few characters -- uppercase English characters in this case -- so it would be nice for it to be quick. 回答1: replaceOccurrencesOfString:withString:options:range: will return the number of characters replaced in a NSMutableString . [string replaceOccurrencesOfString:@"A" withString:@"B" options:NSLiteralSearch range:NSMakeRange(0, [receiver length])];