Posts

Showing posts with the label swift

What's the difference between importing a target into unit testing and including that file among the target Membership?

Image
When I'm writing tests I can do: How is the above different from adding the Test File to a specific Target? Ultimately my question is: Had I made my unitTests a target to all my files...would it be equivalent to doing: If not, then what is the difference? From the Swift docs under the heading Access Levels for Unit Test Targets (emphasis added) When you write an app with a unit test target, the code in your app needs to be made available to that module in order to be tested. By default, only entities marked as open or public are accessible to other modules. However, a unit test target can access any internal entity, if you mark the import declaration for a product module with the @testable attribute and compile that product module with testing enabled. These docs say that the @testable attribute provides your Unit Test target access to all internals of the module marked as @testable. Thus letting you avoid having to manually add individual files in that module to the Unit Test tar...

Distance between face and camera using ARKit

Is there any where are you to get distance between camera and face using ARKit ? I think this is possible by using the ARFaceAnchor.leftEyeTransform and ARFaceAnchor.rightEyeTransform properties. Once you have these you can get the approximate distance of the eyes to the Camera using the worldPosition of the Eyes and subtracting the position of the Camera e.g. SCNVector3Zero . Below is a very crude example with all the code commented so it should be easy enough to understand: Hope it helps... By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Using AVAsynchronousKeyValueLoading in Swift

I'm curious if there is a Swifty, safe way to use AVAsynchronousKeyValueLoading without having to hard code the keys I'm using. Specifically, I'd like to call loadValuesAsynchronously(forKeys:completionHandler:) with the key "availableMdiaCharacteristicsWithMediaSelectionOptions" , but it currently isn't possible to get a String from any kind of KeyPath -based solution. I would love it if there was some kind of way to retrieve the name of a property in such a way that it would be checked at compile time whether the property exists. Is there such an API? The solution was #keyPath . I for some reason thought that KeyPath had replaced #keyPath in Swift, but #keyPath(AVAsset. availableMediaCharacteristicsWithMediaSelectionOptions) gives the string "availableMediaCharacteristicsWithMediaSelectionOptions" which is exactly what I want. By clicking "Post Your Answer", you acknowledge that you have ...

Why is our URLSession object a variable and not a constant

I'm following a tutorial on consuming REST API's to get JSON back from a third party server. We are building out a networkProcessor class in which we will be able to use it by creating instances of this class in ViewControllers in order to make url sessions for network calls. I noticed that the author declared the session placeholder as a variable and not a constant which went against what I've learned while using Xcode which is to always consider using constants first. Is there a specific reason why the author may have chosen to make this a variable and not a constant? Here is what I have so far: By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.