key-value-observing

Why would you use an ivar?

浪尽此生 提交于 2019-12-27 10:35:40
问题 I usually see this question asked the other way, such as Must every ivar be a property? (and I like bbum's answer to this Q). I use properties almost exclusively in my code. Every so often, however, I work with a contractor who has been developing on iOS for a long time and is a traditional game programmer. He writes code that declares almost no properties whatsoever and leans on ivars. I assume he does this because 1.) he's used to it since properties didn't always exist until Objective C 2

NSCollectionView Master detail binding configuration

爷,独闯天下 提交于 2019-12-25 03:58:06
问题 I have the following models in my application. Board , holds a NSMutableArray property lists of type List below List , holds a NSArray property cards of type Card below Card , has a NSString property name The relationship is thus Board --> to-many List --> to-many Card I have a NSCollectionView based master-detail interface, where I want to display Boards in the master and its corresponding Lists+Cards in the detail view. The master interface is fine, the elements Board are displayed nicely.

What's the most *simple* way to implement a plain data object which conforms key-value-observing?

痴心易碎 提交于 2019-12-25 03:46:10
问题 What's the most simple way to implement a plain data object which conforms key-value-observing? 回答1: Make an class with properties for its plain value attributes and KVC-compliant collection accessors for collections. Foundation magic will take care of the notifications for a simple object like that. 来源: https://stackoverflow.com/questions/5386497/whats-the-most-simple-way-to-implement-a-plain-data-object-which-conforms-key

How can I get int values from the change dictionary in KVO method observeValueForKeyPath:ofObject:change:context:?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 13:20:05
问题 I am observing changes in the rate property of an AVPlayer by calling the following method on it like so: addObserver:sharedPlayerManagerInstance forKeyPath:@"rate" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:0]; The change dictionary I get back from observeValueForKeyPath:ofObject:change:context: is therefore: change = { kind: 1, new: 1, old: 0 } I checked the class of each value, and it turns out to be __NSCFNumber. However, when I try to convert [change

AVPlayerItem.duration returns as NaN even after player.status == .readyToPlay

霸气de小男生 提交于 2019-12-24 05:54:47
问题 I have an implementation using KVO on player.status much like the suggestion documented here. Here's the relevant bits: var player: AVPlayer? var url = URL(string: "some video url")! override func viewDidLoad() { super.viewDidLoad() initializeVideoPlayer() } func initializeVideoPlayer() { let playerItem = AVPlayerItem(url: url) self.player = AVPlayer(playerItem: playerItem) let playerLayer = AVPlayerLayer(player: player) playerLayer.frame = self.view.layer.bounds videoView.layer.addSublayer

AVPlayerItem.duration returns as NaN even after player.status == .readyToPlay

霸气de小男生 提交于 2019-12-24 05:54:05
问题 I have an implementation using KVO on player.status much like the suggestion documented here. Here's the relevant bits: var player: AVPlayer? var url = URL(string: "some video url")! override func viewDidLoad() { super.viewDidLoad() initializeVideoPlayer() } func initializeVideoPlayer() { let playerItem = AVPlayerItem(url: url) self.player = AVPlayer(playerItem: playerItem) let playerLayer = AVPlayerLayer(player: player) playerLayer.frame = self.view.layer.bounds videoView.layer.addSublayer

performSelector in NSOperation subclass

[亡魂溺海] 提交于 2019-12-24 00:52:35
问题 I couldn't find an answer anywhere else on the net so any help would be appreciated. I am tying to create a system whereby I can retrieve the results of an NSOperation task, which I understand cannot be done by concrete subclasses such as NSInvocation. I have an NSOperation subclass ( TheEngine ) which is abstract by convention and must be extended to implement the function -main , to include the body of code to execute. TheEngine contains the following initialisation function whose job is

Why does OCMock partialMock break KVO?

不羁的心 提交于 2019-12-23 12:57:54
问题 If I have an object that uses KVO to observe a property on some object and then create a partial mock for that observer I no longer receive any notifications. Why is this? Here's a minimal example: @interface TestPartialMockAndKVO : SenTestCase @end @implementation TestPartialMockAndKVO - (void)test { // Should print "Changed!" when foo property is changed MyObserver* myObserver = [[[MyObserver alloc] init] autorelease]; // But with this line, there is no print out [OCMockObject

How to wait for a given time and only perform last function call

血红的双手。 提交于 2019-12-23 09:25:50
问题 Let's say I have a class named Person , with variables like firstName and lastName . I am listening to changes in these variables using a reactiveCocoa-framework, but let's say I'm only using the built in KVO-listening, like the didSet{} . So assume I have this code: let firstName:String { didSet{ self.nameDidChange() }} let lastName: String { didSet{ self.nameDidChange() }} func nameDidChange(){ print("New name:", firstName, lastName} Every time I'd change either the first name or the last

Remove Observer issue in KVO in ios

家住魔仙堡 提交于 2019-12-23 05:22:26
问题 I have a table which is filled with an array of objects, which I am observing, and when I delete all the objects, I remove the observer , but the problem is that when I delete all the objects in array and then again start adding it to the array I get removeObserver issue. I have a strong reference to my object I am adding Observer this way [self.object addObserver:self forKeyPath:kTaskCompletedKey options:NSKeyValueObservingOptionNew context:&kTaskObservationContext]; and I am removing it