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 · 4384 views
    This topic created in 5048 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
    Gal3rielol
    Jan 15, 2013
    1
    *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
    Numbcoder
    OP
    Jan 15, 2013
    2
    @Gal3rielol 先谢了。
    这个是 API 文档里面的,但还是不太明白是什么意思,能详细解释一下原因么?
    lldong
    lldong
    Jan 15, 2013
    3
    m和n实在栈里面的,初始的内容是随机的,你直接写一个byte进去然后读出来可能就会有问题了。你可能需要malloc一块内存然后清零。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4929 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 02:56 · PVG 10:56 · LAX 18:56 · JFK 21:56
    ♥ Do have faith in what you're doing.