there's a lot of code in here but please be patient I will try to explain my question
so i am trying to convert Apple's AvDepthCapture project which is in UIKit as a SwiftUI project, so i copied all the supporting files, i will attach the image for the same below, the shaders folder contain the metal files for applying filters
so I created a class same as the cameraviewcontroller and added all the properties as follows -
class CameraViewController: UIViewController, AVCapturePhotoCaptureDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureDepthDataOutputDelegate, AVCaptureDataOutputSynchronizerDelegate, ObservableObject {
private var previewView: PreviewMetalView!
}
now when i run my app on my device it asks for camera permission but then shows a white screen instead of opening the camera and the PreviewMetalView file that i copied earlier directly from the original UIKit project,
the declaration is causing error
private var previewView: PreviewMetalView!
this line, it quits my app and says unexpectedly found nil when unwrapping an optional value but the code is the same as that of the UIKit project and UIKit project works perfectly fine on my device then why is it throwing this error!?, please help i can provide both the UIKit project and my SwiftUI project file if you want to see i really can't figure it out
there's a lot of code but this specific line is throwing error, I declared a type of PreviewMetalView but now PreviewMetalView has an initialiser which takes in a type NSCoder so what should I write there ??
like I would be declaring my variable as
var previewView = PreviewMetalView(coder: NSCoder)
what to put in place of NSCoder ?
when I opened the original UIKit project the previewView is defined as an IBOutlet to a Container View which is then linked to the CameraViewController but I cannot find where is it initialised please help!
Related
When I go to view my SwiftUI through the canvas preview in Xcode 11.3.1 I am getting the error
Compiling failed: 'Color' is only available in iOS 13.0 or newer
But the project itself builds successfully and the simulator loads without any issues. I have tried clearing the build folder, quitting Xcode and rebuilding but still no luck.
Any help would be great. Thanks in advance.
SwiftUI minimum deployment target is 13.0, so if you have project with support of older version, then all SwiftUI code (including preview providers) you have to prepend with availability modifier, like
#available(iOS 13.0, *) // << here !!
struct Demo: View {
var body: some View {
VStack {
Text("Hello")
}
}
}
You Should use Assets or Other option like Color Literal for Color.
Don't use the system Color option since your deployment target is 11.4.
Man, I've had a similar issue. The problem was that sometimes my preview worked sometimes it didn't... I reviewed the diagnostics and realized that there are some #_dynamicReplacement attributes mentioned (which are used, I guess, for hot reloading). It wasn't working when I've had a file with #available attributes opened in the (adjacent) editor. When I closed that editor everything worked back again.
Magic ✨
Also one more hint from my friend - when you have a file from another target (not the one hosting your Canvas-related code) in (adjacent) editor it behaves the same way.
I'm implementing Google Maps in my project, because MKLocalSearch doesn't have a complete list of restaurants/bars. I'm following Google's documentation. I believe I've uncovered an issue and seek advice on how to solve.
The fist step is variable declaration at the class level:
var locationManager = CLLocationManager()
var currentLocation: CLLocation?
var mapView: GMSMapView!
var placesClient: GMSPlacesClient!
var zoomLevel: Float = 15.0
After following the remaining instructions, my program keeps failing on the mapView line:
let camera = GMSCameraPosition.camera(withLatitude: defaultLocation.coordinate.latitude,
longitude: defaultLocation.coordinate.longitude,
zoom: zoomLevel)
mapView = GMSMapView.map(withFrame: view.bounds, camera: camera) //Fails here!
The error message in the debugger is: Fatal error: Unexpectedly found Nil while unwrapping optional value.
So the question is why does the Google documentation declare the mapView variable the way it does? Don't all variables that ARE NOT optional have to initialize with a value? Should I declare the variable as Optional? Seems odd to me that Google Documentation would be incorrect.
Thanks.
By declaring an optional with ! you are telling the compiler whenever I access this optional it will have a value. It means you don't have to stick ! at the end everytime you use it. But it does mean if you haven't set the optional to have a value you will get an error when you access it.
An example of using one would a class member of a UIViewController that you setup in viewDidLoad(). You aren't required to setup a separate init() function for the view controller to initialise the variable but you can pretty much guarantee the entry point for your code is viewDidLoad() and any subsequent code run will have a valid version of this class member.
Search for Implicitly Unwrapped Optionals for more details
you should take optional mapView when there is possibility of having mapView or not. You should always take like this
let mapView = GMSMapView(frame: self.view.bounds)
I do have a strange issue in using the reorder feature in my app's UICollectionView. We have a custom layout which is implemented to show a decoration view. The collection view uses a flow based layout. When I move the first cell from its position to last cell position for reordering of the cells, the app crashes before it calls the collection view delegate's collectionView(moveItemAt: to) method.
Attached the stack trace of this issue. You can see that crash is happening in the bridging between NSIndexPath and IndexPath. I am not sure why it is happening inside UIKit. Searching for this issue found that it appears to be bug inside UIKIt which got introduced in Swift 3.0. I tested my old build which was built before swift 3.0 migration and it works without any crashes.
Can someone tell me how can I fix this issue?
Related bugs links
UICollectionView broken after Swift 3 migration?
https://bugs.swift.org/browse/SR-2103
https://bugs.swift.org/browse/SR-2417
func handleLongGesture(_ gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
case UIGestureRecognizerState.began:
if let movingPageIndexPath = collectionView.indexPathForItem(at: gesture.location(in: collectionView)) {
collectionView.beginInteractiveMovementForItem(at: movingPageIndexPath)
}
case UIGestureRecognizerState.changed:
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: collectionView))
case UIGestureRecognizerState.ended:
collectionView.endInteractiveMovement()
default:
collectionView.cancelInteractiveMovement()
}
}
I have for months tried to find what causes the following in Xcode. I have deleted the temporary files, searched through the MainStoryboard file - no success.. I dont know how to fix it.. Source code of project is on GitHub (https://github.com/rsyncOSX/Version3.x).
One problem solved - the second issue is still there. Have searched through Main.storyboard file, cannot spot the problem. The ViewController IDed by 3xI-3C-guU is valid. I am also finding reference to fs3-Ij-mBm searching in Main.storyboard.
2016-12-19 09:06:43.068961 RsyncOSX[10461:604908] Unknown class
_TtC8RsyncOSX21TabViewControllerMain in Interface Builder file at path /Volumes/Home/thomas/Library/Developer/Xcode/DerivedData/RsyncOSX-budzkonsqjvzovfxbfnmopllerwh/Build/Products/Debug/RsyncOSX.app/Contents/Resources/Base.lproj/Main.storyboardc/NSWindowController-abu-zT-Ht4.nib.
2016-12-19 09:06:43.270247 RsyncOSX[10461:604908] Unknown class View
in Interface Builder file at path
/Volumes/Home/thomas/Library/Developer/Xcode/DerivedData/RsyncOSX-budzkonsqjvzovfxbfnmopllerwh/Build/Products/Debug/RsyncOSX.app/Contents/Resources/Base.lproj/Main.storyboardc/3xI-3C-guU-view-fs3-Ij-mBm.nib.
This problem can occur when you change a classname of a UIViewController even though a storyboard does still have the old classname. You can fix this by finding out which storyboard it is that is causing this problem (try the search function in Xcode, it will tell you that you can find classname in file example.storyboard) and update the name accordingly.
Environment:
Xcode Version 8.1 beta (8T47)
Apple Swift version 3.0.1 (swiftlang-800.0.56 clang-800.0.42)
The Swift 3.0.1 compiler flagged 'UIScreen' as '...no member'.
...but the UIScreen file does have 'main':
#available(iOS 2.0, *)
open class UIScreen : NSObject, UITraitEnvironment {
#available(iOS 3.2, *)
open class var screens: [UIScreen] { get } // all screens currently attached to the device
open class var main: UIScreen { get } // the device's internal screen
I found numerous instances of a particular class not having a certain member.
And this was after converting the code to Swift 3.0.1 thru Xcode helper conversion function.
What gives?
Note: I was able to access UIScreen.main.scale via playground.
It appears that I'm working with a corrupt swift file.
Swift3.0.1 Since UIScreen is UIKit framework's class.So make sure you have imported.
import UIKit