Strange errors after converting SceneKit sample code to Swift 3 - ios

I downloaded Apple's SceneKit sample code (fox.swift) and opened it up on Xcode 8 beta 6.
It asked me to convert the code to Swift 3, which I did.
When I try to run the code on my phone I receive the errors:
Value of type ‘SCNNode’ has no member ‘run’
Value of type ‘SCNNode’ has no member ‘add’
Sample lines where the error occurs:
cameraYHandle.run(actionY)
self.cameraYHandle.add(cameraYAnimation, forKey: nil)
This leads me to three questions:
1) Are the functions 'run' and 'add' gone on SCNNode for Swift 3?
2) If so, what should I replace them with?
3) If so, if so, why didn't Xcode's converter handled them already?
Thank you for your time :)
PS.: It runned well for Mac using Xcode 7.3.

As dan commented, these translations resulted in a code without errors:
run => runAction
add => addAnimation
play => playAudio
so,
cameraYHandle.run(actionY) becomes cameraYHandle.runAction(actionY)
and so on.
Thank you, Dan.

Related

Issue with String initializer in Swift when using format parameter

I'm getting an error for this line of Swift code in my XCode playground:
print(String(format: "%.2f", 3.345))
The error reads
No exact matches in call to initializer
I believe this means that I haven't used the right parameter names/order to call the initializer. However, when running this line of code while working on an iOS app or even in the online Swift playground http://online.swiftplayground.run/, the line runs without any issues.
When running it in the XCode playground or on my terminal through the Swift REPL however, it throws an error.
Why is this the case?
Foundation has to be imported before using String.
String is a Foundation type in swift.
I was corrected by Matt below in the comments.
String is built into swift and String(format: is in foundation.
I guess that's why the docs didn't show it as such.
Thank you for the correction.

availableRawPhotoPixelFormatTypes Missing in Xcode 12 beta 6

I get the following snippet:
let newPhotoSettings = AVCapturePhotoSettings(rawPixelFormatType: OSType(self.photoOutput.availableRawPhotoPixelFormatTypes.first!), processedFormat: nil)
When I build in Xcode 12 beta 6, I get the following error:
Value of type 'AVCapturePhotoOutput' has no member 'availableRawPhotoPixelFormatTypes'
When I check the API documentation (here), it does not show availableRawPhotoPixelFormatTypes as deprecated.
Anyone else has this issue?
UPDATE
The above errors are only present when I try to render SwiftUI preview for Home Screen Widget. If I run the project normally, it runs perfectly fine without errors.
Also, I am getting same error for preview pixel types:
photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: photoSettings.availablePreviewPhotoPixelFormatTypes[0]]
Value of type 'AVCapturePhotoSettings' has no member 'availablePreviewPhotoPixelFormatTypes'
It seems this is now split into two queries:
Use availableRawPhotoFileTypes to get the supported RAW file types, choose one of them, and then ask for the corresponding supported format types with supportedRawPhotoPixelFormatTypes(for fileType: AVFileType).
I think right now only DNG files are supported in iOS, but separating the APIs is probably more future-proof.

Use of unresolved identifier - app development with Swift Project 2

Sorry - I realise this is a complete beginner question, but I've googled for half a day now and still can't resolve the issue myself.
I'm using xCode 8.3 and trying to complete the apple - app development with swift course - end of unit project 2. I'm told (by the Apple book) I should be able to run the app without build failures, even if it isn't finished.
I get an unresolved identifier error when I add the following code to my ViewControler file, inside the class ViewController: UIViewController.
func updateUI() {
correctWordLabel.text = game.formattedWord
scoreLabel.text = "Wins: \(totalWins), Losses: \(totalLosses)"
treeImageView.image = UIImage(named: "Tree \(currentGame.incorrectMovesRemaining)")
}
xCode suggests I change it to Game.formattedWord, but when i do get 'Instance member 'formattedWord' cannot be used on type 'Game' ViewController.Swift'.
Could someone please help?
I've checked the sample code from Apple about 100 times and they are def saying it should be game.formattedWord in the code.
Thank you!
Try correctWordLabel.text = currentGame.formattedWord
I think it’s a typo.
Earlier in your code you create an instance of the Game struct called currentGame so you are accessing the formattedWord variable inside that instance. That’s why you couldn’t change it to Game. Game is like the blueprint of the struct. currentGame is your actual ‘thing’ Hope that makes some sense.

How to show/hide comments in XCode 8.2.1

While programming in XCode 8.2.1, I am simply trying to perform the following action:
... but when I try to do this (either by using the mouse/menu, or using the shortcut: "Control-Shift-Command-Left Arrow") , I get the unexpected result of the "Funk" alert sound... and no folding/unfolding takes place.
I have researched the question but all other posts are outdated.
Is this a known bug or am I just doing something wrong?
Thankyou!!!!

Swift App Extension: instance method count is unavailable

I just create my first app extension using XCode 7.1. One code file containing the code below is shared with both targets:
var str = "";
var l = str.count; //Compile error for extension target App: count is unavailable: There is no ...
The reason for this compile error seams to be that App extension compiles with swift 1.2 while the container target compiles with swift 2.0.
One solution would be importing the content App into the extension App doesn't appear to be a good solution from what i read about it. Sharing the code between targets can be difficult if both are not compiled using the same compiler.
I just run through all target settings and didn't find nothing that could be changed.
Can't find any post about this problem, witch is not so uncommon, so it is must likely i am interpreting something in a wrong way.
The only solution i can think of is using NSString instead of String but that is just an workaround for one class type. More problems of this kind will emerge in the future.
In Swift 2 it's
str.characters.count
Use str.characters.count to get String length in Swift 2

Resources