新浪微博开发之二十一(微博模型)
来源:互联网 发布:js input 选中 编辑:程序博客网 时间:2024/06/14 19:52
// MyUserModel.h
// 新浪微博
//
// Created by jose on 15-3-31.
// Copyright (c) 2015年 jose. All rights reserved.
// 用户模型
#import <Foundation/Foundation.h>
@interface MyUserModel : NSObject
/** string 用户昵称 */
@property(nonatomic,copy)NSString *name;
/** string 用户头像地址(50x50)*/
@property(nonatomic,copy)NSString *profile_image_url;
/** 用户会员的等级 */
@property(nonatomic,assign)int mbrank;
/** 用户的会员类型 */
@property(nonatomic,assign)int mbtype;
/** 判断是否为会员 */
@property(nonatomic,assign,getter=isvip)BOOL vip;
//字典转模型
+(instancetype)UserModelWithDict:(NSDictionary *)dict;
@end
*****************************************************************************************************************************************
********************************************************************************************************************************************
**********************************************************************************************************************************************‘
//
// MyUserModel.m
// 新浪微博
//
// Created by jose on 15-3-31.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import "MyUserModel.h"
@implementation MyUserModel
//字典转模型
+(instancetype)UserModelWithDict:(NSDictionary *)dict{
MyUserModel *model=[[MyUserModel alloc]init];
model.name=dict[@"name"];
model.profile_image_url=dict[@"profile_image_url"];
model.mbrank=(int)dict[@"mbrank"];
model.mbtype=(int)dict[@"mbtype"];
return model;
}
//判断是否为会员
-(BOOL)isvip{
//如果大于2就是会员
return _mbtype>2;
}
@end
****************************************************************************************************************************************************************
******************************************************************************************************************************************************************
*******************************************************************************************************************************************************************
//微博模型
//
// MyWeiboModel.h
// 新浪微博
//
// Created by jose on 15-3-31.
// Copyright (c) 2015年 jose. All rights reserved.
// 微博模型
#import <Foundation/Foundation.h>
#import "MyUserModel.h"
@interface MyWeiboModel : NSObject
/** string 微博创建时间 */
@property(nonatomic,copy)NSString *created_at;
/** string 字符串型的微博id */
@property(nonatomic,copy)NSString *idstr;
/** string 微博信息内容 */
@property(nonatomic,copy)NSString *text;
/** string 微博来源 */
@property(nonatomic,copy)NSString *source;
/** object 微博作者的模型 */
@property(nonatomic,strong)MyUserModel *user;
/** object 转发微博的模型 */
@property(nonatomic,strong)MyWeiboModel *retweeted_status;
/** int 转发数 */
@property(nonatomic,assign)int reposts_count;
/** int 评论数 */
@property(nonatomic,assign)int comments_count;
/** int 表态数 */
@property(nonatomic,assign)int attitudes_count;
/** object 微博配图地址 无图返回[]数组都是MyPictureTool模型 */
@property(nonatomic,copy)NSArray *pic_urls;
//字典转模型
+(instancetype)WeiboModelWithDict:(NSDictionary *)Dict;
@end
********************************************************************************************************************************
*********************************************************************************************************************************
********************************************************************************************************************************
//
// MyWeiboModel.m
// 新浪微博
//
// Created by jose on 15-3-31.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import "MyWeiboModel.h"
#import "MyUserModel.h"
#import "NSDate+MyNSDate.h"
@implementation MyWeiboModel
//字典转模型
+(instancetype)WeiboModelWithDict:(NSDictionary *)Dict{
MyWeiboModel *model=[[MyWeiboModel alloc]init];
model.text=Dict[@"text"];
//微博作者模型
model.user=[MyUserModel UserModelWithDict:Dict[@"user"]];
model.created_at=Dict[@"created_at"];
model.source=Dict[@"source"];
model.idstr=Dict[@"idstr"];
model.comments_count=(int)Dict[@"comments_count"];
model.reposts_count=(int)Dict[@"reposts_count"];
model.attitudes_count=(int)Dict[@"attitudes_count"];
//转发微博
NSDictionary *retweetedDict=Dict[@"retweeted_status"];
if (retweetedDict) {
//转发的微博进行字典转模型
model.retweeted_status=[MyWeiboModel WeiboModelWithDict:retweetedDict];
}
return model;
}
//重写方法
-(NSString *)created_at{
//_created_at = @"Mon Jul 14 16:13:07 +0800 2015";
NSDateFormatter *fmt=[[NSDateFormatter alloc]init];
fmt.dateFormat=@"EEE MMM dd HH:mm:ss Z yyyy";
//微博创建时间
NSDate *createtime=[fmt dateFromString:_created_at];
if (createtime.IsThisYear) {
if (createtime.IsToday) {
//获取时间差
NSDateComponents *cmps=[createtime DeltaWithNow];
if (cmps.hour>=1) {
return [NSString stringWithFormat:@"%d小时前",(int)cmps.hour];
}
else if (cmps.minute>=1){
return [NSString stringWithFormat:@"%d分钟前",(int)cmps.minute];
}
else{
return @"刚刚";
}
}
else if (createtime.IsYesterday){
//时分格式
fmt.dateFormat=@"昨天 HH:mm";
return [fmt stringFromDate:createtime];
}
else{
//月日时分格式
fmt.dateFormat=@"MM-dd HH:mm";
return [fmt stringFromDate:createtime];
}
}
else{
//年月日格式
fmt.dateFormat=@"yyyy-MM-dd";
return [fmt stringFromDate:createtime];
}
}
/****重写方法
-(NSString *)source{
// _source == <a href="http://weibo.com/" rel="nofollow">微博 weibo.com</a>
//截取范围
NSRange range;
range.location=[_source rangeOfString:@">"].location+1;
range.length=[_source rangeOfString:@"</"].location-range.location;
//开始截取
NSString *subsource=[_source substringWithRange:range];
return [NSString stringWithFormat:@"来自%@",subsource];
} ***/
//重写set方法
-(void)setSource:(NSString *)source{
NSRange range;
range.location=[source rangeOfString:@">"].location+1;
range.length=[source rangeOfString:@"</"].location-range.location;
NSString *subsource=[source substringWithRange:range];
_source=[NSString stringWithFormat:@"来自%@",subsource];
}
// _source = [NSString stringWithFormat:@"来自%@",subSource];
@end
- 新浪微博开发之二十一(微博模型)
- 新浪微博开发十一(微博账号模型)
- 新浪微博开发之二十二(微博请求参数模型)
- 新浪微博开发之二十三(微博请求结果返回模型)
- 新浪微博开发之二十四(微博末读消息模型)
- 新浪微博开发之二十七(全局变量)
- 新浪微博(十一)Parameter类
- (droid分享)新浪微博开发系列【十一】之查看微博正文
- 新浪微博开发之授权的实现(二)
- (droid分享)新浪微博开发系列【二】之授权
- 新浪微博简单开发之简单登陆(二)
- 新浪微博(二十一)微博布局文件(weibo_content.xml)
- 新浪微博开发二------------------------登陆篇
- 新浪微博开发之二十五(封装微博工具)
- 新浪微博开发之二十八(原创微博frame)
- 新浪微博开发之二十九(原创微博view)
- 新浪微博开发之php开发
- 新浪微博开发之二十(中间工具栏控制器)
- ubuntu git使用方法-获取与创建项目
- C++ post方式请求网页
- 浩易南:烧钱第一步,养个员工玩儿
- Linux高级编程复习笔记 第一章 内存管理 malloc new delete free sbrk brk
- Gentoo下KDE4升级KDE5记录
- 新浪微博开发之二十一(微博模型)
- Android中Service(服务)详解
- Perl and or 运算
- AFNetWorking的-1016和3840错误
- HDU 1257 最少拦截系统
- 数
- 互联网+.一个时代变革的征兆
- 欧拉工程第20题
- 华为oj之合法ip