Can you spot the mistake? import Foundation If the string you pass to the date formatter doesn't match the date format of the date formatter, then date(from:) returns nil. You always need to be careful when using the date(from:) method of the DateFormatter class. The value you assign to the dateFormat property needs to conform to UTS or Unicode Technical Standard. The dateFormat property is of type String. Let's set the dateFormat property of the DateFormatter instance and give it another try. It cannot infer the date format of the string. The DateFormatter is powerful, but it isn't magical. We passed a string to the date formatter's date(from:) method without specifying the date format of the string. The method seems to work fine since we don't see any errors or warnings. To convert the string to a date, we pass it to the date(from:) method of the DateFormatter class. We create a DateFormatter instance to convert the string to a date. I show you a more advanced example later in this post. Let's define the string we plan to convert to a Date object. This means we add an import statement for Foundation at the top of the playground. Fire up Xcode and create a playground.Īs I mentioned in the introduction, the DateFormatter class is defined in the Foundation framework. The class we use to convert a string to a date in Swift is DateFormatter (or NSDateFormatter if you are using Objective-C). U can setup AVPlayer in another way, that open for u full customization of your video Player screenĬreate UIView subclass for playing video (basically u can use any UIView object and only needed is AVPlayerLayer.The Foundation framework makes it painless to convert a string to a date, but there are a few pitfalls you need to watch out for.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |