I have a class BorderedView class which is the subclass of UIView. After migrating to swift 4 I am getting few error in this class. Can't figure out whats wrong.Please see the image
Related
I am new to swift and am trying to build an app. I am receiving "Expected Declaration" error on Xcode when I type the following code.
.edgesIgnoringSafeArea(.bottom)
Please guide me on how to resolve it. Thanks
A declaration is one of the things listed in https://docs.swift.org/swift-book/ReferenceManual/Declarations.html
If the compiler is saying it's expecting a declaration, it means you have written something that isn't a declaration in some place in the code where only a declaration is allowed.
In your case .edgesIgnoringSafeArea is a method on SwiftUI View type, so it would only be valid to put that right after a SwiftUI view, not on its own. It might be because you have brackets in the wrong place.
I'm using the Xcode 10 beta 5. My project is running on Swift 4 with the 4.0.0 SnapKit.
I have a function which sets up UITableView's constraints:
private func setupConstraints() {
tableView.snp.makeConstraints { make in
make.leading.equalTo(view.safeAreaLayoutGuide.leadingAnchor)
make.trailing.equalTo(view.safeAreaLayoutGuide.trailingAnchor)
make.top.equalTo(view.safeAreaLayoutGuide.topAnchor)
make.bottom.equalTo(view.safeAreaLayoutGuide.bottomAnchor)
}
}
This function produces the following errors:
Argument type 'NSLayoutXAxisAnchor' does not conform to expected type 'ConstraintRelatableTarget'
I tried view.safeAreaLayoutGuide.leadingAnchor as! ConstraintRelatableTarget, but this casting fails.
Do you guys have any idea how to fix it?
Try e.g. view.safeAreaLayoutGuide.snp.leading. You’re missing the .snp part and the final part differs too.
Another Case
In my case, I get the same error when my "view" is optional property. I was adding the ".snp" part like in the accepted answer. But I get the same error.
Xcode Version 11.4 (11E146)
Solution
So I converted to the non-optional. Problem solved for my case.
I hope, it'll help someone else.
Best.
Migrating to Swift 3 from 2.3 and am running into this issue. The error is traceable to a view controller.
I do not see any extensions/protocols which would require a 'Key' constrained to 'String'.
I've tried to comment out code that might be causing the error, and have had strange results - ie removing an empty viewDidLoad() made the error appear in another class.
I'll update the thread if I make progress.
Key is a type inside a structure maybe a struct/class like Dictionary.
Use AnyHashable as Key to replace String if in Dictionary.
Knocking up an empty class within a Swift Playground gives an error __lldb_expr_
//: Playground - noun: a place where people can play
import UIKit
class FooBar {
}
let foo = FooBar()
See attached screenshot.
This occurs on Xcode Version 6.3.1 (6D1002). I have also tried with the latest Xcode 6.4 beta 3 - Version 6.4 (6E7) - available 11th May 2015. The same error occurs.
Empty classes build without issue in a normal Swift project.
The error can be avoided by simply adding a dummy constant as follows:
//: Playground - noun: a place where people can play
import UIKit
class FooBar {
let wibble = 10
}
let foo = FooBar()
Was surprised at this error given that creating a initial empty class is such a basic thing. In my case I wanted a scroll view delegate class to track content offsets. It would seem entirely reasonable to use a delegate with no properties.
Any ideas?
This is not an error.
It's an information that the variable foo now holds an object of class FooBar whose internal name is __lldb_expr_12.FooBar. __lldb_expr_12 is the Swift module's name in the Playground in this case.
I get the following warning when I run my app in iOS5
CoreData: warning: Relationship properties should be #dynamic, not ivars (entity foo, class foo, property bar). This will be an error in the future.
the property bar is being declared in the class as #dynamic. I would like to fix this before it becomes "an error in the future".
You should be using the Xcode to generate your MO subclasses. You will not see this error from the classes generated by the IDE.