NSInvalidArgumentException isKindOfClass - ios

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.

Related

I changed the display name of my app in xcode and it no longer runs without crashing

After I tried changing the display name of the project, whenever I run it, as it launches it crashes with this error message:
2020-03-23 19:32:05.010069+0200 Coronavirus Tool[10927:4335736]
Unknown class _TtC8CoronaMT18TipsViewController in Interface Builder
file. 2020-03-23 19:32:05.059007+0200 Coronavirus Tool[10927:4335736]
Unknown class _TtC8CoronaMT24StatisticsViewController in Interface
Builder file. 2020-03-23 19:32:05.061510+0200 Coronavirus
Tool[10927:4335736] Unknown class
_TtC8CoronaMT28RiskCalculatorViewController in Interface Builder file. 2020-03-23 19:32:05.063672+0200 Coronavirus Tool[10927:4335736]
Unknown class _TtC8CoronaMT27NotificationsViewController in Interface
Builder file. 2020-03-23 19:32:05.067168+0200 Coronavirus
Tool[10927:4335736] Unknown class _TtC8CoronaMT18MoreViewController in
Interface Builder file. 2020-03-23 19:32:05.131735+0200 Coronavirus
Tool[10927:4335736] * Terminating app due to uncaught exception
'NSUnknownKeyException', reason: ‘[<UIViewController 0x101c0e820>
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key blueButton.'
* First throw call stack: (0x181086d8c 0x1802405ec 0x1810869f0 0x1819dc44c 0x18b1375a0 0x18b3097e4 0x180f94b24 0x18b3081f4
0x18b139aa8 0x18ad7d074 0x18aca1b14 0x18ad4fe1c 0x18ad4f2d8
0x18ad4ec14 0x18ad4e6a4 0x18ad423a8 0x18ac9a6f4 0x18520fe54
0x185213fe4 0x1851806c8 0x1851a81b0 0x18b084680 0x18102f2bc
0x18102ea7c 0x18102c7b0 0x180f4cda8 0x182f32020 0x18af6c758
0x100bc550c 0x1809ddfc0) libc++abi.dylib: terminating with uncaught
exception of type NSException
I've tried adding the Bundle display name in the info.plist, and reverting the name back to the way it was, along with cleaning the project, restarting xcode, and deleting the app/reinstalling it.
Can someone please help me fix this???
Your clue in this error is blueButton. My hunch is that the IBOutlet has a previous outlet still connected to blueButton. Check to see if you have two outlets connected to blueButton. If so, Xcode crashes because it doesn't know which outlet to use. Hope that helps.
Usually the “UIViewController ... is not KVC-compliant for ...” message is an indication that the base class for your scene has not been set (hence the “UIViewController” at the start of the warning), and therefore the blueButton outlet wasn’t found.
(FWIW, if the warning was “RiskCalculatorViewController ... is not KVC-compliant for ...”, that would suggest a problem with the outlet in that particular UIViewController subclass. But the error doesn’t reference any particular subclass of UIViewController, which indicates that the problem is not the outlet itself, but rather with the base class of this storyboard scene.)
Fortunately, you shared a series of error messages with us. We can see a litany of view controller classes that the storyboard was unable to find (see the errors before the bolded one). This suggest a more fundamental problem, where something went wrong in your renaming process, rendering all of these storyboard base classes unfindable.
If you can, rollback to prior version of the app and try the renaming process again.
If not, you’ll have to manually clean this up. It seems that at least one of two possibilities has taken place:
Your view controller classes (and possibly other source files) do not have not their “Target Membership” set correctly:
Make sure you have a checkmark next to your main target.
Assuming that’s OK/fixed, go back to your storyboard and check the “Module” selected for your scene’s base class.
Make sure the “Module” is your main target.
Sometimes you can just select the module and you’ll be fine. Sometimes, though, this doesn’t work. In that case, I often will delete the “Class” name in this “Custom Class” section, leave the field, and then come back and enter the class name again, and the module will be selected correctly.

UIImage+ResizeMagick | NSInvalidArgumentException | iOS | Swift

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

Unrecognised Selector when using nicklockwood's CountryPicker in Swift

I know they say there is no such thing as a stupid question, but I feel stupid since I know this question has been asked dozens of times before, but I can't seem to find one of the solutions which fit my case (I have made the effort of looking).
So the problem I face is that I am creating a Swift iOS project, and am looking to implement a country picker. From what i can tell, there is no native solution for that array of countries, so I came across what looks to be a nice custom solution by 'NickLockWood' ( https://github.com/nicklockwood/CountryPicker )
And the problem is that I am having a little trouble trying to get it to work in my Swift project, since all the sample and demo code provided is in obj-c (I am in the process of getting better at converting such code from one language to another, but I appear to not be at the ninja level yet for this..).
From what I can tell, this is how he uses it in his viewController
- (void)countryPicker:(__unused CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code
{
self.nameLabel.text = name;
self.codeLabel.text = code;
}
I have managed to try convert that into my Swift viewController as such..
func countryPicker(picker: CountryPicker?, didSelectCountryWithName name: String!, code: String!) {
println("\(name)")
println("\(code)")
}
So when the app launches, the listPicker is populated with country names and the associated flags. So I have a good feeling it is hooked up mostly correctly.
The error occurs when I spin the picker and it lands on a selection. I then get this...
exception 'NSInvalidArgumentException', reason: '-[UIViewController countryPicker:didSelectCountryWithName:code:]: unrecognized selector sent to instance 0x17dca740'
In my ViewController, where this picker is associated with, I used the storyboard to link the 'CountryPicker' delegate to the ViewController.
Then in the ViewController this is my code..
import UIKit
class RegionViewController: UIViewController, CountryPickerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func countryPicker(picker: CountryPicker!, didSelectCountryWithName name: String!, code: String!) {
println("\(name)")
println("\(code)")
}
Am I perhaps missing something else here?
Thanks!
My error.
I hadnt associated the viewController I was working on in the storyboard to use the custom RegionViewController I was trying to reach.
Fixed that connection and all was right again.
Thanks!

Initialising swift view controller with nib name in objc class

In my app I have a view controller written in Swift. I imported it in to app delegate which is written in objective c. I try to create an object of the swift view controller like this
ListAllSongsViewController *songListVC = [[ListAllSongsViewController alloc]initWithNibName:#"ListAllSongsViewController" bundle:nil];
The ListAllSongsViewController is written in swift. The project compile without any issue but when executing the above line the app crashes & stops at init method of ListAllSongsViewController
There is nothing in the log, it just stops. Zombie & All exception break points are enabled.
P.S. It only crashes in device (iOS 7.1), but works fine in simulator
Update :
Getting the same issue even if I use the default swift initialiser
ListAllSongsViewController(nibName: "ListAllSongsViewController", bundle: nil)
Usually occurs when you passed a wrong nibName. Considering it crashes only in device, I think you've made a mistake about the case of the string ListAllSongs, because the Mac/Simulator's file system is case insensitive while the device is not.

Writing an iOS 8 share extension without a storyboard

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

Resources