I'm using "UIImage+ResizeMagick" (iOS api by some developer for resizing image written in obj-c) in my swift project, but facing issues and getting the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage resizedImageByMagick:]: unrecognized selector sent to instance 0x7fe74c2065c0'
I know this error occurs when that function doesn't exists in that particular class or if we pass wrong parameters while calling the function but i don't think it's the case with my code (if i'm not wrong)
This class is written as: "UIImage(ResizeMagick)" and as per my knowledge it's a category so i can use the methods with every UIImage object. I've imported it in my class as #import "UIImage+ResizeMagick.h" and using it as:
UIImage *image = [UIImage imageNamed:#"validate-icon-tick.png"];
image = [image resizedImageByMagick:#"200x200"];
I'm using multiple libraries in my project that are written in obj-c but i'm using bridging header for this purpose. May be the problem with ResizeMagick is because of extensions vs categories difference in obj-c and swift.
Kindly tell me what i'm doing wrong or if is it possible or not. Thanks.
Fixed the issue for using extension (cocopods) in swift.
I've added #import <UIImage-ResizeMagick/UIImage+ResizeMagick.h> in my bridging header file. In controller i've used the methods of this extension as:
let image = oldImage.resizedImageByMagick("200x200")
Extensions vs Categories (in swift and objective-c) are well explained over here:stack overflow post link
Related
I'm working on iOS project with DB, I am using SharkORM and integrate it to my project using cocoa pods, my project is built using Swift 3.
Everything is working perfectly, but now I need to add encrypted values to the DB and in order to test it I added a very simple code,
I created a "User" class in which I defined a "test" property, this property is of type Double:
dynamic var test: Double = 0;
I also added the following code to the class to define "test" as encrypted property:
override class func encryptedPropertiesForClass() -> [Any]! {
return ["test"]
}
in order to read/write this property I did the following:
print(User.currentUser.test)
User.currentUser.test = 10
User.currentUser.commit()
print(User.currentUser.test)
Please note that current user is a singleton instance and it is being read from the DB. However, I'm getting the following exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SRKEncryptedObject doubleValue]: unrecognized selector sent to instance
Any idea why this is happening? thanks in advance.
I have CoreData app that is perfectly working on iOS10, written in Swift3, supporting iOS 8.4 and above.
When I try to run it on iOS 9.3.5 I'm getting error:
2016-10-07 17:47:20.596 FormApp[710:179733] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'
crashing on line:
form.addToOpenQuestions(openQuestion)
I have added #objc() to managed object classes. Then I'm getting new error:
CoreData: warning: Unable to load class named 'FormApp.Form' for entity 'Form'. Class not found, using default NSManagedObject instead.
It is happening on line:
let form = NSEntityDescription.insertNewObject(forEntityName: "Form", into: managedObjectContext) as! Form
My config:
All classes were generated by Xcode. I have tried deleting Module and all configurations. Anyone have idea how to make it work?
For some reason NSSet is expected, but your NSManagedObject code has NSOrderedSet, which is a subclass of NSObject. Try to remove "Arrangment: Ordered" checkmark in your core data model and refactor those relationships to NSSet.
Not sure why this happens in iOS 10 but not in iOS 9 though.
P.S. Perhaps you should reconsider your Core Data model? It looks like your Open/Closed questions are going to change their status. If so, I would recommend to make one Question entity with closed bool or status int.
I was having the same issue with iOS 9.3
The issue was same as mention by #alex above and i have solve as below
if #available(iOS 11.0, *) {
// use iOS 11-only feature
YOUR_CLASS.insertIntoClosedQuestion(YOUR_OBJECT, at: index)
} else {
// handle older versions
let orderset:NSMutableOrderedSet = Form.closeQuestion as! NSMutableOrderedSet
orderset.insert(YOUR_OBJECT, at: index)
YOUR_CLASS.addToClosedQuestion(orderset)
}
Hope it will helpful to others.
Does anyone know of a good way to write an iOS 8 share extension without the MainInterface.storyboard that comes with the template?
When I delete the file or remove the NSExtensionMainStoryboard from Info.plist, the extension stops working (nothing happens when you tap on the button in the share pane). We tried replacing NSExtensionMainStoryboard with NSExtensionPrincipalClass which also didn't work.
Any ideas?
Figured it out!
Turns out there's a weird module naming thing going on in Swift, so you can fix it by adding an #objc name to the class:
#objc(PrincipalClassName)
class PrincipalClassName: UIViewController {
...
and then set the NSExtensionPrincipalClass key to PrincipalClassName.
Instead of the #objc hack, the proper way to do it in Swift is to include the module name in NSExtensionPrincipalClass, i.e.,
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ActionViewController</string>
(Documenting the error otherwise:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: ...)'
Hopefully will help someone who run into this error in the future.)
Found the answers from these answers combined Answer 1 and Answer 2.
For Objective-C you will have to put the following in the info.plist of the App extension:
NSExtensionPrincipalClass and make sure that it is under NSExtension Dict
So full answer should be like this , in my case ActionViewController is the App extension viewController
Can't add a comment but it is no longer NSPrincipalClass rather it is NSExtensionPrincipalClass
I have a problem that I could not understand, I'm using a library for the use of Map Open Source Map (https://github.com/route-me/route-me), the example works perfectly, and I believe not to be something connected to the code , I believe it is something in the configuration.
Well what happens is that if I make the following call:
RMMarkerManager *markerManager = [mapView markerManager];
I get an error that says the UIView class does not have the method markerManager:
2013-08-05 17:18:33.573 MapOffline[1310:907] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView markerManager]: unrecognized selector sent to instance 0x1d88fbb0'*
No entanto, se eu adicionar a validação, o código funciona perfeitamente:
if ([mapView isKindOfClass:[RMMapView class]]) {
RMMarkerManager *markerManager = [mapView markerManager];
}
The sample project does not have this validation and works, someone could tell me what can be?
It is not good practice validate whenever you use methods of this class.
Note: The RMMarkerManager class inherits from UIView.
What happened in my case was that I was not making reference to some images that were being used by the project the in example.
I honestly do not know what that has to do one thing with another, more after adding the images in the project, everything worked perfectly.
I guarantee that I have made no other changes.
My .xib always configured and referenced everything as it should.
I'm not understanding why this, more this was my solution.
:-/
If you used a storyboard then you need to set the "custom class" (in the identity inspector panel) of your view to be RMMapView. Otherwise the storyboard doesn't know which class to instantiate for your view.
I am using MapBox example and I have imported my mbtiles file. I am getting this error:
MB Example[8517:c07] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '* -[NSURL
initFileURLWithPath:]: nil string parameter'
I have checked my mbtile file and its loading on x-code so there no problem with it.
RMMBTilesSource is indeed using that code. You need to make sure that your OSMBright.mbtiles file is part of the project's target and being added to your bundle so that it can be pulled up as a tile source. Like any resource that you need to use in your app, it's not enough to simply be part of the Xcode project.
The reason for the crash is clear from your question itself. reason : [NSURL initFileURLWithPath:]: nil string parameter. You are initializing NSURL without passing a nil parameter. Search for initFileURLWithPath and check wether the parameter is nil or not
[NSURL initFileURLWithPath:] // Pass a valid path here
Your question cannot be answered correctly in it's current format. You need to add the code related to the issue.
The issue is you are passing a nil parameter to the initFileURLWithPath method.
Possibly the mbtiles file is missing. So it'll return nil, also issue can be in the Mapbox.
Please check that you added it to the project correctly.
Had the same error. Are you sure you copied the MapBox.bundle from the .framework into your Xcode-Project as stated here:
https://www.mapbox.com/mapbox-ios-sdk/
?
That fixed it for me!