iOS NSData 详细使用说明

所需积分/C币:46 2011-11-10 12:22:17 283KB PDF
收藏 收藏 4
举报

iOS NSData 详细使用说明文档。
Contents NSData Class Reference 5 Overview 5 Adopted protocols 6 Tasks 6 Cre ting data objects g Accessing Data 7 Testing Data 7 Storing Data 8 Class methods 8 data 8 data With Bytes: length: 8 data WithBytesNocopy: length: 9 data NoCopy: length: freeWhen Done: 10 ta With offie: 10 data WithContentsOfFile: options: error: 11 data With ContentsOfMapped File: 12 data With ContentsofuRL: 12 data With ContentsOfURL: options: error: 13 data WithData: 13 tance methods 14 bytes 14 description 14 getBytes: length: 15 getBytes: range: 15 init With Bytes: length: 16 initWith BytesNo Copy: length: 16 initWithBytes NoCopy: length: freeWhen Done: 17 initWithContentsofFile 17 initWith Contents OfFile: options: error: 18 initWith ContentsOfMappedFile: 19 initwithContentsofurl: 19 init withC tsOfURL: opti initwithData: 20 isEqual ToData: 20 gth 21 rangeofData: options: range: 21 subdatawith Range: 22 riteTo File atomically: 23 teToFile: options error: 23 iteTO URL: atomically: 24 writeTOURL: options: error: 24 3 2010-05-11@2010 Apple Inc. All Rights Reser CONTENTS Constants 25 NSData Reading options 25 NSDataWritingoptions 26 NSDataSearchOptions 26 Appendix A Deprecated NSData Methods 29 Deprecated in iOS 4.0 29 getBytes: 29 Document Revision History 31 2010-05-11@2010 Apple Inc. All Rights Reser NSData Class Reference Inherits from NSObject Conforms to NSCoding NSCopying NSMutableCopying NSObject(NSObject Framework /System/Library/Frameworks/Foundation framework Availability Available in ios 2.0 and later Declared in NSData h Companion quides Binary Data Programming Guide Property list Programming guide Related sample code CryptoEXercise ADEma GKRocket Lazytablelmages SimpleURLConnections Overview NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers )take on the behavior of Foundation objects N SDat a creates static data objects, and N SMutableDat a creates dynamic data objects. N SData and NSMuta bl a are typically used for data storage and are also useful in Distributed objects applications, where data contained in data objects can be copied or moved between applications Using 32-bit Cocoa, the size of the data is subject to a theoretical 2GB limit (in practice, because memory will be used by other objects this limit will be smaller); using 64-bit Cocoa, the size of the data is subject to a theoretical limit of about 8EB(in practice, the limit should not be a factor NSData is"toll-free bridged"with its Core foundation counterpart, CFData Reference. this means that the Core foundation type is interchangeable in function or method calls with the bridged foundation object Therefore, in a method where you see an NSData parameter, you can pass a CFDataRef, and in a function where you see a CrDataRef parameter, you can pass an Nsdat a instance (you cast one type to the other to suppress compiler warnings). This also applies to your concrete subclasses of N.. See Interchangeable Data Types for more information on toll- free bridging Overview 5 2010-05-11@2010 Apple Inc. All Rights Reser NSData Class ref Adopted protocols NSCoding encodewithCoder twithCod opsIn opyWithZone: NSMutable Copying utableCopyWithzone Tasks Creating Data Objects data(page 8 Creates and returns an empty data object dataWithBytes: length: (page 8) Creates and returns a data object containing a given number of bytes copied from a given buffer dataWithBytes NoCopy: length:(page 9) Creates and returns a data object that holds iength bytes from the buffer bytes. dataWithBytesNoCopy: length: freeWhenDone: (page 10) Creates and returns a data object that holds a given number of bytes from a given buffer dataWithContentsofFile:(page 10 Creates and returns a data object by reading every byte from the file specified by a given path dataI thContentsofFile: options: error:(page 11) Creates and returns a data object by reading every byte from the file specified by a given path dataWithContentsofMappedFile: (page 12) Creates and returns a data object from the mapped file specified by path. dataWithContentsofURI: (page 12) Returns a data object containing the data from the location specified by a given URI dataWithContentsofUrL: options: error: (page 13) Creates and returns a data object containing the data from the location specified by aukl dataI thData:(page 13) Creates and returns a data object containing the contents of another data object initwithBytes: length: (page 16) Returns a data object initialized by adding to it a given number of bytes of data copied from a given buffer initWithBytesNoCopy: length: (page 16) Returns a data object initialized by adding to it a given number of bytes of data from a given buffer Adopted Protocols 2010-05-11@2010 Apple Inc. All Rights Reserved NSData Class reference initWithBytes NoCopy: length: freewhenDone: (page 17) Initializes a newly allocated data object by adding to it /ength bytes of data from the buffer bytes initWithContentsofFile: (page 17) Returns a data object initialized by reading into it the data from the file specified by a given path initwithContentsofFile: options: error: (page 18) Returns a data object initialized by reading into it the data from the file specified by a given path initWithContentsOfMappedFile: (page 19) Returns a data object initialized by reading into it the mapped file specified by a given path initWithContentsOfURL: (page 19) Initializes a newly allocated data object initialized with the data from the location specified by uRL nitWithContentsOfURL: options: error: (page 19) Returns a data object initialized with the data from the location specified by a given UR initWithData: (page 20 Returns a data object initialized with the contents of another data object Accessing Data bytes(page 14) Returns a pointer to the receiver's contents description (page 14) Returns an Nsstring object that contains a hexadecimal representation of the receiver's contents getBytes: length:(page 15 Copies a number of bytes from the start of the receiver's data into a given buffer getBytes: range: (page 15 Copies a range of bytes from the receiver's data into a given buffer subdataWithRange: (page 22) Returns a data object containing a copy of the receiver's bytes that fall within the limits specified by a glven range rangeofData: options: range: (page 2 Finds and returns the range of the first occurrence of the given data, within the given range, subject to gIven options. getBytes: (page 29)Deprecated in iOS 4.0 Copies a data object's contents into a given buffer (Deprecated. This method is unsafe because it could potentially cause buffer overruns. You should use getBytes: length: (page 15)or getBytes: range: (page 15)instead. Testing data isEqualToData: (page 20 Compares the receiving data object to otherhat Task 2010-05-11@2010 Apple Inc. All Rights Reserved NSData Class reference length(page 21) Returns the number of bytes contained in the receiver Storing Data writeToFile: atomical ly: (page 23) Writes the bytes in the receiver to the file specified by a given path writeToFile: options:error:(page 23) Writes the bytes in the receiver to the file specified by a given path writeTOURL: atomically: (page 24) Writes the bytes in the receiver to the location specified by aur/ writeTOURL: options: error: (page 24) Writes the bytes in the receiver to the location specified by a given URL Class methods data Creates and returns an empty data object +(iddata Return value An empty data object Discussion This method is declared primarily for the use of mutable subclasses of NSData Availability Available in ios 2.0 and later d Sample Code EADemo Lazy tablelmages SeismicXML pRongs XMLPerformance Declared in NSData h data With Bytes:length: Creates and returns a data object containing a given number of bytes copied from a given buffer Class methods 2010-05-11@2010 Apple Inc. All Rights Reserved NSData Class reference +(id)dataWithBytes: (const void *)bytes length: (NSUInteger)length arameters bytes a buffer containing data for the new object length The number of bytes to copy from bytes. This value must not exceed the length of bytes. Return value a data object containing length bytes copied from the buffer bytes. Returns n i l if the data object could not be created Availability Available in ios 2.0 and later See also dataI thBytesNoCopy: length: (page 9) dataWithBytesNoCopy: length: freeWhenDone: (page 10) Related sample Code Crypto Exercise EADemo GKTank GLTexture Atlas PVRTextureloader Declared in NSData h data With BytesNo Copy: length: Creates and returns a data object that holds ength bytes from the buffer bytes +(id)datai thBytesNocopy: void *)bytes length: (NSUInteger)length Parameters bytes a buffer containing data for the new object by t es must point to a memory block allocated with malloc length The number of bytes to hold from bytes. this value must not exceed the length of bytes Return value a data object that holds length bytes from the buffer bytes. Returns n l if the data object could not be created Discussion The returned object takes ownership of the bytes pointer and frees it on deallocation Therefore, bytes must point to a memory block allocated with ma l loc. Availability Available in ios 2.0 and later Class methods 9 2010-05-11@2010 Apple Inc. All Rights Reserved NSData Class ref See also dataWithBytes: length: (page 8) dataWithBytesNoCopy: length: freeWhenDone:(page 10 Declared in NSData h data With BytesNo Copy: length: freeWhen Done Creates and returns a data object that holds a given number of bytes from a given buffer +(id)datawithBytesNoCopy: (void *)bytes length: (NSUInteger)length freeWhenDone: (booL)treewhenDone Parameters bytes a buffer containing data for the new object. If freeWhen Done is v ES, bytes must point to a memory block allocated with malloc length The number of bytes to hold from bytes. This value must not exceed the length of bytes freewhenDone If YtS, the returned object takes ownership of the bytes pointer and frees it on deallocation Return value a data object that holds length bytes from the buffer bytes. Returns n l if the data object could not be created Availability Available in ios 2.0 and later See also dataWithBytes: length: (page 8) dataWithBytesNoCopy: length: (page 9) Declared in NSData h dataWith Contentsoffile: Creates and returns a data object by reading every byte from the file specified by a given path +(id)dataWithContentsoffile: ( NSString *)path Parameters path The absolute path of the file from which to read data Return value a data object by reading every byte from the file specified by path Returns ni l if the data object could not be created Class methods 2010-05-11@2010 Apple Inc. All Rights Reserved

...展开详情
试读 32P iOS NSData 详细使用说明
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    一个资源只可评论一次,评论内容不能少于5个字
    switch123 英文版,是一种挑战,感觉不错@!
    2014-07-27
    回复
    Inexor 英文版的 没啥用
    2014-07-03
    回复
    hfdwdjl 不是很好懂,全英文的……
    2014-03-18
    回复
    昆卡卡 自己懒了,应该直接看官方文档的
    2013-10-08
    回复
    pcialpc 要是中文就好
    2013-09-27
    回复
    CartmanGuo 就是官方文档。。。
    2013-05-29
    回复
    后者why 所教了,找好了久,虽然英文的
    2013-05-27
    回复
    zcbhyt xcode help里面有
    2013-05-06
    回复
    辉哥无悔 英文版的,一般般
    2013-04-02
    回复
    p_huan 文档是英文的 看起来有点费力
    2013-03-17
    回复
    关注 私信 TA的资源
    上传资源赚积分,得勋章
    最新推荐
    iOS NSData 详细使用说明 46积分/C币 立即下载
    1/32
    iOS NSData 详细使用说明第1页
    iOS NSData 详细使用说明第2页
    iOS NSData 详细使用说明第3页
    iOS NSData 详细使用说明第4页
    iOS NSData 详细使用说明第5页
    iOS NSData 详细使用说明第6页
    iOS NSData 详细使用说明第7页
    iOS NSData 详细使用说明第8页
    iOS NSData 详细使用说明第9页
    iOS NSData 详细使用说明第10页

    试读已结束,剩余22页未读...

    46积分/C币 立即下载 >