I have been working on developing a framework and I have decided to create custom enums that extend the Error protocol to report to the host application when a domain specific error is encountered.
i.e.
public enum MyCustomError: Error {
case customCase(message: String)
}
from the host application I have a response call back that is another enum with associated value
i.e.
public enum MyCustomResponse {
case success
case error(Error)
}
form within the host application I try to access the error by doing the following
i.e.
let responseHandler: (MyCustomResponse) -> Void = { response in
switch response {
case .error(let error):
if case let MyCustomModule.MyCustomError.customCase(theErrorMessage) = error {
print(theErrorMessage)
}
}
}
what I am getting is a message from the compiler telling me that MyCustomModule has no member named MyCustomError. If a loose the MyCustomModule. then the compiler complains Use of unresolved identifier 'MyCustomError'. I am importing MyCustomModule, and the access level of the MyCustomError is public, any ideas on how to solve this would be really appreciated.
Thanks
Note: I am developing my framework via cocoapods version 1.1.1 and using Xcode 8.2.1, swift version 3.0.2, supporting iOS version 8.0 and above.
Generated interface
import Foundation
public enum MyCustomError : Error {
case customCase(message: String)
}
After a long while trying out every little thing I could think of, even sandboxing the problem in a new repo (check github.com/anuragajwani/framework_pod_enums_test) without the ability to reproduce it I ended re-cloning the repository with the issue in question and reapplied all the changes and it worked no problem. Pitty I could not find the underlying problem, but by comparing each configuration setting in comparison with the sandboxed project and everything matching exactly I gave up. I have hunch that it had to with the compiler which given how flaky it is it would be no surprise.
I had the exact same issue. In my case I just set the "Build Active Architecture Only" to "No" in the Build Settings and the issue was gone.
Related
When I'm migrating the .net core application from 2.0 to 3.1, the following method services.AddCookieTempData() is not working since it's referring assembly"AspNetCore.Mvc.CookieTempData". If we comment this code it's showing the below error message. Please let us know what is the alternate for this method.
public void ConfigureServices(IServiceCollection services)
{
services.AddCookieTempData();
Error Message:
The 'Microsoft.AspNetCore.Mvc.ViewFeatures.Infrastructure.DefaultTempDataSerializer' cannot serialize an object of type
Your question seems similar to what is reported at https://github.com/aspnet/Mvc/issues/6711. On that page, Elion writes, "TempData serializer currently supports only a limited set of data types for simplicity. It supports a few primitive types such as int, string, and bool, and simple containers of those types, such as lists."
That same page points to a work-around at Store complex object in TempData. hem's highly-upvoted answer there (https://stackoverflow.com/a/35042391/2615878) recommends using an extension method and provides sample code for such.
We found a bug in old code which could be easily found if there would be a warning,
The issue was that inner class member was used but not assigned or initialized. Sample code minimized. Problem is that url is always null.
public class Main {
public class Sender {
private String url;
public Sender() {
}
public void send() {
OtherClass.send(url);
}
}
}
In intellij it warns about variable never assigned. In eclipse I didn't find such warning.
The code is more complex and adding a warning at any level will reduce time to find similar bugs.
Is it possible in eclipse to warn in some way if variable is used before assigned/initialized ?
You can use SpotBugs(successor of findbugs) eclipse plugin. Right click on project Spotbugs->find bugs this will find these types of bugs.
I suggest also installing sonarlint plugin which has good static analysis capabilities.
https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin
https://marketplace.eclipse.org/content/sonarlint
I upgraded a project I am working on to Swift 4.0. After doing so I realized this was not the best idea. I've fixed all bugs but one and can't figure it out. I have installed RealmSwift in my project and am getting the following error in one of the Realm files.
ERROR: Cannot call value of non-function type 'ThreadConfined.Type'
public init(to threadConfined: Confined) {
let bridged = (threadConfined as! AssistedObjectiveCBridgeable).bridged
swiftMetadata = bridged.metadata
type = type(of: threadConfined). ****ERROR CALLED ON THIS LINE****
objectiveCReference = RLMThreadSafeReference(threadConfined: bridged.objectiveCValue as! RLMThreadConfined)
}
Lesson learned about upgrading too soon. I was hoping someone could give me a hand so I can start developing again. Any thoughts?
Realm's master branch now contains support for Swift 4 and beta 1 of Xcode 9 (#5006). Using a build of Realm Swift from source should get you up and running.
I noticed that even though I was building from source (using CocoaPods), this issue was happening for me as well.
To solve it, two lines need to be removed (as seen in the file in #jonthornham's comment):
private let type: ThreadConfined.Type
and:
type = type(of:threadConfined)
Scenario: Networking app based on Alamofire.
I'm encountering deprecated-code notices in my latest project build. I traced it to the following statement within Alamofire. I don't see any mention of the alternatives.
#available(*, deprecated=3.4.0)
public static func errorWithCode(code: Int, failureReason: String) -> NSError {
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
return NSError(domain: Domain, code: code, userInfo: userInfo)
}
What's the replacement?
And... how do I determine other replacements of deprecated codes?
You now need to build your own errors with your own custom domain. It was unwise of us to originally expose those convenience methods because it led users to create their own errors using the Alamofire error domain which is not correct.
All of this is going to be easier in Swift 3 with the new AFError type being introduced.
In a nutshell, if I define a constructor in a class thats named after the same name as the file itself, it returns the following area.
Some example code. Take the filename as ParseWebsiteData.scala for both.
This returns an error.
class ParseWebsiteData(url:String) {
}
This however, works fine.
class Foo(url:String) {
}
The only thing that I'm seeing as the issue are parser bugs from 2013, but this is the latest version of Eclipses's Scala IDE setup so I'm strongly thinking this is not the case, but turns out I'm wrong. Oops :(
As it's still an issue, what are the way(s) to avoid this occurring as I code in the future?
Well, can't tell the root cause but I was getting the same error in Scala Eclipse editor and I just did "project->clean" and it was gone!