Does lexicontext ios sdk provide autocomplete in utf8 - ios

Does lexicontext ios sdk provide autocomplete in utf8?

Not out of the box I'm afraid.
But I think it shouldn't be too difficult to add this functionality using the dictionary's search API.
// first obtain a reference to the dictionary
Lexicontext *dictionary = [Lexicontext sharedDictionary];
// later, given a prefix that the user typed, do something like:
NSDictionary *words = [dictionary wordsWithPrefix:prefix];
You should probably start offering to auto-complete for prefixes of at least 2 characters.
Otherwise, you may get very long results. For example, the result for [dictionary wordsWithPrefix:#"a"] returns a result of about 1800 Adjectives, 400 Adverbs, 500 Verbs... and will probably be too slow :)

Related

Difference between accessing values using subscripting and using just valueForKey in NSDictionary

I have the following line:
_driverName.text = [[[responseDictionary valueForKey:#"response" ] valueForKey:#"driverinfo"]valueForKey:#"name"];
But I think I can shrink this line by using subscription in this way:
_driverName.text = responseDictionary[#"response" ][#"driverinfo"][#"name"];
it seems more clean and readable.
is it possible to apply this syntax without collateral consequences?
thanks in advance
Ignoring the misuse of valueForKey: (use objectForKey:), you should not use either example in your question. Both suffer from being impossible to debug when you run into issues because the data structure isn't what you thought it was.
While it takes more time, it is worth it in the end to split each access into a separate line:
NSDictionary *response = responseDictionary[#"response"];
NSDictionary *driverInfo = response[#"driverInfo"];
_driverName.text = driverInfo[#"name"];
But using the modern subscript syntax is always easier and less prone to error than using objectForKey: and it ensures you don't mistakenly use valueForKey:.

split string in ios string from json data?

I have one string. Now I wanted to split this string. For static separation I know the code but I don’t code for dynamic value.
my string is
NSString *str = #"https://graph.facebook.com/v2.5/181054825200000/feed?fields=created_time,message,picture,full_picture,comments.limit%280%29.summary%28true%29,likes.limit%280%29.summary%28true%29&limit=5&format=json&access_token=CAALjFrE5mNYBAOg1EDiUrsE2kr1kIRrLIv7g4OweSMvHso2exB5Dttshn7dgOlW24ZCXSnDZAWiV6xMUKXedTXUhiHpdmZBPCGzD1orFlrLRP2gaBZCbZBZBnjUHewF9hZBmJKxtiwVzpw9gnnQXk5Hfx0ZBM2ksAUzkSWR5feaNMbf3UUmUpJlxeh0gKdDrzWBvIJRPy0xGqL0ZAMFsRhyCZCTX42l1sZAceZB0VCeDZB95mrAZDZD&until=1456345291&__paging_token=enc_AdCKD3tSYMoZB3MCKaJkYnbVmBgUyY2tBceGDD2G1hqxRDiQKZCsSbmvWZASLvlCMf0BVzq2uZAScSWp7ZAavZB2d72BIHJISefk09noRuv9gA5b5hFwZDZD";
but i don’t how to show any value dynamically .(for e.g. until (in string))
please help me for this issue.
Thank You.
If you are parsing a URL you should really use NSURLComponents. It makes breaking a URL into the different parts much easier, and the code is tested and verified by Apple.
For separate string by a separator you can use this.
NSString *url = #"<url>";
NSArray *array = [url componentsSeparatedByString:#"<seperator string>"];
NSLog(#"%#", array);
But for URL parsing ,As per Duncan's answer, yes it is good to parse a URL using NSURLComponents. By using this class you can get any desired part of an URL.

GAIDictionaryBuilder fails for NSNumber values

I am trying to send commerce transaction data to google analytics on iOS with V3 SDK. I am building the data dictionary using GAIDictionaryBuilder class provided by Google (which is not open source unfortunately). For both createTransactionWithId and createItemWithTransactionId calls, my NSNumber values (revenue, price, etc.) are failing to be added to dictionary data properly. Here is the sample code:
NSMutableDictionary* test = [[GAIDictionaryBuilder createTransactionWithId:(NSString *)transactionId
affiliation:(NSString *)affiliation
revenue:(NSNumber *)revenue
tax:(NSNumber *)tax
shipping:(NSNumber *)shipping
currencyCode:(NSString *)currencyCode] build];
NSLog(#"revenue: %#", revenue);
NSLog(#"TR data: %#", test);
// if I explicitly set the value, IT WORKS!!!!
[test setObject:revenue forKey:#"&tr"];
NSLog(#"TR data FIXED??: %#", test);
In the output, I see revenue correctly, then when logging test dictionary I see the following line corresponding to revenue data:
"&tr" = "<null>";
Then, for the manual fix attempt, I see
"&tr" = "15.25";
as expected.
Here are some clues:
I use the same code in a different project compiled in a different OSX machine without any issues like this.
The transactions are in TRY (Turkish Lira), I suspect Google is trying to fix the separator (',' in Turkish vs '.' everywhere else), but as said above, the other app is also using TRY.
So the question is, why "<null>", why and how does it fail to convert a proper NSNumber to this bizarre value?
Eventually, I fixed the issue by working around it. I assigned the NSNumber to a new one (by getting its floatValue) and it seemed to fix the null values.
By the way, google analytics library version 3.07 readme mentions a similar issue as fixed however neither 3.03 nor 3.07 actually fixed my problem.

iOS AES encryption wrong result

Here is how I encrypt the string:
+ (NSString *)encrypt:(NSString *)message password:(NSString *)password {
NSData *encryptedData = [[message dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptedDataUsingKey:[password dataUsingEncoding:NSUTF8StringEncoding] error:nil];
NSString *base64EncodedString = [NSString base64StringFromData:encryptedData length:[encryptedData length]];
return base64EncodedString;
}
The plain text is:
{"roomID":"{\"array\":[\"949156\",\"949157\"]}","duration":15,"link":"","type":"text","thumbnailBlobID":"","posy":103.6809424405021,"text":"Aa","className":"Message","originalBlobID":"","datetime":"20140319214528457","selfDestructive":0,"userID":"949157","posx":1.347154229880634,"status":"normal","entityID":"20140319214528457and949157and{\"array\":[\"949156\",\"949157\"]}"}
This is what I get
gXqxfDhImRD7S20lUdYuCPAlXfqRnG6xk4w4K5Op/WnYMh6VgJUUqMifK2vHkUpAbnZ+wKdSWjfzU1PuOwvJ4dJ9EiHwjeyyorezFNG6eylYcOvMWNeU6+5Z9XxfcFngqhmxM6k1lf7bkttTu0FnEHad/czFgiMVTy60DJpFMLSODkKEVezqQB9s/f3Qy/B6+sF5Hs5E0FDn7kU6Jtm6mLkFjGzDCXTdFXNjdussbkTL8C1gcOnn4hrNkqQKb82MgqqYf8sVgs4FVIjsmoJd0ALY8y/5QbBkgc6ZyB4aOQPPx/u4HS3F7HXHkIkkAjZS/hiHQBRyfwCvi2uwFedno5twYogNW56pSMQqBeJBxBAhPMpXzb51853GLP4bCotGtOyEfU96x5kWHDOR5QA2WhYZkB3AALDJ2kfqzWR8iOKHo3zE6DCQ7aH0RwEFlNPi8vsNwvUqtQ7nUODA5lUMYah6W2rfDh/em8BD8dGF5J6IUTIlSerx8wWPA9bn/SxO
From website http://aesencryption.net (256 bit)
(Which i assume to be the correct answer
5MdV0TelF++/8Cy9bnkeah0nQ5JbC04CEdCcHfdlavQtZaxg3ZSXklp9yXbeP05hcIeQDgFcMr9NlD6aKhjBL3Xh70ksYqc6Xv5BZvCbXrvO4ufAf4gjmDRQr9DYSbjFct6N82fFGDtrcuFm36Zv+QAQtR/scT86A++Vn/EBlPwFb7ZmxlMPkJWjQ98ObreXHeKkZ8f2npMKfJ0i36nIZ8CZeL0EYeg/njo9ykPTfm9wfKieqlIICn1qNZAXE//P9hTleW/GNs5+ET2gxNSCmdO+ByUB9Q3sZ/+57qXbsfCxHr8dsuBrsbRI+cVIXyquQL1IC/zuz3G3fcyoiLrD/PnFtV5z5XR0hpUiU8JjovjYwyXaBfyTBnO71zxmdoZdsyPwA1LQO0pedn8UsICT2KbfBKwuumW2CJPexbnMmVzpIJ/VPISikdg18V3rdJqiPMIb4Zq2PGKO0Wtq1dCTMusTv/ZnqxgVQFQlUivgBqtnOLCDaMAGL636NXda95V2
There is no single standard way to apply AES, or standard data format for the output. AES requires a number of helpers when used on data that is not exactly 16-bytes long, and they can be configured in different ways. I have no idea how the aesencryption.net tool is applying these helpers; it doesn't say. If AES256EncryptedDataUsingKey: is the particular piece of code I assume it, it applies them very poorly (it's very similar to the code I discuss in Properly Encrypting With AES With CommonCrypto). I would not be surprised if aesencryption.net does something different.
If you have a piece of plaintext and a key, and you pass it to an encryptor twice and get the same answer back, then your encryptor is broken. A correct AES encryptor (for almost any common use of AES) should always return different results for the same plaintext+key (otherwise an attacker can determine that two plaintexts are equal, which breaks the security proof of AES). In the most common case, this is achieved by having a unique initialization vector (IV). For password-based AES, you also include a random salt. So even if these were good implementations of AES, you wouldn't expect your results to match.
Is it possible that the escape characters (the back slashes) are being interpreted differently in code versus via the web? The bottom line here is I would (in code) decode what you just encoded and you should come out with the same as what you put in. This is probably the test you want to conduct. Hope this helps. Also see comment below from #RobNapier

My NSDictionary somehow has multiple values for one key

I have been attempting to debug a issue with my code, and just came upon an odd phenomenon. Found this in the debug area when a breakpoint was triggered:
Am I correct in observing that there are multiple values for this key: #"6898173"??
What are possible causes of this? I do not set those key-value pairs using the string literal, but by getting a substring of a string retrieved and decoded from a GKSession transmission.
I still have this up in the debug area in xcode, incase theres anything else there that might help.
EDIT:
By request, here is the code that would have created one of the two strings (another was created at an earlier time):
[carForPeerID setObject:[[MultiScreenRacerCarView alloc] initWithImage:[UIImage imageNamed:#"simple-travel-car-top_view"] trackNumber:[[[NSString stringWithUTF8String:data.bytes] substringWithRange:range] intValue]] forKey:[[NSString stringWithUTF8String:[data bytes]] substringFromIndex:9]];
The string in data might look something like this:
car00.0146898173
EDIT:
Code that sends the data:
[self.currentSession sendData:[[NSString stringWithFormat:#"car%i%#%#", [(MultiScreenRacerCarView *)[carForPeerID objectForKey:peerID] trackNumber], speed, [(MultiScreenRacerCarView *)[carForPeerID objectForKey:peerID] owner]] dataUsingEncoding:NSUTF8StringEncoding] toPeers:#[(NSString *)[peersInOrder objectAtIndex:(self.myOrderNumber + 1)]] withDataMode:GKSendDataReliable error:nil];
Sorry its hard to read. Its only one line.
What you're seeing is a debugger "feechure". When you have a mutable dictionary and modify it, the debugger may not show you the correct view of the object.
To reliably display the contents of an NSMutableArray or NSMutableDictionary, switch to the console and type po carForPeerID.

Resources