Date   

Re: Binding to object returned by custom getter

Quincey Morris
 

On Jul 19, 2017, at 13:14 , Jack Brindle <jackbrindle@...> wrote:

It is permissible to use a method to do the calculating as it appears you have done, but you must call the willChange… and didChange…
methods at the [beginning] and end of the calculation in order for the KVO to succeed.

This represents a truth about KVO compliance for some scenarios, but the problem in this case is one level more subtle. The binding is observing the *wrong* instance of the velocity object. The only direct solution in this case is to use a stored property instead. (It can still be both derived and stored.)

Other solutions:

— Derive two additional properties, say “velocityX” and “velocityY”, and bind to those.

— Write two value transformers, bind to “velocity”, and use the value transformers to get the X and Y components.

But storing a reference to the current velocity object seems simpler.


On Jul 19, 2017, at 13:31 , Alex Zavatone <zav@...> wrote:

I am welcome to be corrected here.

You are correct, although I wouldn’t swear to the exact memory management consequences of this scenario.


Re: Binding to object returned by custom getter

Alex Zavatone
 


On Jul 19, 2017, at 12:29 PM, Quincey Morris <quinceymorris@...> wrote:

Yes, that’s exactly the reason. By returning a new object from the getter, you are making the property non-KVO-compliant.

KVO observes a known object.  If you return another one, then you need to remove the observer from your old object and add it to your new one.

KVO is going, “I’m looking at this thing.”

If the accessor for that thing returns an identical copy of that thing, but one that is at another memory address, KVO doesn’t know that there’s a new thing.  It’s still looking at the slot that holds the old thing.

What’s even more dangerouserer is that if a KVO event was triggered on that old object and you check the KVO event data within observeValueForKeyPath: ofObject: change: context: and you check anything on the object without checking to see if it exists, you’re going to crash your app.

While I love KVO, people much smarter than I prefer notifications sent to items in known scopes, rather than observing known objects for reasons like the crashy thing above.

The known scoped object can choose to respond to the messages/notifications or to ignore them.

I am welcome to be corrected here.

- Z


Re: Binding to object returned by custom getter

Jack Brindle
 

I think I would have a property that holds the velocity that is calculated in response to the keyPathsForValues… method being fired.
Then just bind to that property. Make sure that everything that is used to calculate velocity is included in the keyPathsForValues…
method or this won’t work very well.

It is permissible to use a method to do the calculating as it appears you have done, but you must call the willChange… and didChange…
methods at the bingeing and end of the calculation in order for the KVO to succeed. You really cannot call the method just to get the
value (it will fire the KVO, causing an infinite loop), which leads you right back to the method suggested above.

- Jack

On Jul 19, 2017, at 2:54 AM, Jonathan Taylor <jonathan.taylor@...> wrote:

Hi all,

I have a property "velocity" that returns a custom object representing a 2D vector. That vector object has properties "x" and "y". From time to time, the value of velocity to be displayed will change. Changes are deduced through keyPathsForValuesAffectingValueForKey logic (I'm just mentioning that in case it's relevant).

I have a custom getter for velocity, which returns an autoreleased vector object that I construct then and there, containing the current velocity value. I then have a UI element that is bound to velocity.x and .y. When the velocity to be displayed changes, I get the following error:

2017-07-19 10:43:37.336 StackViewer[15059:303] Cannot update for observer <NSAutounbinderObservance 0x19f217590> for the key path "velocity.y" from <PIVSliceViewer 0x10194de80>, most likely because the value for the key "velocity" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the PIVSliceViewer class.

I am a bit surprised at this - it had seemed to me that I was not doing anything unreasonable here, and I can't think of an obvious additional notification-related thing I should be adding to solve the problem. I am imagining it might have to do with the fact that I am returning a different (temporary) object for velocity, since I construct them on the fly in the getter - but that did not seem like an unreasonable thing to be doing.

Does this symptom sound like something people would expect or recognise? Any suggestions about what I am missing that could solve this? I guess I might be able to fix things by introducing an explicit backing variable for the velocity property, and updating that, but I think I'd prefer my current approach (which I think is simpler and cleaner) if I can work out what the problem is here...

Thanks for any suggestions
Jonny


Re: Binding to object returned by custom getter

Quincey Morris
 

On Jul 19, 2017, at 02:54 , Jonathan Taylor <jonathan.taylor@...> wrote:

I am imagining it might have to do with the fact that I am returning a different (temporary) object for velocity, since I construct them on the fly in the getter

Yes, that’s exactly the reason. By returning a new object from the getter, you are making the property non-KVO-compliant.

KVO is reference-based, not value-based. When you observe the key-path “velocity.y” of some object, there is a actually a chain of observations:

1. some object (instance) observed for changes to key (property) “velocity”
2. some velocity (instance of the vector class) observed for changes to key “y”

Returning a different velocity object from the first object returns an *unobserved* object, which causes the observation of the original vector instance to be meaningless.

The potentially confusing part of this is that the *last* key in the key-path, although it represents an object**, isn’t observed. Observations are needed only when taking objects and properties pairwise.


** In your case, the property “y” might be a scalar, probably a CGFloat or a double. From the observer’s point of view, though, it is a NSNumber object. KVC has internal “magic” that automatically converts values of known scalar types (standard numeric and Boolean types, for example) into objects.


Re: dispatch_async question

 


On Jul 19, 2017, at 6:30 AM, Dave <dave@...> wrote:

As far as I am aware, the only thing using dispatch_async does, is call the delegate sometime after the current method as returned, which I can’t see is of any benefit and makes things much hard to understand.

The call you showed runs the block on the main thread. That aspect may be crucial. Does the code this is part of run on a different thread/queue?

Also, it can often be very useful to defer some code until after the current event completes; this is often called a “delayed perform” because the old school way to do it is by calling -performSelector:withObject:afterDelay:. An async dispatch to the current queue is the moral equivalent. In the case of this statement, I couldn’t tell you why this is useful without knowing more about the code overall.

—Jens


Binding to object returned by custom getter

Jonathan Taylor
 

Hi all,

I have a property "velocity" that returns a custom object representing a 2D vector. That vector object has properties "x" and "y". From time to time, the value of velocity to be displayed will change. Changes are deduced through keyPathsForValuesAffectingValueForKey logic (I'm just mentioning that in case it's relevant).

I have a custom getter for velocity, which returns an autoreleased vector object that I construct then and there, containing the current velocity value. I then have a UI element that is bound to velocity.x and .y. When the velocity to be displayed changes, I get the following error:

2017-07-19 10:43:37.336 StackViewer[15059:303] Cannot update for observer <NSAutounbinderObservance 0x19f217590> for the key path "velocity.y" from <PIVSliceViewer 0x10194de80>, most likely because the value for the key "velocity" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the PIVSliceViewer class.

I am a bit surprised at this - it had seemed to me that I was not doing anything unreasonable here, and I can't think of an obvious additional notification-related thing I should be adding to solve the problem. I am imagining it might have to do with the fact that I am returning a different (temporary) object for velocity, since I construct them on the fly in the getter - but that did not seem like an unreasonable thing to be doing.

Does this symptom sound like something people would expect or recognise? Any suggestions about what I am missing that could solve this? I guess I might be able to fix things by introducing an explicit backing variable for the velocity property, and updating that, but I think I'd prefer my current approach (which I think is simpler and cleaner) if I can work out what the problem is here...

Thanks for any suggestions
Jonny


Re: dispatch_async question

Alex Zavatone
 

On Jul 19, 2017, at 9:51 AM, Fritz Anderson <anderson.fritz@...> wrote:

On Jul 19, 2017, at 8:30 AM, Dave <dave@...> wrote:

In the following code, does it *need* to use the dispatch_async function?

dispatch_async(dispatch_get_main_queue(), ^{
if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)])
[[self delegate] gameCenterManager:self availabilityChanged:successDictionary];
});

It sometimes uses it and sometimes it calls the delegate inline. I’m wondering why?

As far as I am aware, the only thing using dispatch_async does, is call the delegate sometime after the current method as returned, which I can’t see is of any benefit and makes things much hard to understand.
It's hard to understand because concurrency is the most difficult task in software engineering. (A debate on "hardest task" might be fun. Please let's not.) If the code you're looking at was thoughtfully-written, the decision to dispatch or not was deliberate.

UI work must be done on the main thread, one operation at a time — in other words, serially, which is easier if you have a queue manager to make sure everything happens in turn. Letting multiple threads interrupt each other as they force a label to change its layout will end badly.

The original code assumes the delegate may require the main thread.

## Assume the caller is **guaranteed** to be on the main thread

The assumption is not to be made lightly. If it's true, this is easy. Call directly. There may be further issues (do not monopolize the UI thread) but those are beyond the scope of your question.

## Assume the caller might not be on the main thread

The work has to be done on the main thread (so the original code assumes). You must use GCD to hand it over to the main dispatch queue. The main queue makes sure the work gets its turn with no interference.

That answers the literal question of why the code is sometimes dispatched, sometimes not. The decisions and the design that drove them (such as why "do it later" may also be the right strategy) are much harder. You can learn, but not in a single email.

— F
I’m glad that Fritz chimed in here before I risked an answer.

My gut feeling was that, “well, even if it isn’t required, seeing the word ‘_async’ in the function clearly states to you that the intent of the operation is for it to be async - no assumption by the programmer is needed.”

It’s kind of like, “well, even if it isn’t needed, it’s certainly clearer to whomever is writing or reviewing the code.”

I think that if you are following the debugger, and observing what is happening, the results may be confusing when observing what the debugger is telling you. This is one of the things I have learned to accept, assuming that I will figure it out later, if needed.

Is that the case, Dave?
- Alex Zavatone


Re: dispatch_async question

Fritz Anderson
 

On Jul 19, 2017, at 8:30 AM, Dave <dave@...> wrote:

In the following code, does it *need* to use the dispatch_async function?

dispatch_async(dispatch_get_main_queue(), ^{
if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)])
[[self delegate] gameCenterManager:self availabilityChanged:successDictionary];
});

It sometimes uses it and sometimes it calls the delegate inline. I’m wondering why?

As far as I am aware, the only thing using dispatch_async does, is call the delegate sometime after the current method as returned, which I can’t see is of any benefit and makes things much hard to understand.
It's hard to understand because concurrency is the most difficult task in software engineering. (A debate on "hardest task" might be fun. Please let's not.) If the code you're looking at was thoughtfully-written, the decision to dispatch or not was deliberate.

UI work must be done on the main thread, one operation at a time — in other words, serially, which is easier if you have a queue manager to make sure everything happens in turn. Letting multiple threads interrupt each other as they force a label to change its layout will end badly.

The original code assumes the delegate may require the main thread.

## Assume the caller is **guaranteed** to be on the main thread

The assumption is not to be made lightly. If it's true, this is easy. Call directly. There may be further issues (do not monopolize the UI thread) but those are beyond the scope of your question.

## Assume the caller might not be on the main thread

The work has to be done on the main thread (so the original code assumes). You must use GCD to hand it over to the main dispatch queue. The main queue makes sure the work gets its turn with no interference.

That answers the literal question of why the code is sometimes dispatched, sometimes not. The decisions and the design that drove them (such as why "do it later" may also be the right strategy) are much harder. You can learn, but not in a single email.

— F


Re: How to Log Off from Game Center using the Simulator?

Gary L. Wade
 

If you’re only using one Xcode, then you probably should do the regular things: quit Xcode, reboot, etc.  I just tried that version and could scroll to the Game Center item in Settings.  Also, don’t forget about filing a bug.  The developer team does read those; in fact, I got a direct reply from one developer yesterday, not just a “Engineering has requested more info from you.”

On Jul 19, 2017, at 7:27 AM, Dave <dave@...> wrote:

Hi,

I’m using XCode 8.3.3 is there a better/newer version available? I’m having all kind of issues with this version and wondered if worth updating?

All the Best
Dave

On 19 Jul 2017, at 16:23, Gary L. Wade <garywade@...> wrote:

It sounds like you’ve got an issue with Xcode and the Simulators.  If you’ve been playing with beta Xcode and released Xcode at the same time, all sorts of weirdness can happen.  Try quitting Simulator, Instruments, and any other Xcode utility apps, then quit Xcode, and then launch the Xcode you care about using.  If you still have an issue, check your trackpad, mouse, other physical devices, etc., and if that doesn’t work, you might have a bug with Simulator that should be reported to Apple.  If you’re using accessibility in any manner to do your navigation within Simulator, be sure to note that.

I personally saw no issues with doing the operation you suggested with the most recent beta of Xcode.

On Jul 19, 2017, at 6:07 AM, Dave <dave@...> wrote:

Hi,

Game Centre doesn’t show up in the Simulator Settings…..  In fact, when I open the settings App on the Simulator (iPhone 5s - iOS 10.3 (14E8301)), I can’t fully see the bottom item in the list (only the top few lines of pixels are visible) and it won’t scroll. I can just about click the last item in the list and if I do, it take me to the “Photo & Camera” panel.

Not sure what is going on?

All the Best
Dave




Re: How to Log Off from Game Center using the Simulator?

Dave
 

Hi,

I’m using XCode 8.3.3 is there a better/newer version available? I’m having all kind of issues with this version and wondered if worth updating?

All the Best
Dave

On 19 Jul 2017, at 16:23, Gary L. Wade <garywade@...> wrote:

It sounds like you’ve got an issue with Xcode and the Simulators.  If you’ve been playing with beta Xcode and released Xcode at the same time, all sorts of weirdness can happen.  Try quitting Simulator, Instruments, and any other Xcode utility apps, then quit Xcode, and then launch the Xcode you care about using.  If you still have an issue, check your trackpad, mouse, other physical devices, etc., and if that doesn’t work, you might have a bug with Simulator that should be reported to Apple.  If you’re using accessibility in any manner to do your navigation within Simulator, be sure to note that.

I personally saw no issues with doing the operation you suggested with the most recent beta of Xcode.

On Jul 19, 2017, at 6:07 AM, Dave <dave@...> wrote:

Hi,

Game Centre doesn’t show up in the Simulator Settings…..  In fact, when I open the settings App on the Simulator (iPhone 5s - iOS 10.3 (14E8301)), I can’t fully see the bottom item in the list (only the top few lines of pixels are visible) and it won’t scroll. I can just about click the last item in the list and if I do, it take me to the “Photo & Camera” panel.

Not sure what is going on?

All the Best
Dave



Re: How to Log Off from Game Center using the Simulator?

Gary L. Wade
 

It sounds like you’ve got an issue with Xcode and the Simulators.  If you’ve been playing with beta Xcode and released Xcode at the same time, all sorts of weirdness can happen.  Try quitting Simulator, Instruments, and any other Xcode utility apps, then quit Xcode, and then launch the Xcode you care about using.  If you still have an issue, check your trackpad, mouse, other physical devices, etc., and if that doesn’t work, you might have a bug with Simulator that should be reported to Apple.  If you’re using accessibility in any manner to do your navigation within Simulator, be sure to note that.

I personally saw no issues with doing the operation you suggested with the most recent beta of Xcode.

On Jul 19, 2017, at 6:07 AM, Dave <dave@...> wrote:

Hi,

Game Centre doesn’t show up in the Simulator Settings…..  In fact, when I open the settings App on the Simulator (iPhone 5s - iOS 10.3 (14E8301)), I can’t fully see the bottom item in the list (only the top few lines of pixels are visible) and it won’t scroll. I can just about click the last item in the list and if I do, it take me to the “Photo & Camera” panel.

Not sure what is going on?

All the Best
Dave


dispatch_async question

Dave
 

Hi All,

In the following code, does it *need* to use the dispatch_async function?

dispatch_async(dispatch_get_main_queue(), ^{
if ([[self delegate] respondsToSelector:@selector(gameCenterManager:availabilityChanged:)])
[[self delegate] gameCenterManager:self availabilityChanged:successDictionary];
});

It sometimes uses it and sometimes it calls the delegate inline. I’m wondering why?

As far as I am aware, the only thing using dispatch_async does, is call the delegate sometime after the current method as returned, which I can’t see is of any benefit and makes things much hard to understand.

Am I missing something? This code is attempting to authenticate a Game Center Player, (the whole method is copied below), it may prompt the user to authenticate, I’m wondering if its something to do with this, although again, I can’t see that dispatch_async is necessary or or is of any benefit?

I’m trying to debug my Game Center Code and decided to see how someone else did it, but I’m getting more confused by the minute,

All the Best
Dave


Re: How to Log Off from Game Center using the Simulator?

Dave
 

Hi,

Game Centre doesn’t show up in the Simulator Settings….. In fact, when I open the settings App on the Simulator (iPhone 5s - iOS 10.3 (14E8301)), I can’t fully see the bottom item in the list (only the top few lines of pixels are visible) and it won’t scroll. I can just about click the last item in the list and if I do, it take me to the “Photo & Camera” panel.

Not sure what is going on?

All the Best
Dave

On 18 Jul 2017, at 17:09, Dave <dave@...> wrote:

Hi All,

Using the Simulator, how can I log off from Game Centre? I’ve logged on ok once, but now I want to test it again from not being logged in.

Thanks a lot
Dave




Re: Game Center Multi-Player Question

Quincey Morris
 

On Jul 18, 2017, at 02:37 , Dave <dave@...> wrote:

I’m not quite sure how I would go about implementing the AI’s though, this is a turn based board game and as far as I can see, only “Real” players get a Move

You could have each real player device calculate the following AI move(s), and pass multiple moves to the next real player. Or, if you have a single “server” device, the turn can bounce back to that device whenever it’s the AI’s turn to play.


Re: How to Log Off from Game Center using the Simulator?

Quincey Morris
 

On Jul 18, 2017, at 08:09 , Dave <dave@...> wrote:

Using the Simulator, how can I log off from Game Centre?

You should be able to log off using Settings, just like on a device.


Game Center loadPlayersForIdentifiers deprecated - How to fix?

Dave
 

Hi,

I’m getting a warning on this method:

[GKPlayer loadPlayersForIdentifiers:theMatch.playerIDs withCompletionHandler:^(NSArray* thePlayerArray,NSError* theErrorInfo)

It says to replace it with “players”, however this won’t fix it, it will break it, since the above is working with PlayerIDs not Player Objects. So, should write a method that gets the Array of Player Objects, then creates a new array of PlayerIDs by iterating over the Player Objects? This seems like a giant waste of time, since it just means I’m doing the work instead of GKPlayer, not sure why is was deprecated?

All the Best
Dave


To do list need help adding row to table view from a bar button item.

Taylor Arndt
 

Hi,
So my to-do list is almost done, and I have one problem, I imbedded my
table view controller in a navigation controller and all is well, until
I try to add a row to the table view, o we have a problem. Basically
how to make an action with a bar button item? code is below.
tasks table view controler
//
// tasksTableViewController.swift
// todo lists
//
// Created by Taylor Arndt on 7/17/17.
// Copyright © 2017 Taylor Arndt. All rights reserved.
//

import UIKit

class tasksTableViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Uncomment the following line to preserve selection between
presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in
the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}

override func tableView(_ tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return name.count
}

/*
override func tableView(_ tableView: UITableView, cellForRowAt
indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:
"Task", for: indexPath)

// Configure the cell...

let name = name[indexPath.row]

cell.nameLabel.text = name.name


return cell
}
*/

/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt
indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/

/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit
editingStyle: UITableViewCellEditingStyle, forRowAt indexPath:
IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert
it into the array, and add a new row to the table view

name.apend() }
}
*/

/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt
fromIndexPath: IndexPath, to: IndexPath) {

}
*/

/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt
indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a
little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}


task.swift
//
// task.swift
// todo lists
//
// Created by Taylor Arndt on 7/17/17.
// Copyright © 2017 Taylor Arndt. All rights reserved.
//
import Foundation

var name=[ String]()
I would appreciate any help with this project, as I have came a long
ways doing it.
Taylor




--
Taylor


Re: Trying to make Arc happy

 


On Jul 18, 2017, at 1:07 AM, Gerriet M. Denkmann <g@...> wrote:

- (BOOL)isNiceAndHas: (NSArray **)friends;

Method parameter of type ‘NSArray *__autoreleasing *' with no explicit ownership

I think you resolve this by changing it to the form shown in the error messages, i.e.

- (BOOL)isNiceAndHas: (NSArray *__autoreleasing *)friends;

—Jens


How to Log Off from Game Center using the Simulator?

Dave
 

Hi All,

Using the Simulator, how can I log off from Game Centre? I’ve logged on ok once, but now I want to test it again from not being logged in.

Thanks a lot
Dave


Re: GKSession - More Game Center Question

Dave
 

HI,

I said GKSession in my last post, I was looking at “GKTurnBasedEventListener” and I’m wondering if I can use “GKTurnBasedMatch” without having to worry about “GKSession” and/or the iCloud.

Cheers
Dave

On 18 Jul 2017, at 15:32, Dave <dave@...> wrote:

Hi All,

I have a Question about GKSession and about turn based games in GC in general.

Firstly, do I *need* to use GKSession in order to create a Turn Based Game? If so, then it looks like I will also have to enable iCloud as a capability of my App?

My other question relates the the Game Center documentation. All I can find online is the XCode HTML based docs, is there a PDF available for GameKit? Trying to learn something as complex as this using HTML is like pulling teeth. I sooooooo wish Apple would supply the PDFs again. Whoever thought the current document system was in any way better for the end user than having a collection of PDFs needs serious physiological help.

All the Best
Dave




1361 - 1380 of 1475