ios-queryable is an implementation of IQueryable/IEnumerable for Core Data

Last update: Mar 3, 2022

#ios-queryable is an Objective-C category that provides IQueryable and IEnumerable-like functionality to Core Data.

Tired of writing boilerplate Core Data code? Can't live without LINQ? ios-queryable is for you!

It supports query composition and deferred execution, and implements a subset of IEnumerable's methods, including where, take, skip, orderBy, first/firstOrDefault, single/singleOrDefault, count, any, and all.

It lets you write code like this:

NSArray* widgets = [[[[[self.managedObjectContext ofType:@"Widget"]
			where:@"Type == 'abc'"]
			orderBy:@"createddate"]
			take:5]
			toArray];

instead of like this:

NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription* entity = [NSEntityDescription
                               entityForName:@"Widget" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
 
NSPredicate* predicate = [NSPredicate predicateWithFormat: @"type == 'abc'"];
[fetchRequest setPredicate:predicate];
 
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc]
                                    initWithKey:@"createddate" ascending:YES];
 
NSArray* sortDescriptors = [[NSArray alloc] initWithObjects: sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
 
[fetchRequest setFetchLimit:5];   
NSError* error;
NSArray* widgets = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

It also supports the NSFastEnumeration protocol, allowing for easy use in foreach loops:

foreach(Widget* widget in [self.managedObjectContext ofType:@"Widget"])
{
	// Do widgety stuff
}

#Usage To use ios-queryable, simply copy NSManagedObjectContext+IQueryable.h and NSManagedObjectContext+IQueryable.m into your project folder. Then, simply include the header file, and start writing your queries!

For examples, check out the tests in the tests project.

GitHub

https://github.com/martydill/ios-queryable
You might also like...

Flixtor-iOS - iOS streaming app inspired by Netflix that allows you to watch any film and series

Flixtor-iOS - iOS streaming app inspired by Netflix that allows you to watch any film and series

Flixtor-iOS iOS streaming app inspired by Netflix that allows you to watch any f

Jan 14, 2022

IOSAnimationSample-master - An iOS Animation playground to exercise different iOS Animations

IOSAnimationSample-master - An iOS Animation playground to exercise different iOS Animations

iOS Animation Sample This app is an iOS Animation playground to exercise differe

Feb 5, 2022

BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift!

 BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift!

BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift! Deprecated BrickKit is being phased out at Wayfair, and the

Jun 24, 2022

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.

๐Ÿšจ UNMAINTAINED ๐Ÿšจ This project is no longer used by LinkedIn and is currently unmaintained. LayoutKit is a fast view layout library for iOS, macOS, a

Jun 12, 2022

Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Extremely Fast views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainabl

Jun 27, 2022

Simple static table views for iOS in Swift.

Simple static table views for iOS in Swift.

Simple static table views for iOS in Swift. Static's goal is to separate model data from presentation. Rows and Sections are your โ€œview modelsโ€ for yo

May 28, 2022

An easy way to create and layout UI components for iOS (Swift version).

An easy way to create and layout UI components for iOS (Swift version).

Introduction Cupcake is a framework that allow you to easily create and layout UI components for iOS 8.0+. It use chaining syntax and provides some fr

Jun 16, 2022

An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.

An Impressive Auto Layout DSL for  iOS, tvOS & OSX. & It is written in pure swift.

KVConstraintKit KVConstraintKit is a DSL to make easy & impressive Auto Layout constraints on iOS, tvOS & OSX with Swift Installation Using CocoaPods

May 30, 2022

The ultimate API for iOS & OS X Auto Layout โ€” impressively simple, immensely powerful. Objective-C and Swift compatible.

The ultimate API for iOS & OS X Auto Layout โ€” impressively simple, immensely powerful. Objective-C and Swift compatible.

The ultimate API for iOS & OS X Auto Layout โ€” impressively simple, immensely powerful. PureLayout extends UIView/NSView, NSArray, and NSLayoutConstrai

Jun 17, 2022
Comments
  • 1. countByEnumeratingWithState:objects:count: crashes if managed context changes while enumerated

    The method in discussion executes a fetch request (via its toArray) each time the runtime asks for a batch of objects to enumerate through. And if the managed object contents change between fetch requests, it generates a crash as the toArray contents are not the same between invocations.

    Reviewed by cristik at 2015-08-31 12:03
  • 2. FirstOrDefault with condition throws exception on line #139 - Bad Access

    As I understand it, these two code snippets should be identical in behaviour.

    [[myQueryable where:@"someId = %@", someId] firstOrDefault]; and [myQueryable firstOrDefault:@"someId = %@", someId];

    However the first works a treat, the second dies in the where [NSPredicate predicateWithFormat:condition arguments:args];

    Reviewed by Codeglee at 2013-09-13 15:24
  • 3. Semantic Versioning

    Iโ€™ve recently added IOSQueryable to the CocoaPods package manager repo.

    CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

    However, IOSQueryable doesn't have any version tags. Iโ€™ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

    Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

    In case you didnโ€™t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

    $ git tag -a 1.0.0 -m "Tag release 1.0.0"
    $ git push --tags
    
    Reviewed by orta at 2012-12-15 17:39
  • 4. Unrecognized Selector count sent to an NSNumber

    While trying to query an average value during an NSManagedObject's awakeFromFetch and awakeFromInsert, I'm getting this error:

    2015-08-10 22:07:10.077 PropertyHunter[29805:971191] -[NSDecimalNumber count]: unrecognized selector sent to instance 0x608000431260

    The line of code:

    [[[sharedContext ofType:@"Store"] where:@"location.zipcode = %@", self.zipcode] average:@"visits"];

    I'm using this in a Mac OS X app. Any idea why this happens?

    Reviewed by EddyBorja at 2015-08-11 02:11
Related tags
IOS-App4 - Core Data add new data and update data
IOS-App4 - Core Data add new data and update data

iOS-App4 Core Data add new data and update data.

Jan 8, 2022
FlexLayout adds a nice Swift interface to the highly optimized facebook/yoga flexbox implementation. Concise, intuitive & chainable syntax.
FlexLayout adds a nice Swift interface to the highly optimized facebook/yoga flexbox implementation. Concise, intuitive & chainable syntax.

FlexLayout adds a nice Swift interface to the highly optimized Yoga flexbox implementation. Concise, intuitive & chainable syntax. Flexbox is an incre

Jun 16, 2022
sample project for `UICollectionViewLayout` implementation
sample project for `UICollectionViewLayout`  implementation

collection-view-layout-pattern-sample UICollectionViewLayout implementation pattern. About This project is introduced in iOSDC Japan 2021. sample code

Nov 3, 2021
Fancy Swift implementation of the Visual Format Language (experimental and doesn't work with the recent version of Swift)
Fancy Swift implementation of the Visual Format Language (experimental and doesn't work with the recent version of Swift)

VFLToolbox Autolayout is awesome! VFL a.k.a Visual Format Language is even more awesome because it allows you to shorten constraints setting code. The

May 1, 2022
VerticalFlowLayout - This implementation is built using a UICollectionView and a custom flowLayout.
VerticalFlowLayout - This implementation is built using a UICollectionView and a custom flowLayout.

VerticalFlowLayout This implementation is built using a UICollectionView and a custom flowLayout. Table of contents Requirements Installation CocoaPod

Apr 19, 2022
API Calling - Made an app in swift that gets data from Randomuser api and uses it in UITableView
API Calling - Made an app in swift that gets data from Randomuser api and uses it in UITableView

API_Calling Made an app in swift that gets data from Randomuser api and uses it

Feb 4, 2022
Om๐Ÿ‘€iOS - ์˜ค๋Š˜์€ ๋ฌด์Šจ iOS?!
Om๐Ÿ‘€iOS - ์˜ค๋Š˜์€ ๋ฌด์Šจ iOS?!

์˜ค๋ฌด๋ Œ Omoolen, ์ฝ˜ํƒํŠธ ๋ Œ์ฆˆ ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•œ ๋งž์ถค ๋ Œ์ฆˆ ์ถ”์ฒœ ๋ฐ ์˜คํ”„๋ผ์ธ ํ”ฝ์—… ์˜ˆ์•ฝ ์„œ๋น„์Šค SOPT 28th APPJAM ํ”„๋กœ์ ํŠธ ๊ธฐ๊ฐ„: 2021.06.26 ~ 2021.07.17 ์†Œ๊ฐœ ํŒ€์› ์†Œ๊ฐœ ๊น€์†Œ์—ฐ ๊น€ํ˜„๊ทœ ์ž„๊ฒฝ์ง„ Development Environment a

Apr 9, 2022
VidyoPlatform Basic CustomLayouts Reference App for iOS (Swift)VidyoPlatform Basic CustomLayouts Reference App for iOS (Swift)

VidyoPlatform Basic CustomLayouts Reference App for iOS (Swift) VidyoPlatform reference application highlighting how to integrate video chat into a na

Nov 19, 2021
Olvid-ios - Olvid client application for iOS

Olvid Olvid is a private and secure end-to-end encrypted messenger. Contrary to

May 11, 2022
IOS-PokemonQuizApp - Assignment to make a responsive iOS app. App has to connect with an external API

iOS-PokemonQuizApp Assignment to make a responsive iOS app. App has to connect with an external API. The Project The idea of the project is to make a

Jan 9, 2022