After updating to XCode 7.3 and Swift 2.2, everything with my iOS project seemed fine and I have no compile errors or warnings. It worked perfectly when compiling to Swift 2.1
However, after the update, as soon as the app launches, it freezes and XCode returns an EXC_BAD_ACCESS error, with no messages on the console. The problem is with my 'sharedInstance' singleton, for some reason it won't work.
The code goes as follows:
class Authenticator {
private init() {}
static let sharedInstance = Authenticator()
private let parseDAO = ParseDataAccessObject.sharedInstance
var place: Place?
var placeObj: PFObject?
var menu: Menu?
var consumables: [Consumable]?
var tables: [Table]?
....
}
When the app launches, it returns the following error:
Debug
Error
Are one of the types of those properties an enum with a single case? There is a bug with the newest version of Swift that causes a EXC_BAD_ACCESS error when an object is initialized with a single-case enum property that is not optional. Here is the relevant Swift bug tracker issue: https://bugs.swift.org/browse/SR-1035
For a temporary fix, add another case to the enum.
Related
I am having hard times trying to figure out pretty simple thing.
I have framework that only works on IOS 13+,
So when I try to initialize it with empty class like
private var itso: ITSOFramework I get error that ITSOFramework is only available on IOS 13+
I can add class guard, but then everything fails on run and I can run it on devices below ios13.
But all I want to do, is to have in my init method, condition to initialize it if 13+ and don't do anything below, so at least I have a app without some functionality, but at least it works.
so I am looking for something like
is #available(iOS 13.0, *) {
itso = RTDFramework.ITSOFramework()
} else{
.. do something else
}
I'm working with a Cocoa Touch framework, built for distribution, which uses Core Data managed object subclasses. When I implement the framework in a client project built with the same Xcode/Swift version as the framework, the app compiles successfully.
However, when I build the framework with Xcode 11.1 (Swift 5.1), and implement the framework in a client project using Xcode 11.2.1 (Swift 5.1.2), I get a compile error in the property declaration of the generated "swiftinterface" file. "#NSManaged not allowed on computed properties"
From Framework project NSManagedObject subclass:
extension TestEntity {
#nonobjc public class func fetchRequest() -> NSFetchRequest<TestEntity> {
return NSFetchRequest<TestEntity>(entityName: "TestEntity")
}
#NSManaged public var id: Int64
}
From Framework .swiftinterface file:
#objc #NSManaged dynamic public var id: Swift.Int64 {
#objc get
#objc set(value)
}
If I remove the setter-getter, the client app builds and runs, but I see this warning:
Cannot load Swift type information; AST validation error in "my_test_framework": The module file format is too old to be used by this version of the debugger.
Thoughts, rants, lessons, and/or workarounds are welcome!
I am working in a iOS project involving Realm and the use of Generics. I am exploring ways to clone a retrieved Realm object to update it outside a write transaction and then send it to an update function using generics.
I am facing a weird problem and i don't know if it is related to Realm or to the Generics stuff. You help will be appreciated
Setting:
One class GenericObject that inherits from Realm Object, and a subclass called Sale:
GenericObject: Object
Sale: Generic Object // This class includes a primary key called "id"
I fetch a Sale object from the web and I am able to save it in Realm, creating a new object outside the write transaction (I could save it without worrying about the write transaction, but I want to use the same code and flow for any update)
When I modify a property of the object and try to update Realm, it throws an exception because the primary key can't be found. (The primaryKey is defined in the subclass Sale)
I have been able to pinpoint the problem to my newItem() method in Sale as follows:
override func newItem<T:GenericObject>(ofType itemType: T.Type) -> T {
let dictionary = self.getDictionary()
let newItem = T.init()
newItem.updateWithDictionary(dict: dictionary)
print("Type: \(type(of: newItem)) - Object: \(newItem)")
return newItem
}
And then, I call it as follows:
let newObject = object.newItem(ofType: Sale.self)
self.realm.add(newObject, update: true)
So far, so good. I retrieve the object from the web and it works. The print() reports that type(of:) the instantiate object is Sale, and the printout of the object also says Sale
Type: Sale - Object: Sale { ....
When I update the object and save it, it fails saying that Realm could not find the primary key, type(of:) reports Sale, but the instance is printed as the GenericObject superclass, as follows:
Type: Sale - Object: GenericObject { ....
This result is running the same code and the same code execution. I am using Xcode 10 and Swift 4.2, with Realm 3
Any idea what may be happening here?
After 6 months, the problem seems to be fixed without a clear indication of what was going on.
As of 2019-04-22, having migrated to Realm 3.14.1, Xcode 10.2.1 and Swift 5.0, I am able to get a clone of the object using T.init(), and saving it successfully outside the Realm write transaction with the original code used when I posted the question
I don't see anything related to a syntax change from Swift 4.2 to 5.0, but I understand that Xcode 10.2.1 includes updates to LLVM/clang.
I'd love to spend some time checking the new compiler with the previous Realm version
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)
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.