Date   

Game Kit Turn Based Match?

Dave
 

Hi,

I’m trying to understand how to use the GKTurnBasedMatch facility in Game Kit.

From reading the documentation, I’m not quite sure how make it work with the rules of the game I am developing.

In my game, players can perform the following in the following order:

1. Make a Move (play a piece from their “Stash” on the Board).
2.. Draw a New Piece (randomly pick a new piece that is placed in the players “Stash”).

However, a player may not be able to make a move and if all the pieces have been picked, then can’t draw a piece either. The games ends (and a winner is determined) when no player can perform either action, and then a winner is determined from the current Score of each player.

This doesn’t fit into the way the documentation describes the GKTurnBasedMatch class working, so I’m wondering if I can still use it. The thing is that there is a fair amount of work to do in order to get it to the stage where I can see if I can bend GKTurnBasedMatch to my needs, but I’d rather know up-front is possible.

Does anyone know if there is a Game Kit Specific Mailing list around?

All the Best
Dave


Re: dispatch_async question

Dave
 

The thing is, in my case, it actually doesn’t matter if its run on the Main thread or not, since the delegate its calling does not itself do any UI work.

I should have probably said - “it actually doesn’t matter if its run on the Main thread or not, since the delegate its calling is thread safe”.

The class that the delegate calls to update the UI isn’t thread safe, but I think its better to handle its threading requirements in the View Controller itself, since the Game Engine is also Thread Safe…..

All the Best
Dave


NSWindowController and window release

Graham Cox
 

Here we go again… another memory management issue.

I have a fairly simple situation where I instantiate a window controller (NSWindowController subclass), which loads its window from a nib file. The window contains one custom view.

When the window is closed, the window controller (as its delegate) gets the -windowShould Close:, -windowWillClose: etc. as normal. The owner of the window controller (the app delegate in this case) retains it until it receives the -windowWillClose: notification, at which point it’s removed from its list of windows. Then, the window controller is deallocated, as expected.

However, the window it is controlling is never deallocated, and so neither is the custom view within it. The result is a lot of leaks.

I have been through the code with a fine-tooth comb, nothing that shouldn’t is retaining the window, nor the view.

There are no issues flagged up by running the analyser either.

The documentation for -[NSWindow releaseWhenClosed] states:

"The default for NSWindow is YES; the default for NSPanel is NO. Release when closed, however, is ignored for windows owned by window controllers. Another strategy for releasing an NSWindow object is to have its delegate autorelease it on receiving a windowShouldClose: message.”

In the nib ‘release when closed’ is set for the window, but apparently this is ignored for windows that have an associated windowController.

Following its advice, I tried autorelease-ing the window in the -windowShouldClose: method - result, EXC_BAD_ACCESS (whatever the state of the setting in the nib).

So what’s the deal - how do I get a window controller to let go of its window correctly?

—Graham


Re: NSWindowController and window release

Graham Cox
 

OK, I figured it out.

What was important to me was that the custom view was deallocated. Therefore it was the view’s -dealloc I was logging, not the window’s. I inferred, incorrectly, that it was the window that wasn’t going away. In fact it was, but the view wasn’t.

The custom view is set up as a layer hosting view, and I set the view to be the layer’s -layoutManager. That’s a strong property, so a retain cycle was created there.

Once understood, easily solved.

I do vaguely recollect something about this possibility in documentation a long time ago, but going through it just now, could find no mention of it. In the end, the only canonical documentation is the headers. Ho hum.


—Graham

On 27 Jul 2017, at 9:39 pm, Graham Cox <graham@...> wrote:

Here we go again… another memory management issue.


Re: Memory management of document modal panels

Jeff Laing
 

According to Mike Ash
(https://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html
- see Caveats) self should be being retained.

Apple (https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html#//apple_ref/doc/uid/TP40007502-CH6-SW3)
also suggest that if you reference a local variable inside the block,
then self will be retained.

I can't see anywhere where they suggest the behavior changes with the
retention-model being used; just that a block doesn't retain anything
until it is copied and in the case where you pass a block in as a
completion handler, it is that methods responsibility to copy the
block.

Jeff Laing <jefflaing@...>
-------------------------------------------------------------------------------
"... because even if we can't um, if we can't rise to his level, no at
least we can, we can drag him down to ours ..."
-- William Gaddis, "JR".


SceeneKit not picking up arrow keys correctly?

Alex Hall
 

Hi all,
I'm following a tutorial on SceneKit, which sets up a few nodes, a camera, and some keyboard capturing to let the user arrow around the sceene. The author of the code says it works on his machine, and everything looks fine to me both in the code and in the debug console.

However, when I press a plain arrow key, nothing happens. Not only do I not move, but my keyUp event in the delegate doesn't capture anything, as though the key wasn't pressed. If I press command with an arrow, that arrow's key code is captured by the function, but there's no masking going on that would require any modifier.

I'm sending this from my phone at work, so I don't have the actual sample code to include, sorry. I'm hoping someone has seen these oddities with key capturing in SceneKit and has some idea of what I could try. I'm on 10.13, Xcode 9, both the latest betas. I'm building a Mac app. Thanks in advance!

Sent from my iPhone


nib loading error on foreign systems

James Walker
 

I have a view controller that loads from a nib.  I only have the nib in English, no other localizations.  When I run with my normal American English setup, all is well.  But if I set the language and region to German, then after loadView has been called, half of the outlets are nil.  I don't see any error messages in the debug log, and the build log does not report any problems with the .xib file.  Any suggestions?


Re: nib loading error on foreign systems

James Walker
 

On 8/2/2017 10:57 AM, James Walker wrote:

I have a view controller that loads from a nib.  I only have the nib in English, no other localizations.  When I run with my normal American English setup, all is well.  But if I set the language and region to German, then after loadView has been called, half of the outlets are nil.  I don't see any error messages in the debug log, and the build log does not report any problems with the .xib file.  Any suggestions?

Sorry, I misunderstood the situation.  The Xcode debugger was lying to me about some member variables being NULL.  The real problem was an assertion failure in -[NSCell _objectValue:forString:errorDescription:] which had something to do with a text field having an NSNumberFormatter that it should not have had.


How to print class name in Swift

Gerriet M. Denkmann
 

This works (prints either null, NSString or NSNumber)

- (id)transformedValue:(id)value
{
NSLog(@"%s value %@ %@",__FUNCTION__, [value class], value);

}

But my Swift version:

override func transformedValue(_ value: Any?) -> Any?
{
print(“value \(String(describing: type(of: value))) \(String(describing:value))")

}

just prints:
value Optional<Any> Optional(33)

I do not want to know what the compiler things about value, I want to know what value is at run-time.

How can this be done?

Gerriet.


Re: How to print class name in Swift

Dave Fernandes
 

My understanding is that an optional is just a type that wraps another type. So you need to unwrap the optional before calling String(describing: type(of: value))) to get the class name that you are interested in displaying. In other words, your print statement should be replaced with:

if let unwrappedValue = value
{
print(“value \(String(describing: type(of: unwrappedValue))) \(String(describing: unwrappedValue))")
}
else
{
print(“value nil”)
}

(Warning: code written in Mail.)

On Aug 7, 2017, at 12:25 PM, Gerriet M. Denkmann <g@...> wrote:

This works (prints either null, NSString or NSNumber)

- (id)transformedValue:(id)value
{
NSLog(@"%s value %@ %@",__FUNCTION__, [value class], value);

}

But my Swift version:

override func transformedValue(_ value: Any?) -> Any?
{
print(“value \(String(describing: type(of: value))) \(String(describing:value))")

}

just prints:
value Optional<Any> Optional(33)

I do not want to know what the compiler things about value, I want to know what value is at run-time.

How can this be done?

Gerriet.


respondsToSelector in Swift

Gerriet M. Denkmann
 

How to translate this into Swift

- (id)transformedValue:(id)value
{
if ( ![value respondsToSelector: @selector(doubleValue) ] )
{
NSLog(@"%s Error value %@ %@",__FUNCTION__, [value class], value);
return @50;
};

NSNumber *input = (NSNumber *)value; // maybe NSString
double output = …
return @(output)
}

Gerriet.


Re: respondsToSelector in Swift

Quincey Morris
 

On Aug 7, 2017, at 09:51 , Gerriet M. Denkmann <g@...> wrote:

How to translate this into Swift

It’s not clear which part of that is giving you trouble, but I was able to do this in a playground (Swift 4, Xcode 9), and got the expected output:

class A: NSObject
{
@objc func transformedValue (value: AnyObject) -> AnyObject
{
if !value.responds (to: #selector (getter: AnyObject.doubleValue))
{
// log statement omitted
return NSNumber (value: 52)
}

return NSNumber (value: value.doubleValue)
}
}

let a = A ()

print (a.transformedValue (value: NSNumber (value: 10)))
print (a.transformedValue (value: "20" as NSString))
print (a.transformedValue (value: NSObject ()))

Note that Swift’s “AnyObject” has the same magic behavior as Obj-C’s id, that the compiler will let you call any known method on a receiver variable declared with the type.


Re: respondsToSelector in Swift

Gerriet M. Denkmann
 

On 8 Aug 2017, at 00:57, Quincey Morris <quinceymorris@...> wrote:

On Aug 7, 2017, at 09:51 , Gerriet M. Denkmann <g@...> wrote:

How to translate this into Swift
It’s not clear which part of that is giving you trouble,
Mostly the #selector.
And also, I did not know about AnyObject.

This now seems to work:

final class SpeedValueTransformer: ValueTransformer
{
override class func transformedValueClass() -> AnyClass { return NSNumber.self }

override func transformedValue(_ value: Any?) -> Any?
{
let anyValue = value as AnyObject

if anyValue.responds(to: #selector (getter: AnyObject.doubleValue))
{
let optionalInput = anyValue.doubleValue

if let input = optionalInput
{
let output = input * 3 + 42
return output // NSNumber (value: output)
}
}

return 50 // error case
}
}

Thanks for your help!

Kind regards,

Gerriet.


Changing Folder Name in Xcode

Gerriet M. Denkmann
 

I have a project:

Some Folder
Some.xcodeproj
Old and Bad Name
lots of stuff

I would like to change the folder “Old and Bad Name” to “Nice new name”

I could rename this folder in Finder and then reimport “lots of stuff” into Xcode.
But this is very tedious and error prone.

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/project.pbxproj - but I am afraid of messing with Xcode's private files.

Can Xcode (Version 8.3.3 (8E3004b)) do this for me? Some sort of refactoring?

Gerriet.


Re: Changing Folder Name in Xcode

Quincey Morris
 

On Aug 8, 2017, at 03:50 , Gerriet M. Denkmann <g@...> wrote:

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/project.pbxproj - but I am afraid of messing with Xcode's private files.

I wouldn’t edit the .pbxproj file. Under the assumption that your project has the files organized under yellow group “folder” icons (in the navigator pane, as opposed to blue “folder reference” icons), you can go ahead and rename the folder to its new name. (For Xcode 8, you should close the project before doing this, because this version has a bug where it doesn’t update the visuals of the navigator pane properly when a file appears or disappears. Re-open the project after the rename.)

When you get back to Xcode, all your source files will have turned red (in the navigator pane). Make sure the File tab of the utilities pane is shown. Select the top-level yellow group icon, then click on the tiny gray folder-like button under its name in the Files tab. You’ll get a standard open dialog, which you can use to choose a new (real) folder to associate with the group icon. Simply choose the newly-renamed folder. Then close and re-open the project, again because of the cosmetic bug mentioned above.

If all of your source file groups are relative to this base folder, all your files should now be black in the navigator. But, if any of the subgroups had other kinds of paths, you will need to repeat the previous step for each one that contains red files, choosing the relevant folder each time.

There’s one final step. There are some files specified by path in settings. Typically this includes the info.plist and the prefix header, if any. You will need to fix those relative paths manually in settings.

HOWEVER, if your project is under git source control, doing all this will likely bork your repository pretty well. AFAIK, Xcode 8 isn’t smart enough to change the relative paths inside the repository. In this case, you should probably find some other piece of software to update the names in the repository *first*, then re-open the project in Xcode and fix the groups’ paths.

ALTERNATIVELY, if you’re prepared to open your project in Xcode 9, it can handle this situation correctly. Before renaming anything, select the top level yellow group icon that contains your source code files. (This should be the one that has your bad old name.) In the navigator pane, select that group and press Enter to edit the name. When you change the name and press Enter, Xcode will rename the folder, and update all of the git information that depends on it. As before, if you have sub-groups that aren’t relative to this group, you’ll have to handle them in a separate step, and you’ll have to change a couple of build settings manually.


Re: Changing Folder Name in Xcode

Ben Kennedy
 

On 08 Aug 2017, at 10:16 am, Quincey Morris <quinceymorris@...> wrote:

HOWEVER, if your project is under git source control, doing all this will likely bork your repository pretty well. AFAIK, Xcode 8 isn’t smart enough to change the relative paths inside the repository. In this case, you should probably find some other piece of software to update the names in the repository *first*, then re-open the project in Xcode and fix the groups’ paths.
If you're using Git, this can be mitigated by simply using `git mv` to rename the directory (`git mv oldname newname`).

b


Re: Changing Folder Name in Xcode

Alex Zavatone
 

On Aug 8, 2017, at 5:50 AM, Gerriet M. Denkmann <g@...> wrote:

I have a project:

Some Folder
Some.xcodeproj
Old and Bad Name
lots of stuff

I would like to change the folder “Old and Bad Name” to “Nice new name”

I could rename this folder in Finder and then reimport “lots of stuff” into Xcode.
But this is very tedious and error prone.

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/project.pbxproj - but I am afraid of messing with Xcode's private files.

Can Xcode (Version 8.3.3 (8E3004b)) do this for me? Some sort of refactoring?

Gerriet.
On the right side of the project in one of the inspectors, there is a means of specifying the path to the item selected and how it is defined. Relative to Group, Relative to Project, Absolute Path, etc…

You can also duplicate your folder, set up the new name and then select the new path to the item from the inspector.

Does that help?

- Alex Zavatone


Re: Changing Folder Name in Xcode

Sean McBride
 

On Tue, 8 Aug 2017 17:50:13 +0700, Gerriet M. Denkmann said:

Or close Xcode, rename in Finder, then edit: Some.xcodeproj/
project.pbxproj - but I am afraid of messing with Xcode's private files.
I've done that, and it's worked fine for me.

Can Xcode (Version 8.3.3 (8E3004b)) do this for me? Some sort of refactoring?
If the files are referenced relative it their parent, then I think it's just a matter of re-pointing the folder. Go to Xcode File Inspector > Identity and Type > Location and click that little grey folder icon (that doesn't look like a button at all, of course).

Cheers,

Sean


Re: Changing Folder Name in Xcode

Gerriet M. Denkmann
 

Thanks to all who responded!

In my Xcode project, the yellow group “folder” icons in the navigator pane closely resemble the folder structure of my project. And I do not use git or similar.

This is what I did:

1. make sure that all relevant files had in the File inspector → Identity & Type → Location = Relative to Group

2. In Finder I duplicated and renamed the folder

3. Xcode File inspector → Identity & Type → Location clicked the Folder Icon and set the file name to new folder.

4. in Finder removed the old folder.

There were some glitches: I had to remove the. xcconfig things and add them again.
And some file are mentioned in Build Settings (e.g. Info.plist, .entitlement).
But these were minor issues.

Your hint with the folder-icon button in Xcode → File inspector → Identity & Type → Location proved to be extremely helpful.
Thanks to Quincey and Sean for mentioning this.

Kind regards,

Gerriet.


How to get full user name prior to 10.12?

Graham Cox
 

10.12 added a method to NSProcessInfo, -fullUserName.

How do I get the same info on earlier OS?

—Graham

141 - 160 of 1460