This question already has an answer here:
1st april dates of 80s failed to parse in iOS 10.0
(1 answer)
Closed 5 years ago.
Today a very weird bug (or so I believe) started occurring. Here is the piece of code:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let dateObj = dateFormatter.dateFromString(serviceDate)
dateFormatter.dateFormat = "dd/MM/yyyy"
let serviceDateBr = dateFormatter.stringFromDate(dateObj!)
Now comes the strange part. When I set serviceDate = "2016-10-15", for example, it works:
let serviceDate = "2016-10-15"
...
print("dateSQL: \(serviceDate), dateBR: \(serviceDateBr)")
--------
Answer = dateSQL: 2016-10-15, dateBR: 15/10/2016
On the other hand, when I just change serviceDate to "2016-10-16" it crashes. Not on day 17, 18 or any other. Just 16.
let serviceDate = "2016-10-16"
...
print("dateSQL: \(serviceDate), dateBR: \(serviceDateBr)")
--------
Answer = fatal error: unexpectedly found nil while unwrapping an Optional value
I already know that this fatal error occurs when the first formatting fails, returns nil and then I try to force unwrap it on stringFromDate(). But I can't see why it fails in first place. Can anyone help me?
If it is relevant, I am using Xcode 7.3.1. This bug occurs on device and simulator.
Many thanks.
I suppose you are living in Brasil.
On October 16, 2016 the daylight saving time changes and there is no 0:00.
I have tried on Xcode 7.3 and it seems work fine and the results
dateSQL: 2016-10-15, dateBR: 15/10/2016
cloud you provide more info?
Related
This question already has answers here:
Xcode UI Testing Error keyboard
(2 answers)
Closed 2 years ago.
Every time Apple release a new XCode version, my UI tests fail. And I need to spend days figuring out what needs to be changed in the tests.
Is there something I am missing?
Example:
let tablesQuery = app.tables
let passwordCellsQuery = tablesQuery.cells.containing(.staticText, identifier:"Password")
passwordCellsQuery.children(matching: .secureTextField).element.tap()
passwordCellsQuery.children(matching: .secureTextField).element.typeText("12345678")
let memorableDateDdMmYyyyCellsQuery = tablesQuery.cells.containing(.staticText, identifier:"Memorable Date (dd/mm/yyyy)")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 2).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 2).typeText("1")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 0).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 0).typeText("2")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 1).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 1).typeText("3")
This time around I get "Failed to synthesize event: Neither element nor any descendant has keyboard focus. Event dispatch snapshot: SecureTextField"
It's got to the point that I dread any new XCode release as it ALWAYS breaks all my UI tests, this time it's Version 11.4.1 (11E503a).
Unit tests behave (thankfully).
You should not stick to the autogenerated code.
Write the test code and elements' description by yourself – this way you test will be more stable.
Try to make your code simpler – it will be easier to maintain.
let table = app.tables.element
let passwordCell = table.cells["Password"]
passwordCellsQuery.tapAndType("12345678")
let dateCell = table.cells["Memorable Date (dd/mm/yyyy)"]
dateCell.secureTextFields.element(boundBy: 2).tapAndType("1")
dateCell.secureTextFields.element(boundBy: 0).tapAndType("2")
dateCell.secureTextFields.element(boundBy: 1).tapAndType("3")
extension XCUIElement {
func tapAndType(_ text: String) {
tap()
typeText(text)
}
}
Had a very unusual bug with a handful of our users (less than 10 known out of thousands). Some of the objects that we store in coreData use date types. For some reason, on a specific person's device, some objects would fail during initialization whenever the JSON tried to map the dateString to our formatter.
static let iso8601DateTime: DateFormatter = {
let formatter = DateFormatter()
formatter.timeZone = TimeZone(secondsFromGMT: 0)[enter image description here][1]
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
return formatter
}()
When I made a breakpoint, all JSON time strings came in this format:
I was puzzled why some objects were successfully mapping at that point and others failed despite all of them returning in that format. By change, I read an issue on Apple's support website about language & region with ISO8601. I changed his region from US -> UK -> (back to) US, and found that all of the issues were resolved and He was able to use the application as normal.
Some advice I received said to specify a locale for the dateformatter, but I haven't been able to test yet.
formatter.locale = Locale(identifier: "en_US_POSIX")
Any idea why basically soft-refreshing this setting resolved it (setting to another and then back again)?
This question already has answers here:
Getting iOS system uptime, that doesn't pause when asleep
(6 answers)
Closed 6 years ago.
Is this possible to get Last shutdown or reboot time using objective c or Swift.
I tried many websites and forums. i can't find solution for this problem.
Check out NSProcessInfo there is a property called systemUptime of type NSTimeInterval
NSProcessInfo.processInfo().systemUptime
[[NSProcessInfo processInfo] systemUptime]
I gave you your answer in both objective-c and swift since you tagged them both.
You cannot detect the last shutdown time. But you can detect the last reboot time as:
let systemUptime = NSProcessInfo.processInfo().systemUptime;
And to detect the time, since last reboot is:
let systemUptime = NSProcessInfo.processInfo().systemUptime;
let timeNow = NSDate().timeIntervalSince1970
let dateOfLastReboot = NSDate(timeIntervalSince1970: timeNow-systemUptime)
I'm trying to initialise an NSTimeZone object like this:
var timezone = NSTimeZone.init(name: "Europe/Moscow")
instead of nil or a legit locale value - I get "unable to read data" in xCode's debugging tool
I got the timezone string ("Europe/Moscow") via NSTimeZone.knownTimeZoneNames()
I'm using xCode 7
What am I doing wrong?
Haven't used that class before, but I'm guessing it should be let timezone = NSTimeZone(name : "")? Never seen a class initialized in that way.
Its working fine for me , use let instead of var.Check below
For reference
Swift NSDate UTC time and local time
As pointed out in the comments - the variables view was just wrong - a print() resulted in the correct output.
Running an iPhone 6 Simulator instead of an iPhone 5 simulator gives the expected results.
I have downloaded this library https://github.com/TjeerdVurig/Vurig-Calendar. Now the problem which I'm facing, for example if I select 25th feb 2013 it is printing 24th Feb 2013. I Can't find anything in code. Is it because of time zone or something that is not related with coding??
Please Advise
Thanks
You have problems with time zone and it can be solved by adding this line of code:
[formatter setTimeZone:[NSTimeZone timeZoneWithName:#"GMT"]];
Update
Question 1
Question 2
Question 3
That is very easy to do. In your VRGCalendarView.m go to method
- (void)drawRect:(CGRect)rect {
int firstWeekDay = [self.currentMonth firstWeekDayInMonth]-1;
}
Change this to :
int firstWeekDay = [self.currentMonth firstWeekDayInMonth];
and
int selectedDateBlock = ([selectedDate day]-1)+firstWeekDay;
change this one to
int selectedDateBlock = ([selectedDate day]-2)+firstWeekDay;