Menu
  • HOME
  • TAGS

NSPredicate not filtering out dates accessed by dot notation though the dates don't fall in the query range

Tag: objective-c,nspredicate,nsfetchedresultscontrolle,nsfetchrequest

I have an expiration date of matches and I want objects with an expiration date greater than the current date to be filtered out of a fetch request...heres the code for the fetch request predicate:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:NSStringFromClass([SMLMatch class])inManagedObjectContext:[SMLCDManager mainQContext]];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"expirationDate.date > %@", [NSDate date]];
[fetchRequest setPredicate:predicate];
[fetchRequest setFetchBatchSize:20];
// Specify how the fetched objects should be sorted
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"updatedAt" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]];
DDLogDebug(@"Grabbing Chats/matches after date: %@", [NSDate date]);

Expiration date is a transformable object with a NSDate, "date"...

This query kind of works but seems to be returning weird results and I am wondering if the problem has more to do with the fact i am using dot notation to access the date variable on the SMLMatch match expiration...Any reason that accessing the date like this would be a problem?

Here's a log of output:

Grabbing Chats/matches after date: 2015-01-06 01:02:27 +0000

When I print out the expirationDate.date as they are displayed in the fetched result controller table view:

ExpirationDate: 2015-01-05 02:23:25 +0000 User: Zoe
ExpirationDate: 2015-01-05 09:35:22 +0000 User: Jamie

As you can see, Zoe and Jamie expiration date are indeed before the current date, and should not show up in the results, but amazingly they do show up in the query results! Also, looking at the time zones of all the printed out dates, they appear to all be at the +0000 time zone offset...Can I query off the current date using [NSDate date]? i have seen others construct date input off calendar, but that's only if you want to specify a different range or date that is not the current date.

Why would those dates be passing this predicate?

I construct the fetch results controller with this predicate in the following manner:

_fetchController = [[NSFetchedResultsController alloc] initWithFetchRequest:[self fetchRequest] managedObjectContext:[SMLCDManager mainQContext] sectionNameKeyPath:nil cacheName:nil];
_fetchController.delegate = self;

Best How To :

figured it out having a date be embedded in a transformable type is not query able using predicates...guess it seems obvious this would not work after the fact

so, expirationDate.date, was the culprit. When i moved the date out to its own date property it worked.

so the predicate simply changes to: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"expirationDate > %@", [NSDate date]];

All's well that ends well

It is possible to continuously update the UILabel text as user enter value in UITextField in iOS

ios,objective-c,swift,uitextfield,uilabel

You can register your textField for value change event: [textField addTarget: self action:@selector(textFieldDidChange) forControlEvents:UIControlEventEditingChanged]; and in textFieldDidChange function update your label: - (void)textFieldDidChange { label.text = textField.text; } The function shouldChangeCharactersInRange is needed more for taking desisions whether to allow upcoming change or not...

iPod Touch (5th gen) 'Source type 1 not available' crash when using UIImagePickerControllerSourceTypeCamera

ios,objective-c,ipod-touch

First, You should always validate if the resource is available or not, try using: if(IS_IPAD && imagePicker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { // present the popover } else { // HEY, YOU CAN'T USE THIS } } From the official docs: Because a media source may not be present...

Calling dispatch_sync from a concurrent queue - does it block entirely?

ios,objective-c,multithreading,swift,grand-central-dispatch

dispatch_sync will block the caller thread until execution completes, a concurrent queue has multiple threads so it will only block one of those on that queue, the other threads will still execute. Here is what Apple says about this: Submits a block to a dispatch queue for synchronous execution. Unlike...

Trying to dismiss a popover view controller with a table view inside of it

ios,objective-c,uipopovercontroller

You have to set the delegate of your AssistanceNeededAtPopOverViewController that pops the controllerview, as the new GlobalPageSideDetailViewController. Here you're setting the delegate of a controller you just instantiate and not the one which poped the controller. ...

starting to work with iOS push notifications

ios,objective-c,push-notification

You are using the API wrongly. First of all the Push Notification API has changed after iOS 8.0. My answer will assume that you want to still supporting iOS 7.x and later // Checks if the application responds to the API introduced in iOS 8. if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { //...

Xcode UIWebView not changing page with changed URL

ios,objective-c,xcode,uiwebview

[self.webView reload] - will reload the current page. This is probably happening before the loadRequest has finished. Try removing this line. Also, @joern's comment is correct; the 'event' is the user making a pan gesture. Lose the timer....

Using sockets to build real time chat for iOS?

ios,objective-c,sockets,chat,real-time

Assuming you've got your server side things setup, you can use Square's Socket Rocket to implement the client side https://github.com/square/SocketRocket If you're using socket.io at the backend, there are plenty of iOS libraries available for those as well. SIOSocket is one such library....

NSString to NSDate doesn't work

ios,objective-c,nsdateformatter

You have to set the date format as the string NSString *myDate = @"06/18/2015 8:26:17 AM"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/yyyy h:mm:ss a"]; NSDate *date = [dateFormatter dateFromString:myDate]; //Set New Date Format as you want [dateFormatter setDateFormat:@"dd.MM. HH:mm"]; [dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US"]]; NSLog(@"%@",[dateFormatter stringFromDate:date]); ...

Height did not update when switch from portrait to Landscape?

ios,objective-c,iphone,landscape-portrait

Override didRotateFromInterfaceOrientation method on your ViewController and change the frame of the scrollView. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; self.menuScrollView.frame=CGRectMake(0,yPosition,width,self.view.frame.size.height); } ...

Updating Core Data Model using two separate View Controllers

ios,objective-c,uitableview,core-data

I resolved this. Here is what was done. First off there was serious cleanup of files, arrangement, etc. There were some objects, attributes, etc., that didnt make sense. Renaming things helped a lot as I was causing a lot of confusion. There was a one-to-one relationship between my List and...

Slide in an UIButton and push other UIButton when a certain distance is reached

ios,objective-c,uiviewanimation,nslayoutconstraint

Since you would expect the orange button to move at some point, you can't force it to be centered. Lower the priority from 1000 to something lower. This means: I would really like it to be centered, but it doesn't have to be. Add a horizontal distance (leading/trailing) constraint...

Google Drive API (GTL) - Create multiple folder paths in order?

ios,objective-c,swift,google-drive-sdk,google-api-objc-client

Avoid using a synchronous for loop. The createFolder function should call back when it's complete; that callback should start the next loop iteration.

CPU & Memory steadily increase & FPS drops all because of vector movement

ios,objective-c,sprite-kit

I have figured out my own problem. During character movement through touch, the SKScene's -(void)update:(NSTimeInterval)currentTime method runs that characters class method [_player GPS:currentTime]; which tracks speed and distance. Here's the hiccup, that method sets the character texture according to the direction he is facing. Every frame the same texture continues...

Copying Variable Names

objective-c

The correct modern style is to use ARC (automatic reference counting) in your project, which is the default for new projects (and has been for a few years). Then you do not need to, and are not allowed to, send the release message. The choice of initWithString: vs. stringWithString: makes...

Objective-C AVCaptureDevice Front Camera

ios,objective-c,camera,avcapturedevice,avcapture

this code is returns an AVCaptureDevice instance for the default device of the given media type. AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; change this code to .... AVCaptureDevice *inputDevice = nil; NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; for(AVCaptureDevice *camera in devices) { if([camera position] == AVCaptureDevicePositionFront) { // is front camera inputDevice...

How can i use MapKit View in Xcode 6.3?

ios,objective-c,iphone

Make sure you have added MapKit Framework in your project and try to follow some basic tutorial IOS8 Mapkit tutorial...

Set color CFAttributedStringRef

ios,objective-c

Based on the comments on the question, you mentioned that the words will never change. You could potentially create a whole bunch of if/else statements checking every word selected against every word in an array. I have put this down as a more efficient alternative and it should hopefully work....

iOS: What is the callback when tapped on the empty space between keyboard and search bar to dismiss the keyboard when search bar is active

ios,objective-c,swift

How about -searchBarTextDidEndEditing: in UISearchBarDelegate?

pushviewcontroller doesn't work?

ios,objective-c,pushviewcontroller

Update your AppDelegate.m file with following code self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; ExampleViewController *exampleViewController = [ExampleViewController new]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:exampleViewController]; self.window.rootViewController = navController; //self.window.backgroundColor = [UIColor lightGrayColor]; [self.window makeKeyAndVisible]; The problem is that you are not initializing rootViewController from...

Set background color of .xib launch image background

objective-c

For the launch .xib you won't be able to change the color programmatically. You can input hex values in the side menu. Click on background color, choose the second object from the left, and you can input hex values along with RGB values. User the color hex website to convert...

Crash when processing `__Atom` class object in Objective C (using Objective C runtime )

objective-c,osx,objective-c-runtime

+[NSObject isSubclassOfClass:] is a class method for NSObject and not all classes are subclasses of NSObject. It seems as if you have find private class that is not a subclass of NSObject, so it requires a more delicate handling for checking for inheritance. Try: BOOL isSubclass(Class child, Class parent) {...

How to push a view from project that based on Tab Bar Controller

objective-c

What you need to do is to put the TableViewController inside UINavigationController so that you can push a new ViewController [self.navigationController pushViewController:prue animated:YES]; That came be done either in the storyboard by adding the NavigationController into the TabViewController and put your ViewController as its root http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1 Or in code as...

Call method after asynchronous request obj-c

ios,objective-c,asynchronous,uiviewcontroller,nsobject

You'll have to 'remember' which UIViewController calls the object. This can be done for instance with a property. in .h @property (nonatomic) UIViewController *viewController; in your .m file @synthesize viewController; Before calling the method, set the property with anObject.viewController = self; Then, you'll be able to call [viewController finishedPost:self]; inside...

Set NSObject property - EXC_BAD_ACCESS

ios,objective-c,exc-bad-access,nsobject

Verify that [dict objectForKey:@"infos"] is not NSNull - Crash can be here. Other code looks OK. Also add -(void)deallocto your object and put a break point there to verify that the object is not being released before the assignment. ...

how i can solve Image auto resize in iphone 4 5 6 6+

ios,objective-c,iphone,objective

understand the autoresize concept , the following image is the description that how to we use the autoresizing on Left, right , top and bottom. So, I used to think according to this snapshot: Scenario 1: (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) // it automatically set the width, height, left and bottom: Scenario...

drawing views after time intervals

ios,objective-c

Create this method: -(void) drawViewsEvery5Seconds { if(!lastView)//should be a member variable { lastView = [[UIView alloc] initWithFrame:CGRectMake(0, 580, 16, 25)]; } else { lastView = [[UIView alloc] initWithFrame:CGRectMake(lastView.frame.origin.x+16, 580, 16, 25)]; } lastView.backgroundColor = [UIColor blackColor]; [self.view addSubview:lastView]; [self performSelector:@selector(drawViewsEvery5Seconds) withObject:nil afterDelay:5]; } and then just call [self drawViewsEvery5Seconds]; UPDATE...

how to share screenshot to Facebook

objective-c,facebook,facebook-sdk-4.0,social-media

I believe you want to FBSDKSharePhotoContent and FBSDKShareDialog. You need to setup your content as a photo(s): UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext(); FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init]; content.photos = @[[FBSDKSharePhoto photoWithImage:screengrab userGenerated:YES]]; // Assuming self implements <FBSDKSharingDelegate> [FBSDKShareAPI shareWithContent:content delegate:self]; ...

When replicating UIAlertView; background is not the same

ios,objective-c,uiview,uialertview

Try adding backgroundView into self.view.window, not self.view.

Call function on Server from iOS app - Objective C

ios,objective-c,json,server,backend

You just need to POST data to your server. Port could be anything you want, should be 80. Host your script with a domain url so that you can make network request publicly. You can try this function: -(NSData *)post:(NSString *)postString url:(NSString*)urlString{ //Response data object NSData *returnData = [[NSData alloc]init];...

Progressive HMAC SHA256 in Objective-C

javascript,objective-c,cryptography,hmac,cryptojs

HMAC-SHA256 sample code: + (NSData *)hmacSha256:(NSData *)dataIn key:(NSData *)key { NSMutableData *macOut = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH]; CCHmac( kCCHmacAlgSHA256, key.bytes, key.length, dataIn.bytes, dataIn.length, macOut.mutableBytes); return macOut; } Notes: Add Security.framework to the project Common Crypto must be included: #import <CommonCrypto/CommonCrypto.h> This is data in and out, add any conversions to desired representations...

Assigning a variable from another class

ios,objective-c,methods,protocols

viewClass.h @protocol ViewClassDelegate -(void)buttonWasClicked:(NSString *)aString; @end viewClass.m [submitButton addTarget:self action:@selector(submitButtonTapped) forControlEvents: UIControlEventTouchUpInside]; - (void)submitButtonTapped { [self.delegate buttonWasClicked:@"this is a string"]; } mainVC.m // Imported and called the delegate in mainVC.h. Then in .m I set the delegate -(void)buttonWasClicked:(NSString *)aString { // aString = this is a string } ...

Override UITabBarController Icon Selection

ios,objective-c,uitabbarcontroller

UITabBarControllerDelegate has a delegate method - tabBarController:shouldSelectViewController:, just implement it and check if user is logged in or not. e.g. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { if (isLogin) { return YES; } else{ //show your view controller here return NO; } } You can also check which view controller has...

UIWebView path depends on previous pressed button Xcode

ios,objective-c,iphone,xcode,uiviewcontroller

in your ClassA.m - (IBAction)button1:(UIButton *)sender{ path=[[NSBundle mainBundle] pathForResource:@"filename" ofType:@"pdf"]; [self performSegueWithIdentifier:@"yourIdentifierName" sender:self]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"yourIdentifierName"]) { classB *clsB =segue.destinationViewController; clsB.typeofSelect=path; } } in your class B.h @property (nonatomic, weak) NSString *typeofSelect; in your Class B.m @synthesize typeofSelect;...

How to do a “show (e.g Push)” segue programatically without animation?

ios,objective-c,swift,storyboard,segue

What the show (e.g. Push) segue does internally is to call -[UIViewController showViewController:sender:] Calling this method on your view controller itself, will trigger the appropriate way of presenting the view controller you are passing. // Swift self.showViewController(viewControllerToShow, sender: self) // Objective-C [self showViewController: viewControllerToShow sender: self]; The animation can be...

After an insert into the UITableView : custom the cell

ios,objective-c,uitableview

You need to use UITextField instead of UILabel. When you insert a new cell, set this UITextField's enabled property to true. When loading all the other cells remember to set it to false to disable editing (the same cell maybe used at more than one place)....

Read plist inside ~/Library/Preferences/

objective-c,xcode,osx

You need to use NSString method: stringByExpandingTildeInPath to expand the ~ into the full path. NSString *resPath = [@"~/Library/Preferences/" stringByExpandingTildeInPath]; NSLog(@"resPath: %@", resPath); Output: resPath: /Volumes/User/me/Library/Preferences ...

Obj-C Instance method returning a instanceType called from Swift - Function produces expected type 'UIImage!' error

ios,objective-c,swift

If you look at the method you have defined in Objective C image category, it is instance method and you are trying to call it using UIImage class in swift. You can basically use either one of the following two approaches, Either, self.backgroundImageView.image = self.someImage.applyDarkEffect() // notice the method does...

What is the best practice add video background view?

ios,objective-c,swift,video

First of all, you have two main choices: use a imageView with a GIF or use a video for background with AVPlayer or MPMoviePlayerController. You can find a lot of example for both ways, here's a few: use a GIF for cool background video cover iOS In reply to your...

NSPredicate crash with path which contains square brackets

objective-c,cocoa,nspredicate

If you need to match [ and ] you can use matches operator, which uses regular expressions. Example: NSArray *array = @[@"[apple]", @"[boy]", @"[dog]", @"cat"]; NSPredicate *pred = [NSPredicate predicateWithFormat:@"self matches %@", @"\\[dog\\]"]; NSLog(@"%@", [array filteredArrayUsingPredicate:pred]); About your update: predicateWithFormat is not like stringWithFormat, as it does some additional jobs...

NS_ENUM as property in protocol

ios,objective-c,automatic-ref-counting

You needs to synthesize the property: @implementation Application @synthesize applicationState = _ applicationState; @end or declare the property again: @interface Application : NSObject <ApplicationProtocol> @property (nonatomic) ApplicationState applicationState; @end ...

Cursor doesn't update in NSTextField as it autoresizes when resizing the enclosing NSWindow

objective-c,cocoa,nstextfield,autoresize,nscursor

Interesting question, I've never applied auto-layout to a text field so I was curious myself. My solution was to listen for the NSWindowDelegate method, -windowDidResize. Upon that, I would check to see if the text field was the first responder. If it was, I set it to be first responder...

Indent second line of UILabel

ios,objective-c,uilabel

Use an NSAttributedString for your label, and set the headIndent of its paragraph style: NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; style.headIndent = 14; NSDictionary *attributes = @{ NSParagraphStyleAttributeName: style }; NSAttributedString *richText = [[NSAttributedString alloc] initWithString:@"So this UILabel walks into a bar…" attributes:attributes]; self.narrowLabel.attributedText = richText; self.wideLabel.attributedText = richText; Result:...

Setting delegates (for protocols) only works in prepareForSegue?

ios,objective-c,delegates,protocols

When instantiated from a storyboard, the initWithCoder: methid is called, not the init method. DestinationViewController *destinationVC = [[destinationViewController alloc] init]; destinationVC.delegate = self; is how you do when your controller is not from a storyboard: you init it from the code. After that you have to manually handle the transition...

Build error after I localized Info.plist

ios,objective-c,xcode,swift,localization

Roll back those changes, add a InfoPlist.strings file to your project, localize it and then add the needed keys to it. For example: "CFBundleDisplayName" = "App display name"; "CFBundleName" = "App bundle name"; ...

Multiple NSURLSessions Causing UITableView Problems

ios,objective-c,uitableview,nsurlsession

Besides assuming that your network requests aren't erroring (you should at least log if there are network errors), there are threading issues. Your NSURLSession callback probably runs on a background thread. This makes it unsafe to call UIKit (aka - [_tableView reloadData]). UIKit isn't thread safe. This means invoking any...

__createApplicationIconFromImage_block_invoke: Error: unable to create icon mask image from image named “AppIconMask.png” at scale 2.0

ios,objective-c,cordova,phonegap-plugins

This solved me issue. It is working fine now after following below steps https://discussions.apple.com/thread/6742087?start=0&tstart=0 To troubleshoot this issue where your iPhone is unresponsive, please follow the steps outlined below: 1. If a single application is not responding or stops responding when it opens, you can force it to close. 2....

How to prevent duplicate entry on parse?

ios,objective-c,iphone,swift,parse.com

I suggest to implement a simple beforeSave trigger, on Parse Cloud code, in order to check if the new entry song already exist (basically you're going to make one or more field uniques. For example: Parse.Cloud.beforeSave("Musics", function(request, response) { var newEntrySong = request.object; var querySongs = new Parse.Query("Musics"); querySongs.equalTo("title", newEntrySong.get("title"));...

SceneKit + Collada + animation

objective-c,animation,blender,scenekit,collada

3DSMax + OpenCollada exporter works great.

Difference between stringByAppendingString and appendString in ios

ios,objective-c,swift,nsstring,nsmutablestring

appendString: is from NSMutableString, stringByAppendingString: is from NSString. The first one mutates the existing NSMutableString. Adds to the end of the receiver the characters of a given string. The second one returns a new NSString which is a concatenation of the receiver and the parameter. Returns a new string made...