nsdata

game state singleton cocos2d, initWithEncoder always returns null

萝らか妹 提交于 2019-12-04 16:03:22
问题 I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstructions; } @property (readwrite) NSInteger level; @property (readwrite) NSInteger score; @property (readwrite) Boolean seenInstructions; +(GameState *) sharedState; +(void)

How to Load NSData into an AVPlayerItem?

拜拜、爱过 提交于 2019-12-04 12:51:00
问题 This is a follow-on question from my post about How to Encrypt mp3 Files in iOS. How would I go about loading a track into an AVPlayerItem using NSData rather than a file path/URL? Thanks 回答1: [/*name of NSData*/ writeToFile:/*save file path*/ atomically: YES]; NSURL *filepath = [NSURL fileURLWithPath:/*save file path*/]; AVPlayerItem *player = [AVPlayerItem playerItemWithURL:filepath]; Untested, but should work. 回答2: Updating Dustin's answer for Swift 5: var audioData: Data // some audio

Read only a portion of a file from disk in objective-c

痴心易碎 提交于 2019-12-04 11:19:45
问题 I am reading a very large file using a NSInputStream and sending them to a device in packets. If the receiver does not get a packet, I can send back to the sender with a packet number, representing the starting location in bytes of the packet missing. I know an NSInputStream cannot rewind and grab the packet, but is there another way to grab the requested byte range without loading the entire large file into memory? If there was a [NSData dataWithContentsOfFileAtPath:inRange] method, it would

Handling CFNull objects in NSPropertyListSerialization

走远了吗. 提交于 2019-12-04 10:01:26
In my application, I am trying to serialize a server response dictionary and writing it to file system. But I am getting error "Property list invalid for format" for some responses. The reason is CFNull objects in the server response. Now, the server response will keep on changing so I do not have a definite way to remove CFNull objects (). Below is my code: NSString *anError = nil; NSData *aData = [NSPropertyListSerialization dataFromPropertyList:iFile format:NSPropertyListXMLFormat_v1_0 errorDescription:&anError]; What is the best way to tackle this issue? How can I remove all CFNull objects

NSMutableData remove bytes?

冷暖自知 提交于 2019-12-04 08:52:55
问题 I can add bytes to a NSMutableData instance easily by using the appendData method, however I do not see any similar method for removing data? Am I overlooking something, or do I need to create a new object and copy over only the bytes I need? 回答1: Please see the documentation of the following method: - (void)replaceBytesInRange:(NSRange)range withBytes:(const void *)replacementBytes length:(NSUInteger)replacementLength Apple clearly says the following: If the length of range is not equal to

NSData to NString conversion problem

人盡茶涼 提交于 2019-12-04 07:25:01
I'm getting an HTML file as NSData and need to extract some parts of it. For that I need to convert it to NSString with UTF8 encoding. The thing is that this conversion fails, probably because the NSData contains bytes that are invalid for UTF8. I have tried to get the byte array of the data and go over it, but each time I come across non ASCII character (hebrew letters for example) I get jibrish. Help will be appreciated. UPDATE: To Gordon - the NSData generated like that: NSData *theData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];

NSData cannot retrive image from internet anymore [duplicate]

若如初见. 提交于 2019-12-04 06:52:32
问题 This question already has answers here : How do I load an HTTP URL with App Transport Security enabled in iOS 9? [duplicate] (8 answers) Closed 4 years ago . The following code works fine before iOS8.4.1 (includ 8.4.1). While it ruturns nil in iOS9.0.1. Is it a bug or there is a public annoucement for this change? I tested with two iPads. let url = NSURL(string: "http://www.mapshots.com/wp-content/uploads/2014/05/mapshots-ag-studio-agricultural-mapping-software-logo.png") let data = NSData

Cannot pass immutable value as inout argument: function call returns immutable value

空扰寡人 提交于 2019-12-04 06:29:22
问题 I forked this project, so I am not as familiar with all of the details: https://github.com/nebs/hello-bluetooth/blob/master/HelloBluetooth/NSData%2BInt8.swift. This is all part of an extension of NSData that the I am using to send 8-bit values to an Arduino. func int8Value() -> Int8 { var value: Int8 = 0 copyBytes(to: &UInt8(value), count: MemoryLayout<Int8>.size) //BUG return value } However, it appears in Swift 3 that this now throws an error in the copyBytes section. Although I have seen

NSAttributedString to NSData No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes:

百般思念 提交于 2019-12-04 05:29:17
I am trying to convert NSAttributedString to NSData using RTFDFromRange method. Getting this: No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes: What is wrong with my code? NSAttributedString *val=self.textview.attributedText; NSData *data = [val RTFDFromRange:NSMakeRange(0, self.textview.text.length) documentAttributes:nil]; NSAttributedString does not have a method called RTFDFromRange for iOS, but only for Mac OS X. To convert NSAttributedString to NSData in iOS, you can try these two approaches: 1. Using initWithData :

AVPlayer loading AVAsset from file that is appended simultaneously by external source (for macOS and iOS)

大城市里の小女人 提交于 2019-12-04 01:24:24
I have a question concerning the use of AVFoundation’s AVPlayer (probably applicable to both iOS and macOS). I am trying to playback audio (uncompressed wav) data that come from a channel other than the standard HTTP Live Streaming. The case: Audio data packets come compressed in a channel along with other data the app needs to work with. For example, video and audio come in the same channel and get separated by a header. After filtering, I get the audio data and decompress them to a WAV format (does not contain headers at this stage). Once the data packets are ready (9600 bytes each for 24k,