美文网首页
JSpatch 二

JSpatch 二

作者: AlanQingHua | 来源:发表于2016-09-19 21:16 被阅读0次

    ##### 1.NSArray / NSString / NSDictionary 不会自动转成对应的JS类型,像普通 NSObject 一样使用它们

    Important annotations that needs attention:

    //OC

    implementation JPObject

    +(NSArray *)data

    {

    return @[[NSMutableString stringWithString:@"JS"]];

    }

    +(NSMutableDictionary *)dict{

    return [[NSMutableDictionary alloc] init];

    }

    @end

    //js

    require('JPObject')

    var ocStr = JPObject.data().objectAtIndex(0)

    ocStr.appendString("Patch")

    var dict = JPObject.dict()

    ##### 2 dic如果要把 NSArray / NSString / NSDictionary 转为对应的 JS 类型,使用 .toJS() 接口:t.setObject_forKey(ocStr, 'name')

    // JS

    var data = require('JPObject').data().toJS()

    //data instanceof Array === true

    data.push("Patch")

    var dict = JPObject.dict()

    dict.setObject_forKey(data.join(''), 'name')

    dict = dict.toJS()

    console.log(dict['name'])    //output: JSPatch

    console.log(dict.objectForKey('name')) //output: JSPatch

    #####3 使用 dispatch_after() dispatch_async_main() dispatch_sync_main() dispatch_async_global_queue() 接口调用GCD方法:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

    // do something

    });

    dispatch_async(dispatch_get_main_queue(), ^{

    // do something

    });

    //js

    dispatch_after(1.0, function(){

    // do something

    })

    dispatch_async_main(function(){

    // do something

    })

    dispatch_sync_main(function(){

    // do something

    })

    dispatch_async_global_queue(function(){

    // do something

    })

    相关文章

      网友评论

          本文标题:JSpatch 二

          本文链接:https://www.haomeiwen.com/subject/dxeiettx.html