views:

12

answers:

1

In a previous answer I found on stackoverflow (can't find now) someone suggested using NSRange rangeOfString to see if a particular variable had data in it from a cookie:

NSRange range = [[[NSHTTPCookie requestHeaderFieldsWithCookies:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:cookie]]] objectForKey:@"Cookie"] rangeOfString:@"variable"];
if (range.length != NSNotFound) {
    //it has data
} else {
    //it doesn't
}

From what resources I can find this should work, but it doesn't, even when the cookie is null.

What am I doing wrong?

A: 

This is a bit odd. Even though range.length is apparently null if you log the output you can't check if its null and NSNotFound doesn't work as expected. You have to check if the value > 0.

Rudiger