nsdata

Why does my DateComponents object in iOS not save to or retrieve from CloudKit correctly?

回眸只為那壹抹淺笑 提交于 2019-12-24 07:36:12
问题 I am using CloudKit with Swift for iOS. I am saving an object of type DateComponents in a CloudKit field of type Bytes. When I retrieve the object, it does not have the same value as the object I originally saved. Here is the code where I save the object to CloudKit: let unsafePointer: UnsafePointer<DateComponents> = UnsafePointer<DateComponents>(&time) let unsafeBufferPointer: UnsafeBufferPointer<DateComponents> = UnsafeBufferPointer<DateComponents>(start: unsafePointer, count: 1) let data:

NSJSONSerialization Not Working, NSUTF8StringEncoding Is Working

元气小坏坏 提交于 2019-12-24 05:09:51
问题 I've read the documentation, tutorials, and other Stack Q&A and am hung up on how I'm able to get my JSON to appear using NSUTF8StringEncoding , but not using NSJSONSerialization - which is what I need to extract the data to a NSDictionary or NSArray . I believe it is an issue with the format of the NSData being returned from my URL? EDIT Here is error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x8aabc30

iPhone - UIImage imageWithData returning nil

一曲冷凌霜 提交于 2019-12-24 01:52:48
问题 I need to create an UIImage from a byte array. Here is now I create the byte array: image = CGImageCreateWithImageInRect(aux.CGImage, imageRect); context = CGBitmapContextCreate (data[i][j], TILE_WIDTH, TILE_HEIGHT, bitsPerComponent, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);//kCGImageAlphaNoneSkipFirst);//kCGImageAlphaNone);// CGContextDrawImage(context, CGRectMake(0, 0, TILE_WIDTH, TILE_HEIGHT), image); data[i][j] = CGBitmapContextGetData

How does NSData's implementation of the hash method work?

做~自己de王妃 提交于 2019-12-24 00:49:54
问题 When calling hash on the built in NSData class in the foundation framework -- what implementation is used to return the hash value? (CRC32, something else?) 回答1: Something else. Actually it's an implementation detail, which does not need to use a fixed algorithm in different versions. You can check the implementation in the open source version of Core Foundation. Note that NSData is toll-free bridged to CFDataRef. From http://opensource.apple.com/source/CF/CF-635.21/CFData.c: static

NSData from a custom object

。_饼干妹妹 提交于 2019-12-23 18:38:08
问题 I'm working on client/server application which uses AsyncSocket. For transferring data, it uses NSData . How can I insert my custom object, containing NSNumber s, NSInteger s, and NSString s into an NSData object and then get it back out? 回答1: One way to insert (serialize) a custom object into an NSData object is to use NSCoding and NSKeyedArchiver. First, have your custom object implement the NSCoding protocol. Example here: http://developer.apple.com/library/ios/#documentation/Cocoa

problems with NSMutabledata byteswithnocopy [duplicate]

心已入冬 提交于 2019-12-23 18:28:15
问题 This question already has an answer here : NSMutableData datawithBytesNoCopy:length:freeWhenDone: seems to make a copy of the buffer provided to it (1 answer) Closed 5 years ago . I am trying to write a code to create NSMutableData from malloced buffer.I used freewhendone = YES 1) It gives an error in accessing the buffer after NSData is created.(in memset in below code) 2) The malloced buffer pointer and [data bytes] pointer are different. Is there any explanation for these? UWORD8 *rgb

How to byte reverse NSData output in Swift the littleEndian way?

限于喜欢 提交于 2019-12-23 09:30:25
问题 Hey guys I have this output from NSData: <00000100 84000c00 071490fe 4dfbd7e9> So how could I byte reverse it in Swift and have this output: <00000001 0084000c 1407fe90 fb4de9d7>? 回答1: This should work to swap each pair of adjacent bytes in the data. The idea is to interpret the bytes as an array of UInt16 integers and use the built-in byteSwapped property. func swapUInt16Data(data : NSData) -> NSData { // Copy data into UInt16 array: let count = data.length / sizeof(UInt16) var array =

How do I identify an empty NSData Object that appears as empty brackets?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 08:12:32
问题 I am dealing with a corruption issue in Game Kit's GKTurnBasedMatch class (see this thread) which sometimes results in an invalid game state, with corrupted matchData. So as a workaround, I'm creating a way out a way to identify these invalid matches so I can deal with them appropriately. The corrupted matchData seems like a good way to do this. However, so far I've been unable to identify them. When I do this: // "match" is an existing GKTurnBasedMatch object NSLog(@"match data is: %@",

Get NSData straight from AFNetworking, rather than letting it convert to UIImage

隐身守侯 提交于 2019-12-23 08:07:14
问题 Is there a flag that would let me get NSData, rather than let AFNetworking convert my responseData into the corresponding data type(UIImage, NSString)? 回答1: The AFHTTPResponseSerializer will return the raw NSData : AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager GET:... parameters:... success:^(AFHTTPRequestOperation *operation, NSData *responseObject) {} failure:...]; 回答2:

Read RTFD data in IOS

心已入冬 提交于 2019-12-23 05:39:21
问题 I have RTFD data in NSData objects in IOS that I need to read. In MacOSX I just used to read them with NSAttributedString, but now I know that they are not supported in IOS. attribString = [[NSAttributedString alloc] initWithRTFD:note documentAttributes:&dict]; Is there any way to read only the text of the RTFD data in IOS? 回答1: The rtfd in iOS is something like as a directory. If you only want to get the text part, you can try: NSString *filePath = [[NSBundle mainBundle] pathForResource:@