XCUITest, UIDatePicker, adjustToPickerWheelValue - ios

I'm writing an XCUITest. I have a view with a UIDatePicker on it (NOT a regular picker).
I'm trying to set the date using adjustToPickerWheelValue.
This crashes with the following error:
caught "NSInvalidArgumentException", "-[XCUIElement(XCUIElementTypePickerWheel) adjustToPickerWheelValue:]_block_invoke can only be called with elements of type XCUIElementTypePickerWheel, not valid for DatePicker."
This implies of course that this method is not available for the UIDatePicker.
I've gone through the apple site and it states pretty clearly that it IS supported.
I can't find any examples of this used for a date picker.
It's possible of course that I'm just not setting it right (I'm not sure how one would pass a string date, for example).
This is the code I'm trying:
XCUIElement *DOB;
XCUIElementQuery *DOBList = app.datePickers;
DOB = [DOBList elementBoundByIndex:0];
NSLog(#"DOB = %#\n", [DOB description]);
[DOB adjustToPickerWheelValue:#"SOME DATE GOES HERE?"];
BTW - description is of a DatePicker.
Printing [DOB value] just returns an empty string.
Any ideas?

For using UIDatePickers, I do like that:
XCUIApplication().datePickers.firstMatch.pickerWheels["CurrentValue"].adjust(toPickerWheelValue: "NewValue")
You have to do that for each picker of the UIDatePicker.

Related

SBDatePicker Its posssible to set minimum date and maximum date in swift?

I am new for developing the ios application, I have used SBPickerSelector in Cocapods framework for Selecting datePicker.
whether If possible to set the MinumDate and MaximumDate???
Try;
let picker: SBPickerSelector = SBPickerSelector.picker()
//Minimum Date
picker.datePickerView.minimumDate = NSDate(); // A date
//Maximum Date
picker.datePickerView.maximumDate = NSDate(); // An other date ;
//or picker.setMaximumDateAllowed(NSDate())
I do not understand what do you get from using SBDatePicker, it look like they simply wrap the original class UIDatePicker.
The problem of using this kind of wrappers is that they don't always have the full feature set of the original class and you count on their developers to keep up with Apple changes (which they don't).
If you simply use UIDatePicker you can set maximumDate and minimumDate, just like you asked.
Check out the UIDatePicker Class Reference
And here is an example of setting the minimum and maximum dates

NSDate as function parameter in Swift

I'm facing an issue if I pass NSDate as a function parameter.
My code is:
self.PassDate(responseDate) ; // Response date value = 2015-05-15T00:00:00
func PassDate(date:NSDate) {
// Here ideally date value should be same as responseDate value.. but date is coming as 2015-05-14T07:00:00 PDT
}
Why passing NSDate is changing the timezone/values?
Nothing is changing. Different ways of viewing dates present them using different time zones. The underlying date is not changed. If you view the date in the debugger it (usually) shows it in UTC.
Try logging the date outside your function and inside using println() calls. You should see the same value in both places if you view it the same way each time.

How to fetch date in iOS from string object

I have stored NSDate in the DB using http://www.appcoda.com/sqlite-database-ios-app-tutorial/.
When i fetch the date back to NSString i get following during debugging. (As mentioned in tutorial even though i have a date picker and store value in NSDate, its actually stored as string in DB finally.
(lldb) po _itemPurchaseDate
(
)
Attached screenshot. So how do i fetch date and present it in a ui label in iOS?

IOS Upgrade to 7.0 Issue With Dictionary Lookup

Using location Manager in an app the following code worked prior to iOS7, now with iOS7, I'm getting the "??" escape. I'm looking up the state to retrieve the state abbreviation. The location mananger is properly retrieving the State (if I code to use "state" it will give me the desired state), but the lookup to the plist file (set to dictionary object) to get the abbreviation, for whatever reason fails and gives the "??" option. Any Ideas what's up?
NSString *state = placemark.administrativeArea;
NSString *stateAbbreviation = [self.usStateAbbreviations objectForKey:[state uppercaseString]];
NSString *stateTarget = state;
if (stateAbbreviation) {
stateTarget = stateAbbreviation;
}else{
stateTarget = #"??";
}
From another question:
For iOS6 i get the full name of the administrative area (ex.
"California"), but for the iOS7, I get the value of "CA".
So, it would seem, that state is already the stateAbbreviation on iOS7, so the key is different and you don't get a result for:
[self.usStateAbbreviations objectForKey:[state uppercaseString]];
According to Apple's documentation for CLPlacemark:
The string in this property can be either the spelled out name of the
administrative area or its designated abbreviation, if one exists. If
the placemark location is Apple’s headquarters, for example, the value
for this property would be the string “CA” or “California”.
So there doesn't seem to be a guarantee, one way or the other.

DatePicker not returning selected date iOS

I am trying to get the selected date from a DatePicker and all I get is the current system date. Any ideas why?
I am doing it through the simulator as I do not have a device. Here is the code I use to get the date.
[self scheduleLocalNotification:timerPicker.date];
I have also used this to see if it works:
NSDate *d = [timerPicker date];
[self scheduleLocalNotification:d];
After several reboots of XCode and no code changes it magically started working.

Resources