logo
down
shadow

check if NSDate object exist in NSArray of NSDate objects


check if NSDate object exist in NSArray of NSDate objects

By : Dr. ayad
Date : November 17 2020, 11:55 AM
should help you out These are little things which if you try by yourself, makes you better and inspires you to try it on your own every next time. You see, I didn't know the answer myself, so I created a small test code to see if different date objects with same date can be compared using [NSDate equal:] method and here is my code,
code :
NSMutableArray *dates = [NSMutableArray array];

NSDateComponents *yesterdayDateComponents = [[NSDateComponents alloc] init];
yesterdayDateComponents.day = -1;


NSDate *yesterdayDate = [[NSCalendar currentCalendar] dateByAddingComponents:yesterdayDateComponents
                                                                      toDate:[NSDate date]
                                                                     options:0];
NSLog(@"%@", yesterdayDate);

[dates addObject:yesterdayDate];

NSDate *newYesterDayDate = [[NSCalendar currentCalendar] dateByAddingComponents:yesterdayDateComponents
                                                                         toDate:[NSDate date]
                                                                        options:0];

if ([dates containsObject:newYesterDayDate]) {
    NSLog(@"Date are same");
}


Share : facebook icon twitter icon
Sort NSArray of custom objects by their NSDate properties

Sort NSArray of custom objects by their NSDate properties


By : user3098227
Date : March 29 2020, 07:55 AM
To fix the issue you can do Are you sure that the startDateTime instance variables of the node events are non-nil?
If you don't have one already, you might add a (custom) -description method to your node event objects that does something like this:
code :
- (NSString *)description {
   return [NSString stringWithFormat:@"%@ - %@",
                   [super description], startDateTime]];
}
NSLog(@"nodeEventArray == %@", nodeEventArray);
NSSortDescriptor *dateDescriptor = [NSSortDescriptor
                                     sortDescriptorWithKey:@"startDateTime" 
                                                 ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
NSArray *sortedEventArray = [nodeEventArray
         sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"sortedEventArray == %@", sortedEventArray);
Filtering a NSArray containing objects with a NSDate field with NSPredicate

Filtering a NSArray containing objects with a NSDate field with NSPredicate


By : GyKangiszer
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have an array of objects, with each object containing a field called date. I want to create a subset of this array using NSPredicate where I pull only those objects that fall within a certain date range. Here's the code I am using: , From the output of the predicate
code :
date >= CAST(406616400.676014, "NSDate") AND date <= CAST(406702799.677098, "NSDate")
Map NSArray with timestamps to NSDate objects with Mantle in iOS

Map NSArray with timestamps to NSDate objects with Mantle in iOS


By : user3102499
Date : March 29 2020, 07:55 AM
it fixes the issue Mantle 1.x doesn't provide an easy way to map a field in JSON to multiple model properties. Given the following model implementation below, this should work:
code :
NSDictionary *JSONDictionary = @{
    @"dates" :  @[ @1422784800, @1422784843 ]
};
NSError *error = nil;
Order *order = [MTLJSONAdapter modelOfClass:Order.class fromJSONDictionary:JSONDictionary error:&error];
NSLog(@"Order is from %@ to %@", order.dateFrom, order.dateTo);
@implementation Order

- (NSDate *)dateFrom
{
    if ([self.dates count] > 0) {
        return self.dates[0];
    }
    return nil;
}

- (NSDate *)dateTo
{
    if ([self.dates count] > 1) {
        return self.dates[1];
    }
    return nil;
}

#pragma mark - MTLJSONSerializing

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
        @"dates" : @"dates"
    };
}

+ (NSValueTransformer *)datesJSONTransformer
{
    return [MTLValueTransformer transformerWithBlock:^NSArray *(NSArray *dates) {
        if (![dates isKindOfClass:NSArray.class]) {
            return nil;
        }
        NSMutableArray *dateObjects = [NSMutableArray arrayWithCapacity:dates.count];
        for (NSNumber *timestamp in dates) {
            NSDate *date = [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]];
            [dateObjects addObject:date];
        }
        return [dateObjects copy];
    }];
}

@end
How to check NSDate yyyy/mm/dd in NSArray and compare it?

How to check NSDate yyyy/mm/dd in NSArray and compare it?


By : Far ZaNe
Date : March 29 2020, 07:55 AM
like below fixes the issue After some research i did made a solution as following
First this extension is very good and my way is depends on it https://stackoverflow.com/a/27369380/5188737
code :
func loadMessages(){

    if chatRoom!.messages.count > 0{
        var i = 0
        var tempMsgDate:NSDate?
        var chatMessage:ChatMessage?

        for message in chatRoom!.getAllMessages(){
            let msg = message as! Message
            if i == 0{
                tempMsgDate = msg.timeStamp
                chatMessage = ChatMessage(incoming: msg.income, text: msg.message, sentDate: convertNSDateToString(msg.timeStamp))
                i++
            }else{
                //if the tempMsgDate (which is the first of the same
                //date in the nsarray) 
                if checkIfSameDayDate(tempMsgDate!,date2: msg.timeStamp){
                    var tempDate = msg.timeStamp.time
                    let dateFormatter = NSDateFormatter()
                    dateFormatter.dateFormat = "HH:mm"
                    let date = dateFormatter.dateFromString(tempDate)
                    println("loadmessages method:  \(date?.time)")
                    chatMessage = ChatMessage(incoming: msg.income, text: msg.message, sentDate: msg.timeStamp.time)
                }else{//after he got to different date it save it as
                      //first of same date to follow 
                    tempMsgDate = msg.timeStamp
                    chatMessage = ChatMessage(incoming: msg.income, text: msg.message, sentDate: convertNSDateToString(msg.timeStamp))
                }
            }

            var msgCollection:[ChatMessage] = [ChatMessage]()
            msgCollection.append(chatMessage!)
            chat.loadedMessages.append(msgCollection)
        }
    }
}


func convertNSDateToString(date:NSDate) -> String{
    let dateString = date.date + " " + date.time
    println("in convert: \(dateString)")
    return dateString
}

func checkIfSameDateFromSendMSGAndReciveMSG(date:NSDate) -> Bool{
    for message in chatRoom!.getAllMessages(){
        let msg = message as! Message
        if msg.timeStamp.date == date.date{
            return true
        }
    }
    return false
}
//checks if the date1 equal to date2    
func checkIfSameDayDate(date1:NSDate,date2:NSDate) -> Bool{
    if date1.date == date2.date{
        return true
    }
    return false
}
Sorting NSArray containing NSDate objects

Sorting NSArray containing NSDate objects


By : vsg
Date : March 29 2020, 07:55 AM
should help you out Using the native Array type in Swift. If you are interfacing with legacy code from ObjC, use this:
code :
let array = unsortedArray.sortedArrayUsingSelector("compare:")
Related Posts Related Posts :
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • Adding checkmark to selected table cell also checks another table cell
  • UICollectionView cellForItemAtIndexPath indexPath row is nil
  • Resize and set quality on JPEG image while retaining EXIF in iOS
  • How to push rootviewcontroller in Ios
  • How to add UIBarbuttonItem at centre on UInavigationbar in iOS
  • Would this IOS device test crash be expected
  • PickerView not showing any values
  • How to set root view controller in storyboard animated with navigation controller programmatically
  • Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?
  • Getting list of files in documents folder
  • Error while using Realm Object as a singleton. Is it a good idea?
  • inserting into SQLite database
  • More nodes than I should
  • Facebook IOS SDK navigate to another controller after login not working
  • Swift Array - use "Contains" of type AnyObject
  • Sidebar menu with indicate navigationbar on iOS
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • Web services issue on POST method
  • Parse.com error 'Method not allowed when Pinning is enabled.' when I use a PFQueryTableViewController subclass
  • Swift can't send URLRequest at all?
  • No Provisiong profiles with a valid signing identity were found and Failed to locate or generate matching signing assets
  • iOS: how to set httponly flag for NSHTTPCookie
  • How to get the mac address of a beacon in objective-c without knowing its UUID, major and minor values?
  • tableView is not showing data from JSON in swift
  • iTunes reject app for date of birth
  • SWIFT reporting "Extra argument in call" - works in Playground
  • save data depending on passed value in swift
  • webview not showing on full Screen of iphone 6
  • Location Notification's based on Latest iOS Feature
  • Adjusting Height of UITableViewCell
  • How to show five digit unicode in iphone
  • unwind doesn't work
  • Confusion about coordinates, frames & child nodes in SpriteKit on iOS?
  • If Statements not being recognized by Xcode
  • readonly property in RubyMotion
  • 'No available types for source 1' when the app runs on my device(IPhone 6) swift
  • IOS:Remove view when clicked in background
  • Removing "\" from URL in iOS Swift
  • iOS - Send an email automatically (NOT from user's account)
  • The usage of NSNotificationCenter in the relationship of parent and children
  • When do Apple auto-renewable subscriptions renew?
  • Unknown large spacing between x-axis label and base of plot in core-plot
  • How do I change the displayed time format after NSTimer is initiated?
  • Swift JSON breaks when [ ] are used
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org