Project presents instance which is not included in the app - ios

I'm currently working on an app where you can set pins on a map and retrieve Flickr images associated with the app.
For some reason there's following error thrown:
-[Photo copyWithZone:]: unrecognized selector sent to instance
The strange thing is that there is nothing called "copyWithZone" in my project and I have no idea how it came here. How can I find the part of the project where there is an error?
The Photo class I created only inherits from NSManagedObject and the error is thrown in the following function on the fourth line in the for-loop:
func isDownloading() -> Bool {
var result = false
for next in self.photos {
if let downloadWorker = PendingPhotoDownloads.sharedInstance().downloadInProgress[next.description.hashValue] as? PhotoDownloadWorker {
if downloadWorker.isDownloading() {
result = true
break
}
}
}
return result
}
Thank you in advance.

Related

Swift CocoaPods Library in Objective-C Project

I have found several online resources on how to include an Objective-C library into a Swift project and a few limited resources on how to do the reverse (which is what I'm after).
I have managed to get my project to compile and run based on the work I did here in this question: Swift CocoaPod Library in Objective-C Project Migration from Swift 3 to 4/5
However whenever I try to access anything from the Swift library in my ObjC project my app crashes with the following...
2020-01-29 14:42:09.756352-0700 Hyperion[13547:2723315] -[HGCircularSlider.RangeCircularSlider setStartPointValue:]: unrecognized selector sent to instance 0x1074088c0
2020-01-29 14:42:09.763045-0700 Hyperion[13547:2723315] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HGCircularSlider.RangeCircularSlider setStartPointValue:]: unrecognized selector sent to instance 0x1074088c0'
*** First throw call stack:
(0x18e32ea48 0x18e055fa4 0x18e2325a8 0x1923cf86c 0x18e332af4 0x18e334a7c 0x10208f554 0x10208d4d4 0x192d15dec 0x192be580c 0x10208d388 0x10208b570 0x191d8cab8 0x191d8d160 0x191d11b40 0x191d11c6c 0x191d192c0 0x191d23b84 0x191d23f70 0x191d1716c 0x191d119a0 0x191d87134 0x191d87838 0x1924f3d74 0x1924f7224 0x1924f70d0 0x1924f739c 0x191d87290 0x191d87838 0x1924f3d74 0x1924f7224 0x1924f70d0 0x1924f739c 0x191d87290 0x191d87838 0x191cceaec 0x191ccdf08 0x191cca9c8 0x191cca7e0 0x191ccde54 0x1923a2e50 0x191b3e148 0x1923a2e50 0x191dd9494 0x191dd97f8 0x191b40b58 0x1923a2e50 0x191dd9494 0x191dd97f8 0x191dd8814 0x1923dc3d4 0x1923dd714 0x1923b9e2c 0x192431fa4 0x192434500 0x19242d374 0x18e2aca00 0x18e2ac958 0x18e2ac0f0 0x18e2a723c 0x18e2a6adc 0x19822c328 0x1923a1ae0 0x1020de520 0x18e130360)
libc++abi.dylib: terminating with uncaught exception of type NSException
As I state in the answer of my question linked above I have written a Swift class that exposes the CocoaPod's library functions I need which allows my project to compile...
import Foundation
import HGCircularSlider
#objc public class CircularSliderObjc: RangeCircularSlider
{
#objc override open var startPointValue: CGFloat {
get {
return super.startPointValue;
}
set {
super.startPointValue = newValue;
}
}
#objc override open var endPointValue: CGFloat {
get {
return super.endPointValue;
}
set {
super.endPointValue = newValue;
}
}
#objc override open var endThumbImage: UIImage? {
get {
return super.endThumbImage;
}
set {
super.endThumbImage = newValue;
}
}
#objc override open var startThumbImage: UIImage? {
get {
return super.startThumbImage;
}
set {
super.startThumbImage = newValue;
}
}
}
As you can see in the project I have exposed startPointValue as both a set and a get. However invoking this function at runtime causes the crash.
Here is the calling class's header...
#import "BaseViewController.h"
#import "Hyperion-Swift.h"
#interface TemperatureDeviceViewController : BaseViewController
#property (weak, nonatomic) IBOutlet CircularSliderObjc *rangeSlider;
And the call in my .m file...
[self.rangeSlider setStartPointValue:[self getSliderValueForTemp:startValue]];
I'm assuming I'm missing one critical step here?
UPDATE #1
I've tried the answer suggested by Max which makes a lot of sense. However because this is an IBOutlet it in my ViewController his solution really doesn't work for my use case here.
I did some further debugging and put breakpoints all over my startPointValue function in order to see what the "super" was referencing. However none of the breakpoints are triggered before the crash happens. Therefore I'm not sure that the call to "super" is the actual cause? Verdict is still out on this one I think.
Try redesigning your wrapper class to encapsulate rather than inherit from the framework class. For example:
#objc public class CircularSliderObjc
{
let slider: RangeCircularSlider // NOT #objc!
#objc var startPointValue: CGFloat {
get {
return slider.startPointValue;
}
set {
slider.startPointValue = newValue;
}
}
That way Objective-C doesn't even need to know that the Swift class exists at all. My guess is that this is crashing on the super, where something Swift-specific is being accessed from Objective-C.

How to save a string to Core Data Swift

I'm creating a signup form with multiple view controllers as "pages" and I need the information from one view controller such as 'First name' and 'last name' or 'email address' to another view controller. I decided I'm going to use core data to save the strings and retrieve them from another view controller rather than create a global struct for every view controller (because it crashes every time I try and implement it). Heres my code:
#IBAction func nextBtnWasPressed(_ sender: Any) {
if firstNameText.text != "" && lastNameText.text != "" {
//Core Data User Information
var userInfo = UserInfo() // The Name of the Core Data Entity
var firstName: String = firstNameText.text!
userInfo.firstName = firstName
do {
try NSManagedObjectContext.save(firstName)//Need Fixing
} catch {
fatalError("Failure to save context: \(error)")
}
performSegue(withIdentifier: "toBirthdate", sender: self)
} else {
nextBtn.alpha = 0.5
}
}
Here is the error log : 'Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UserInfo setFirstName:]: unrecognized selector sent to instance 0x600001530e80'
Full error log: View Here
Well, at first I was going to give the obvious answer which is that, in your Core Data data model, your UserInfo entity does not have a firstName attribute.
That's still possible, but then I looked at the full transcript you posted and saw that, a couple hundred microseconds before this error is another error:
Failed to call designated initializer on NSManagedObject class 'UserInfo'
I suspect this error indicates that you have initialized your managed object with init(). This is a common mistake of first-time Core Data users. Ensure that you are initializing your UserInfo object like this:
let userInfo = UserInfo.init(entity: entityDescription, insertInto: context);
or if your deployment target is iOS 10 or later, you can use the newer cleaner method:
let userInfo = UserInfo.init(context: context)

iOS share extension exception - items configuration

I'm having troubles implementing the share extension in an application. I'm using swift 3, xcode8.
override func configurationItems() -> [Any]! {
// To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
let item = SLComposeSheetConfigurationItem();
item?.title = "Test";
item?.value = "Value";
item?.tapHandler = self.show;
return [item]
}
func show() {
print("TEST");
}
When I add that code to configure the items, I get the exception :
2016-09-19 09:22:20.623471 ARShareExtension[10583:675495] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue setChangeObserver:]: unrecognized selector sent to instance 0x17025af40'
I don't know what is wrong, I'm doing it as described in the apple developer site. I would appreciate if someone could help me :) thanks
A bit late, but if anyone still has problems with this, SLComposeSheetConfigurationItem() is now returning an Optional for some reason, but the return value is supposed to be an array of non-optional items, so you can do either
let item = SLComposeSheetConfigurationItem()!
or
guard let item = SLComposeSheetConfigurationItem() else { return nil }

EXC_BAD_ACCESS to Typhoon Singleton Reference

I'm using the Typhoon Framework to integrate all of my core components. I'm working on my data layer (using FMDB instead of Core Data). I have a LocalDataStore class that handles the reading and writing of data to SQLite. This is a singleton class that has an initialization method that sets up the database. Then I have a PlayerDAO that references it.
When I launch the app, the LocalDataStore gets created and the initialization method gets called. It then goes to create the DAO class, and when it tries to access the LocalDataStore, I'm receiving an EXC_BAD_ACCESS error.
Turning on "Enable Zombie Objects" in the launch scheme, I get an additional error:
-[myapp.SQLiteLocalStore retain]: message sent to deallocated instance 0x1740ab5e0
Here's how I set things up in my Typhoon Assembly:
dynamic func config() -> TyphoonDefinition {
return TyphoonDefinition.configDefinitionWithName("MyApp.plist")
}
dynamic func localStore() -> AnyObject {
return TyphoonDefinition.withClass(SQLiteLocalStore.self, configuration: {
(definition) in
definition.injectProperty("databaseName", with: TyphoonConfig("sqlite.filename"))
definition.performAfterInjections("initDatabase")
definition.scope = .Singleton
})
}
dynamic func playerDAO() -> AnyObject {
return TyphoonDefinition.withClass(SQLitePlayerDAO.self, configuration: {
(definition) in
definition.injectProperty("localStore", with: self.localStore())
})
}
Looking at the breakpoint when the error occurs, it's happening on this line in TyphoonComponentFactory:
- (id)newOrScopeCachedInstanceForDefinition:(TyphoonDefinition *)definition args:(TyphoonRuntimeArguments *)args {
...
instance = [pool objectForKey:poolKey]; // line 431
...
}
poolKey = #"localStore"
The debugger says it's currently initializing playerDAO. The pool has only 1 key of "localStore" and the value is _NSZombie_myApp.SQLiteLocalStore
Any idea on what could be going wrong?
Well, changing definition.scope = .Singleton to definition.scope = .LazySingleton fixed it... and in my case, is probably a better approach anyway.
I'm still curious if I was doing something wrong to cause the memory error with the plain Singleton.

Crashing on presenting IDMPhotoBrowser in Swift

I am integrating IDMPhotoBrowser in my Swift Project.
I have created a bridging header and I have imported IDMPhotoBrowser.
#import <IDMPhotoBrowser.h>
In my view controller:
class ViewController: UIViewController, IDMPhotoBrowserDelegate {
override func viewDidLoad() {
super.viewDidLoad()
var photoBro = IDMPhotoBrowser(photos: imagesArray)
photoBro.delegate = self
presentViewController(photoBro, animated: false, completion: nil)
}
But when it is executed, I get the following error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString unloadUnderlyingImage]: unrecognized selector sent to instance 0x165d6870'
In IDMPhotoBrowser Library, I found this function in IDMPhoto.m
// Release if we can get it again from path or url
- (void)unloadUnderlyingImage {
_loadingInProgress = NO;
if (self.underlyingImage && (_photoPath || _photoURL)) {
self.underlyingImage = nil;
}
}
From the error it looks like it is expecting to do something to an array of IDMPhotos but instead has an array of strings...are you passing the right kind of array to the constructor?
As #GoatInTHeMachine pointed, I was not passing the right kind of array.
But as I wanted to pass the imageURLs, I had to change the constructor.
The following worked for me:
var photoBro = IDMPhotoBrowser(photoURLs: imagesArray)

Resources