aryaxt / OCMapper

Objective-C library to easily map NSDictionary to model objects, works perfectly with Alamofire. ObjectMapper works similar to GSON
MIT License
347 stars 45 forks source link

Crash String - stringByRemovingPercentEncoding #40

Open sadanro100 opened 8 years ago

sadanro100 commented 8 years ago

For some weird reason, converting an object to a dictionary crashed with the following error:

valueForUndefinedKey:]: this class is not key value coding-compliant for the key stringByRemovingPercentEncoding

if there was a string generated with the following code set to a property in the object

func generateRandomKey(amountOfCharacters: Int) -> String {

    var alphabet = Array("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789".characters)
    var randomKey = String()

    for (var i = 0; i < amountOfCharacters; i++) {
        randomKey.append(alphabet[Int(arc4random_uniform(62))])
    }

    return randomKey
}

I have now changed to the following solution and it works, funny though:

func generateRandomKey (len : Int) -> String {

    let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

    let randomString : NSMutableString = NSMutableString(capacity: len)

    for (var i=0; i < len; i++){
        let length = UInt32 (letters.length)
        let rand = arc4random_uniform(length)
        randomString.appendFormat("%C", letters.characterAtIndex(Int(rand)))
    }

    return randomString as String
}
sadanro100 commented 8 years ago

Well, I suppose it's got something to do with how OCMapper handles it's String parsing, and gets messed up at some point, which makes me think whether I should be concerned with content I try to parse that's been typed by the user, since the output string causing the problem had nothing special in it.

Feel free to remove the topic if you feel offended, I merely wanted to share a negative experience I had, which could help others.

On Oct 15, 2015, at 12:11 PM, Aryan Ghassemi notifications@github.com wrote:

hmmm what does this have to do with OCMapper?

— Reply to this email directly or view it on GitHub https://github.com/aryaxt/OCMapper/issues/40#issuecomment-148417296.

aryaxt commented 8 years ago

sorry, I missed the part where you said convert object to dictionary :) My bad for a second I thought you opened a bug in a wrong repo hehe Will check to see why it's crashing, thanks