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)
Related
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.
I've created a XIB containing only a UITableView. I changed the parameters of the project to load this view at launch. But I get this "unrecognized selector sent to instance" error I don't know what it is. How do I fix this and get my app to show my view ?
I've searched the web and it seems that might come from Objective-C libraries ?
EDIT
I did some testing, it's look like it crashes when I link my TableView with my IBOutlet in the ViewController. Am I doing something wrong with the type TableView ?
The viewcontroller :
class Liste: UIViewController {
#IBOutlet weak var maListe: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
The error stack :
2019-06-12 14:06:11.083905+0200 GuildWar[5905:8796162]
-[GuildWar.Liste _finishDecodingLayoutGuideConnections:]: unrecognized selector sent to instance 0x104f0ef40 2019-06-12 14:06:17.511280+0200
GuildWar[5905:8796162] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[GuildWar.Liste
_finishDecodingLayoutGuideConnections:]: unrecognized selector sent to instance 0x104f0ef40'
* First throw call stack: (0x21230f518 0x2114ea9f8 0x21222c278 0x23e4c2ef8 0x212314d60 0x2123169fc 0x23e874110 0x21c955f28
0x21c8f5304 0x212cdba4c 0x21c955f28 0x21c95616c 0x21c8f5304
0x23e151dcc 0x23e152958 0x23e4971e4 0x23e4977c0 0x23e495e24
0x23dd5a104 0x23dd6269c 0x23dd59d88 0x23dd5a678 0x23dd589c4
0x23dd5868c 0x23dd5d1cc 0x23dd5dfb0 0x23dd5d084 0x23dd61d84
0x23e494518 0x23e090f0c 0x214c89d44 0x214c93754 0x214c92f5c
0x104cbcc74 0x104cc0840 0x214cc40bc 0x214cc3d58 0x214cc4310
0x2122a12bc 0x2122a123c 0x2122a0b24 0x21229ba60 0x21229b354
0x21449b79c 0x23e497b68 0x1045ea10c 0x211d618e0) libc++abi.dylib:
terminating with uncaught exception of type NSException
It looks like, you might have created IBOutlet or IBAction and deleted later in the code. Revisit the connections in the storyboard connection inspectors and check if there is any warning symbol like the attached screenshot, then you need to remove that connection.
Or if you can share your code I can look into.
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 }
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.
I am trying to set up a multi column table inside a Swift application using the library written in Obj C called TSUIKit which defines its own table TSTableView.
I have added the files to my project and to my bridging header and xcode recognizes correctly the classes...
Every time I execute the code, the tables shows the rows and columns correctly but when I touch any cell, an error appears which says the following:
2014-11-05 09:39:54.811 probarTabla[1584:20072] -[TSTableView numberOfColumns]: unrecognized selector sent to instance 0x7ffbc3654920
2014-11-05 09:39:54.937 probarTabla[1584:20072] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TSTableView numberOfColumns]: unrecognized selector sent to instance 0x7ffbc3654920'
*** First throw call stack:
Here is the code in the controller of the view, the test project only has a unique view with a TSTableView added which corresponds with "tabla" in the code of the ViewController
#import <Foundation/Foundation.h>
#import "TSTableView.h"
#import "TSTableViewDelegate.h"
#import "TSTableViewDataSource.h"
#import "TSTableViewHeaderSectionView.h"
#import "TSTableViewModel.h"
ViewController code:
import UIKit
class ViewController: UIViewController, TSTableViewDelegate {
#IBOutlet var tabla: TSTableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tabla.delegate = self
tabla.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
var pruebaColumna : NSArray = [
["title" : "Probando Columna 1"],
["title" : "Probando Columna 2"],
["title" : "Probando Columna 3"]
]
var model : TSTableViewModel = TSTableViewModel(tableView: tabla, andStyle: kTSTableViewStyleDark)
var pruebaFila : NSArray = [
["cells" : [
["value": "valor1"],
["value": "valor2"],
["value": "valor3"]
]
]
]
model.setColumns(pruebaColumna, andRows: pruebaFila)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: TSTableView!, didSelectRowAtPath rowPath: NSIndexPath!, selectedCell cellIndex: Int) {
println("Has hecho click en la celda")
}
}
Thanks in advance
It is important you keep a strong refererence to your model, as this is the datasource.
Once you keep a strong reference to it, your problem will be solved.