Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash String - stringByRemovingPercentEncoding #40

Open
sadanro100 opened this issue Oct 15, 2015 · 2 comments
Open

Crash String - stringByRemovingPercentEncoding #40

sadanro100 opened this issue Oct 15, 2015 · 2 comments

Comments

@sadanro100
Copy link

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
Copy link
Author

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 [email protected] wrote:

hmmm what does this have to do with OCMapper?


Reply to this email directly or view it on GitHub #40 (comment).

@aryaxt
Copy link
Owner

aryaxt commented Oct 15, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants