iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Numbcoder
V2EX  ›  iDev

请教一个关于 NSData 的诡异问题

  •  
  •   Numbcoder · Jan 15, 2013 · 4031 views
    This topic created in 4877 days ago, the information mentioned may be changed or developed.
    首先有一个 NSData 实例 data (有数据)

    int m;
    int n;

    [data getBytes:&m range:NSMakeRange(0, 1)];
    [data getBytes:&n length: 1];

    为什么 m 得到一个很诡异的数据。n 是正确的数据。
    按道理说 m 和 n 应该相等啊?
    3 replies    1970-01-01 08:00:00 +08:00
    Gal3rielol
        1
    Gal3rielol  
       Jan 15, 2013
    *range*
    The range of bytes in the receiver's data to copy to buffer. The range must lie within the range of bytes of the receiver's data.

    rang of bytes
    Numbcoder
        2
    Numbcoder  
    OP
       Jan 15, 2013
    @Gal3rielol 先谢了。
    这个是 API 文档里面的,但还是不太明白是什么意思,能详细解释一下原因么?
    lldong
        3
    lldong  
       Jan 15, 2013
    m和n实在栈里面的,初始的内容是随机的,你直接写一个byte进去然后读出来可能就会有问题了。你可能需要malloc一块内存然后清零。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2710 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:44 · PVG 23:44 · LAX 08:44 · JFK 11:44
    ♥ Do have faith in what you're doing.