{"action":"created","issue":{"url":"https://api.github.com/repos/CoderMJLee/MJExtension/issues/171","labels_url":"https://api.github.com/repos/CoderMJLee/MJExtension/issues/171/labels{/name}","comments_url":"https://api.github.com/repos/CoderMJLee/MJExtension/issues/171/comments","events_url":"https://api.github.com/repos/CoderMJLee/MJExtension/issues/171/events","html_url":"https://github.com/CoderMJLee/MJExtension/issues/171","id":101795259,"number":171,"title":"在Swift项目中保持OC环境来使用MJExtension","user":{"login":"WenchaoIOS","id":5186464,"avatar_url":"https://avatars.githubusercontent.com/u/5186464?v=3","gravatar_id":"","url":"https://api.github.com/users/WenchaoIOS","html_url":"https://github.com/WenchaoIOS","followers_url":"https://api.github.com/users/WenchaoIOS/followers","following_url":"https://api.github.com/users/WenchaoIOS/following{/other_user}","gists_url":"https://api.github.com/users/WenchaoIOS/gists{/gist_id}","starred_url":"https://api.github.com/users/WenchaoIOS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WenchaoIOS/subscriptions","organizations_url":"https://api.github.com/users/WenchaoIOS/orgs","repos_url":"https://api.github.com/users/WenchaoIOS/repos","events_url":"https://api.github.com/users/WenchaoIOS/events{/privacy}","received_events_url":"https://api.github.com/users/WenchaoIOS/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-19T02:50:22Z","updated_at":"2015-08-19T05:47:23Z","closed_at":null,"body":"Hi，MJ老师：\r\n    现在在Swift下通过标题叙述的方法并将Model模型引入到Swift的Bridge Header中也能成功使用这个框架。只是有些方法可能不是表面上那样，比如:\r\n```objective-c\r\nMJPerson *person = [MJPerson objectWithKeyValues : dictionary];\r\n```\r\n在Swift中就变成了\r\n```swift\r\nlet person = MJPerson(keyValues : dictionary)\r\n```\r\n\r\n而不是很多人想象的\r\n```swift\r\nlet persion = MJPerson.objectWithKeyValues(dictinoary)\r\n```\r\n关于这个方法，我想pr一个example不知是否可行？\r\n还是打算出一个纯Swift版本就不用这样做了？"},"comment":{"url":"https://api.github.com/repos/CoderMJLee/MJExtension/issues/comments/132453721","html_url":"https://github.com/CoderMJLee/MJExtension/issues/171#issuecomment-132453721","issue_url":"https://api.github.com/repos/CoderMJLee/MJExtension/issues/171","id":132453721,"user":{"login":"WenchaoIOS","id":5186464,"avatar_url":"https://avatars.githubusercontent.com/u/5186464?v=3","gravatar_id":"","url":"https://api.github.com/users/WenchaoIOS","html_url":"https://github.com/WenchaoIOS","followers_url":"https://api.github.com/users/WenchaoIOS/followers","following_url":"https://api.github.com/users/WenchaoIOS/following{/other_user}","gists_url":"https://api.github.com/users/WenchaoIOS/gists{/gist_id}","starred_url":"https://api.github.com/users/WenchaoIOS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WenchaoIOS/subscriptions","organizations_url":"https://api.github.com/users/WenchaoIOS/orgs","repos_url":"https://api.github.com/users/WenchaoIOS/repos","events_url":"https://api.github.com/users/WenchaoIOS/events{/privacy}","received_events_url":"https://api.github.com/users/WenchaoIOS/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T05:47:23Z","updated_at":"2015-08-19T05:47:23Z","body":"比如，在swift中导入MJExtension和OC的User类：\r\n```objective-c\r\n//\r\n//  User.h\r\n//  字典与模型的互转\r\n//\r\n//  Created by MJ Lee on 14-5-21.\r\n//  Copyright (c) 2014年 小码哥. All rights reserved.\r\n//  用户模型\r\n\r\n#import <Foundation/Foundation.h>\r\n\r\ntypedef enum {\r\n    SexMale,\r\n    SexFemale\r\n} Sex;\r\n\r\n@interface User : NSObject\r\n/** 名称 */\r\n@property (copy, nonatomic) NSString *name;\r\n/** 头像 */\r\n@property (copy, nonatomic) NSString *icon;\r\n/** 年龄 */\r\n@property (assign, nonatomic) unsigned int age;\r\n/** 身高 */\r\n@property (copy, nonatomic) NSString *height;\r\n/** 财富 */\r\n@property (strong, nonatomic) NSNumber *money;\r\n/** 性别 */\r\n@property (assign, nonatomic) Sex sex;\r\n/** 同性恋 */\r\n@property (assign, nonatomic, getter=isGay) BOOL gay;\r\n@end\r\n\r\n```\r\n\r\n然后在Bridge Header中引入:\r\n```objective-c\r\n#import \"MJExtension.h\"\r\n#import \"User.h\"\r\n```\r\n\r\n然后在Swift的main.swift中\r\n```swift\r\nfunc keyValue2object() {\r\n    \r\n    // 1.定义一个字典\r\n    let dict = [\r\n        \"name\" : \"Jack\",\r\n        \"icon\" : \"lufy.png\",\r\n        \"age\" : \"20\",\r\n        \"height\" : 1.55,\r\n        \"money\" : \"100.9\",\r\n        \"sex\" : SexFemale.value.description,\r\n        \"gay\" : \"true\"\r\n    ]\r\n    \r\n    // 2.将字典转为User模型\r\n    let user = User(keyValues: dict)\r\n    \r\n    // 3.打印User模型的属性\r\n    println(\"name = \\(user.name), icon=\\(user.icon), age=\\(user.age), height=\\(user.height), money=\\(user.money), sex=\\(user.sex), gay=\\(user.gay)\")\r\n    \r\n}\r\n\r\nkeyValue2object()\r\n\r\n```\r\n\r\n输出：\r\n```ruby\r\nname = Jack, icon=lufy.png, age=20, height=1.55, money=100.9, sex=C.Sex, gay=true\r\n```\r\n\r\n\r\n\r\n"}}