Help us understand the problem. What is going on with this article?

ObjectMapperでの日付マッピング方法

More than 3 years have passed since last update.

ObjectMapperスゲー!となってる今日このごろですが、日付のマッピングはどうするんだろうと思って少し調べたら
以下の書き方で日付のマッピングができるとわかりました。

class dateItems: Object,Mappable {
    dynamic var day:NSDate?

    /// ObjectMapper
    required convenience init?(_ map: Map) {
        self.init()
        mapping(map)
    }

    func mapping(map: Map) {
        day <- (map["day"],CustomDateFormatTransform(formatString: "yyyy-MM-dd"))
    }
}

今回マッピングしたい日付は以下のようなものです。

2016-07-01 00:00:00 +0000

マッピングするために日付のフォーマットの書き方どうすればいいんだっけ?となり、調べてたら以下の記事を見つけました。

dateformat

これを参考にすると以下の書き方になりました。

class dateItems: Object,Mappable {
    dynamic var day:NSDate?

    /// ObjectMapper
    required convenience init?(_ map: Map) {
        self.init()
        mapping(map)
    }

    func mapping(map: Map) {
        day <- (map["day"],CustomDateFormatTransform(formatString: "yyyy-MM-dd'T'HH:mm:ssxxx"))
    }
}

無事マッピングされて一安心!

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away