Giter VIP home page Giter VIP logo

fenghuangfm's Introduction

FenghuangFM

仿凤凰FM iOS客户端

image

仿凤凰FM iOS客户端是出于3个目的 1>理解网络请求 2>理解reactiveCocoa 3>理解MVVM

网络请求

凤凰FM的http请求返回数据为JSON格式,可以用Chalse轻松抓取到这些http请求,具体的请求信息在FenghuangFM/HTTPRequest下边。 http请求返回为JSON格式的数据,解析JSON用到了MJExtension库,JSON中有list时,使用如下方式告知JSON中key为"audiolist"的list中每个元素是”Audio“类型。

[ActivityModel mj_setupObjectClassInArray:^NSDictionary *{
    return @{
        @"audiolist":@"Audio"
    };
}];

另外返回的JSON中key可能会以"new"开头,而我们定义模型时成员变量使用new开头会报错,这时需要将JSON中的key转换成模型中的成员变量名,

[LeaderBoardData mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
    return @{
        @"newsList":@"newList"
    };
}];

reactiveCocoa

reactiveCocoa在这里的应用和网络请求结合在了一起,载入主页时,需要发出两个http请求,等待这两个请求都回返结果后再继续下一步,reactiveCocoa可以非常简单地完成这个动作,

MainFeatureViewModel.m

- (void)refreshDataSource
{
    @weakify(self);
    RACSignal *signalFocus = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    @strongify(self);
    [self requestFocusList:^{
        [subscriber sendNext:nil];
    }];
        return nil;
    }];

    RACSignal *signalRest = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    @strongify(self);
    [self requestRest:^{
        [subscriber sendNext:nil];
    }];
    return nil;
    }];

    [[RACSignal combineLatest:@[signalFocus,signalRest]] subscribeNext:^(id x) {
    @strongify(self);
    [(RACSubject *)self.updateContentSignal sendNext:nil];
    }];
}

MVVM

...

fenghuangfm's People

Contributors

tom555cat avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.