I am upgrading my Swift project from 2.3 to 3.0 in XCode 8. I use Google Maps API and they have some boilerplate code as follows:
self.mapView.camera=camera
let marker = GMSMarker(position: camera.target)
marker?.snippet = "Hello World"
marker.map = self.mapView
However, my XCode 8 Swift compiler gives me an error on the last line:
Cannot assign to property; map is a method
I have no control over the properties in Google's GMSMarker class. So how can I set the 'map' property?
Related
I've been trying to compile an already existing iOS project containing a target for an Apple Watch extension.
The project uses RxSwift/RxCocoa which, reading at the official documentation, is compatible with watchOS.
The project compiles and runs successfully on Apple Watch simulator, but it fails on a real Apple Watch, with the following error:
Cannot find 'CGRectType' in scope
Cannot find 'CGPointType' in scope
Cannot find 'CGSizeType' in scope
The reason of this is that these three constants, declared in a class extension inside RxCocoa, are declared like this:
#if arch(x86_64) || arch(arm64)
let CGRectType = "{CGRect={CGPoint=dd}{CGSize=dd}}"
let CGSizeType = "{CGSize=dd}"
let CGPointType = "{CGPoint=dd}"
#elseif arch(i386) || arch(arm)
let CGRectType = "{CGRect={CGPoint=ff}{CGSize=ff}}"
let CGSizeType = "{CGSize=ff}"
let CGPointType = "{CGPoint=ff}"
#endif
Do you know if there's any way to make it work, as this library is supposed to be compatible with watchOS?
I guess that you are still using am old version of the library (not compatible with recent version of the watchOS)
The right definition on the library should be something like
#if arch(x86_64) || arch(arm64)
let CGRectType = "{CGRect={CGPoint=dd}{CGSize=dd}}"
let CGSizeType = "{CGSize=dd}"
let CGPointType = "{CGPoint=dd}"
#elseif arch(i386) || arch(arm) || arch(arm64_32)
let CGRectType = "{CGRect={CGPoint=ff}{CGSize=ff}}"
let CGSizeType = "{CGSize=ff}"
let CGPointType = "{CGPoint=ff}"
#endif
According to this two discussion thread in the library site
Fix build for new arm64_32 architecture
Xcode 10 GM: Use of unresolved identifier 'CGRectType'
It should be fixed in the latest version of the library
The below code works well with "Swift 3" but giving error of "unresolved identifier CALayerContentsGravity" in "Swift 4"
static func create(image: UIImage, size: Double) -> CALayer {
let containerLayer = createContainerLayer(size)
let imageLayer = createContainerLayer(size)
containerLayer.addSublayer(imageLayer)
imageLayer.contents = image.cgImage
imageLayer.contentsGravity = CALayerContentsGravity.resizeAspect
return containerLayer
}
In swift4 CALayerContentsGravity is not working.
To set contentsGravity of layer you should use constant string which is available in swift4.
imageLayer.contentsGravity = kCAGravityResizeAspect
Hope it will work.
i had this problem after I imported the Cosmos pod. I spoke to the author and he said I need to check the pod's target and the Swift language it used.
When I check the Cosmos target the Swift version was 4 but my main project used Swift 4.2. Once I changed the Cosmos pod's version from 4 to 4.2 the error went away.
suggestion from Cosmos author
This is how you check the Cosmos pod Swift version
It needs to match what's in your main project's target:
I'm currently learning Swift, and I followed this tutorial to create an NSWindow that inherits the vibrantDark property from the AppKit in Swift. The code I added to the WindowController.swift file is as follows:
window?.titleVisibility = .hidden
window?.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark)
What I'd like to do is achieve the same result for an NSPopover in my program; however, when I add the following to my LogViewController.swift file, I get an error -- the first of which is "Value of type 'NSView' has no member 'titleVisibility,'" and the second of which is "Cannot use optional chaining on non-optional value of type 'NSView.'"
view?.titleVisibility = .hidden
view?.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark)
Several posts have addressed this issue for NSWindow, but I cannot find an answer that addresses NSPopover. I currently have the following condition set to open NSPopover upon clicking NSImage in the status bar:
popover.contentViewController = LogViewController.freshController()
I'm thinking that having NSPopover as NSView is what's causing the issue, but -- being as I'm still new to Swift -- I'm not sure how to diagnose this the problem. That said, I would much appreciate it if anyone could point me towards the right direction.
You should be using an NSPopover, not an NSView:
var myPopover: NSPopover?
myPopover = NSPopover.init()
myPopover?.appearance = NSAppearance(named: .vibrantDark)
If you want to use a contentViewController:
var popoverViewController: NSViewController?
myPopover?.contentViewController = self.popoverViewController
Curious, what would this be in Swift 4?
stimageout = AVCapturePhotoOutput()
stimageout?.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]
Currently, it errors with Value of type 'AVCapturePhotoOutput' has no member 'outputSettings' which is odd since I don't have memory of Apple changing this.
This is not "begging for help"-type question. I'm just curious if Apple changed this and the steps I need to do in order to fix this issue.
Thanks in advance. :)
The problem is outputSettings is a property on AVCaptureStillImageOutput, not AVCapturePhotoOutput.
AVCaptureStillImageOutput is deprecated in iOS 10, so for iOS 10+, use AVCapturePhotoOutput instead. To set settings using the new API, you can use an AVCapturePhotoSettings object.
let stimageout = AVCapturePhotoOutput()
let settings = AVCapturePhotoSettings()
settings.livePhotoVideoCodecType = .jpeg
stimageout.capturePhoto(with: settings, delegate: self)
Apple's AVCapturePhotoOutput Documentation: https://developer.apple.com/documentation/avfoundation/avcapturephotooutput
AS I have updated the XCode to 8, new version, the following code
func center(_ usePresentationLayer: Bool) -> CGPoint
{
if usePresentationLayer, let presentationLayer = layer.presentation() as! CALayer
{
return presentationLayer.position
}
return center
}
result in
Error - Value of type 'CALayer' has no member 'presentation'
How can I fix this issue in XCode using swift 3.0?
Edit: the question changed
Make sure request is of type URLRequest.
Don't upload screenshots of code - please edit your post so it contains code that's searchable.