nspredicate

How to validate NSPredicate before calling fetch

纵饮孤独 提交于 2020-06-29 06:13:39
问题 I create a search NSPredicate using a custom format string. Sometimes the syntax of this string is wrong and when I execute a fetch using a NSFetchRequest with this predicate I get a NSInvalidArgumentException , for example when the key-path is incorrect. I would much rather prefer to validate this predicate (call some method that returns YES if format is ok), than have an exception thrown that crashes my app. What can I do? To rephrase the inquiry into a simple question: Can I validate the

iOS Swift: How to perform SQL SUM() function using MSQuery and NSPredicate?

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-29 03:49:16
问题 For example, I would like something similar to: select SUM[likes] from [MyAzureSQLService].[InstagramPost] where user == 'rain' Here, the "likes" is unsigned integer column in azure sql table "[MyAzureSQLService].[InstagramPost]", I wanted to query the sum number of all likes received by a specific user. My Swift code in iOS is like this: guard let table = client.table(withName: tableName) else { return } guard let query = MSQuery(table: table) else { return } query.predicate = NSPredicate

iOS Swift: How to perform SQL SUM() function using MSQuery and NSPredicate?

人走茶凉 提交于 2020-06-29 03:49:15
问题 For example, I would like something similar to: select SUM[likes] from [MyAzureSQLService].[InstagramPost] where user == 'rain' Here, the "likes" is unsigned integer column in azure sql table "[MyAzureSQLService].[InstagramPost]", I wanted to query the sum number of all likes received by a specific user. My Swift code in iOS is like this: guard let table = client.table(withName: tableName) else { return } guard let query = MSQuery(table: table) else { return } query.predicate = NSPredicate

Sort NSPredicate with in clausule with array's order

时间秒杀一切 提交于 2020-05-29 07:54:28
问题 I have a NSPredicate that does a search of id within an NSArray of ids, something like ('id in %@',array) Is there a way to get the resultset of that fetch sorted with the same array's order? The code I have now is +(NSArray*) findIn:(NSArray*)identifiers{ if(identifiers == nil) return nil; NSPredicate *searchFilter = [NSPredicate predicateWithFormat:@"id IN %@", identifiers]; NSArray *fetchedObjects = [GSBaseModel setupFetch:[[self class] managedObjectEntityName] andFilter:searchFilter

Filtering Realm with nested subqueries

▼魔方 西西 提交于 2020-05-17 07:56:07
问题 My app has data that looks like this. class ShelfCollection: Object { let shelves: List<Shelf> } class Shelf: Object { let items: List<Item> } class Item: Object { var name: String let infos: List<String> } I'm trying to get all shelves in a shelf collection where any items match the query either by name or by an element in their infos list. From my understanding this predicate should be correct, but it crashes. let wildQuery = "*" + query + "*" shelfResults = shelfCollection.shelves.filter(

31、iOS 正则表达式判断UITextField是否为全汉字,全字母,全数字,数字和字母

徘徊边缘 提交于 2020-03-14 07:47:06
判断全汉字 if ([self deptNameInputShouldChinese]) { [DemonAlertHelper showToastWithMessage:@"只能是中文"]; return; } 调用这个方法就可 #pragma mark-- #pragma mark 输入中文 - (BOOL) deptNameInputShouldChinese { NSString *regex = @"[\u4e00-\u9fa5]+"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if (![pred evaluateWithObject:inputTextField.text]) { return YES; } return NO; } 判断全数字: - (BOOL) deptNumInputShouldNumber { NSString *regex =@"[0-9]*"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if (![pred evaluateWithObject:inputTextField.text]) { return

CoreData 使用

末鹿安然 提交于 2020-03-06 13:37:05
一、CoreData的简单使用 准备工作 创建数据库 新建文件,选择 CoreData -> DataModel 添加实体(表), Add Entity 给表中添加属性,点击 Attributes 下方的 ‘+’ 号 创建模型文件 新建文件,选择 CoreData -> NSManaged Object subclass 根据提示,选择实体 通过代码,关联数据库和实体 - (void)viewDidLoad { [super viewDidLoad]; /* * 关联的时候,如果本地没有数据库文件,Coreadata自己会创建 */ // 1. 上下文 NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init]; // 2. 上下文关连数据库 // 2.1 model模型文件 NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil]; // 2.2 持久化存储调度器 // 持久化,把数据保存到一个文件,而不是内存 NSPersistentStoreCoordinator *store = [[NSPersistentStoreCoordinator alloc]

predicateWithBlock as the predicate for ABPeoplePicker.predicateForEnablingPerson causes exception

大兔子大兔子 提交于 2020-02-24 09:51:32
问题 iOS8 introduced a new scheme for configuring ABPeoplePicker using NSPredicates. I need more than the a basic predicate for which people to enable so I tried using predicateWithBlock like so: - (NSPredicate *)predicateForEnablingPerson { return [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { return TRUE; // Just pass back true until we figure out why it's crashing }]; } There's nothing in the scant documentation about this not being supported. Anyone know

predicateWithBlock as the predicate for ABPeoplePicker.predicateForEnablingPerson causes exception

送分小仙女□ 提交于 2020-02-24 09:50:12
问题 iOS8 introduced a new scheme for configuring ABPeoplePicker using NSPredicates. I need more than the a basic predicate for which people to enable so I tried using predicateWithBlock like so: - (NSPredicate *)predicateForEnablingPerson { return [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { return TRUE; // Just pass back true until we figure out why it's crashing }]; } There's nothing in the scant documentation about this not being supported. Anyone know

NSPredicate on nested array with NSDictionary as object

心已入冬 提交于 2020-02-16 05:25:49
问题 i have a NSDictionary like: { "2017-05-02" = ( { "always_valid" = 0; date = "2017-05-02"; from = "12:00"; to = "13:00"; }, { "always_valid" = 0; date = "2017-05-02"; from = "12:00"; to = "12:00"; }, { "always_valid" = 0; date = "2017-05-02"; from = "14:00"; "hourly_rate" = 12; to = "15:00"; } ); "2017-05-03" = ( { "always_valid" = 0; date = "2017-05-03"; from = "12:00"; to = "13:00"; } ); "2017-05-18" = ( { "always_valid" = 1; date = "2017-05-18"; from = "12:00"; to = "12:00"; } ); } i'm