RestKit - using colon in Paginator Path crashes - ios

I am using RKPaginator to fetch objects from following URL:
http://devSite.com/api/products?pid=somePid&fl=p7:9&limit=5&offset=0
I am setting the path as follows :
NSString*urlPAth = [NSString stringWithFormat:#"http://devSite.com/api/products?pid=%#&fl=p7:9&limit=:perPage&offset=:offset", pid];
But it does give an error and crashes :
* Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[
valueForUndefinedKey:]: this class is not key value coding-compliant
for the key 9.
I know this is because of the colon, but couldn't fine any solution to fix this.

You can't use : in the path when you're using injected parameters because it will be treated as a parameter. If you need to use : then you either need to encode the colon (perhaps to %3A) or you need to inject that value as part of (or after) the parameter injection (which will probably require you to subclass the paginator).

In my case the URL have this scheme:
..elements/DOCCOMPANY_FILE:1502328/structure
That means in my case: "From element with key "DOCCompany:150.." GET its structure.
This will not work with the RKPaginator Class in restkit.
But if you can edit your local sources, add this to the RKPaginator or subclass it:
-(id)valueForUndefinedKey:(NSString *)key {
return [NSString stringWithFormat:#":%#",key];
}
This will ignore all unknown parameters in URL in the pagination class and works well for me.

Related

SharkORM Encrypted properties issue in iOS Swift 3

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.

Swift - Weird coding-compliant error

I'm having a problem and I couldn't find anyone else on the web with the same struggle, maybe it's just too silly.
I have the following class:
class UIXOColourPicker : UIView {
#IBInspectable var moodValue: Int!
...
}
And in my storyboard I have a view just like this:
The user defined runtime attribute was generated by Xcode IBInspectable functionality (which is really cool btw), but whenever I try to run the app I get the error
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIXOColourPicker 0x7fa86877c420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key moodValue.'
I'm on Xcode 6 - Beta 6.
Any ideas?
Sorry if it's a silly question, but I've been struggling with it for like 2 hours and I don't have any other Swift developer here to have a look at it.
Cheers
#IBInspectable uses cocoa objects and not native swift types. So, anything that isn't implicitly convertible to a swift type needs to be a cocoa object instead. For Number or Bool you'd need NSNumber. For something like Point, Size, Rect, etc, you'd need to use NSValue. However, for String you can use String directly; you don't need to use NSString.
So, in your case, you need to use NSNumber instead of Int. I'd also use NSNumber? instead of NSNumber! in case the value isn't set in your storyboard/xib.
#IBInspectable var moodValue: NSNumber?
Update
As #JakeLin and #Echelon pointed out, for int like values, Xcode will only show the attribute in the Attributes Inspector if you declare it as an Int?, but then it will crash at runtime. If you use an NSNumber?, it won't crash at runtime, but the attribute won't be available in the Attributes Inspector anymore; it will only show up in the User Defined Runtime Attributes (this seems like a bug in Xcode to me).
The error itself tells us how to get around that problem though:
IBInspectable[66994:58722469] Failed to set (moodValue) user defined inspected property on (q25429792___IBInspectable.ViewController): [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key moodValue.
What this is saying is that the runtime can't find a "key value coding-compliant" attribute on the class for moodValue (Int attributes aren't key value coding-compliant) and that you can implement setValue:forUndefinedKey: to fix that.
In that case, the implementation might look something like this:
#IBInspectable var moodValue: Int?
override func setValue(value: AnyObject?, forUndefinedKey key: String) {
if let value = value as? Int? where key == "moodValue" {
self.moodValue = value
}
}
So, if you really want the attribute to show up in the Attributes Inspector and you don't mind adding the extra method, declare your property as an Int? and implement setValue:forUndefinedKey:. If you don't want the extra method, you'll have to content yourself with using an NSNumber? and the User Defined Runtime Attributes UI.
This is down to your type for moodValue. It seems the KVO system can't handle the type coercion needed; it's looking for a moodValue with the actual type NSNumber. Changing
#IBInspectable var moodValue: Int!
to
#IBInspectable var moodValue: NSNumber!
Then picking out the moodValue.integerValue should do what you want.

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

ios comparing string in a nsmutabledictionary wtih a string I got this error: 'NSInvalidArgumentException'

I have this line of code where I'm trying to compare a string inside of nsmutabledictinary to string:
if ([[[myDictionary valueForKeyPath:#"time"] stringValue] isEqualToString:#"hours"])
but I'm getting this error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString
stringValue]: unrecognized selector sent to instance 0x3a4849a4'
I check the type of class of the dictionary container:
NSLog(#"%#'", NSStringFromClass([[myDictionary valueForKeyPath:#"time"] class]));
this is the output:
__NSCFConstantString
any of you knows why or how can fix this?
I'll really appreciate your help.
[myDictionary valueForKeyPath:#"time"]
It is already an NSString. There is no need to call -stringValue to convert it to a string.
Why are you doing that ?
Instead of using -valueForKeyPath, you should write it like this :
if ([[myDictionary objectForKey:#"time"] isEqualToString:#"hours"])
NSString does not have a stringValue method. You've likely seen this sort of thing used to turn an NSNumber in a dictionary into a string.
It seems likely that what you really want to do is:
if ([myDictionary[#"time"] isEqualToString:#"hours"]) {
...

Mapbox show Exception and terminate when using mbtiles in ios

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!

Resources