How many programmers use to do, I also build my own library of functions ready to be reused in multiple projects and multiple contexts. Let me pass the title of this post, perhaps a bit 'risky but, nevertheless, as we shall see, not far from reality.
In Objective-C code can call and write C / C + +, including the assembly for that matter. This characteristic makes it a very versatile language and, in some respects, phenomenal. On the one hand, you can use and appreciate the purely Objective-C syntax, the other can run fast porting of code written in ANSI C (perhaps for Digital Unix or Sun) and can comfortably fit into our iPhone and iPad applications; not to mention all the BSD kernel is already available on Mac OS X!
More ...
Returns the name of a file from the object NSURLRequest , allowing you to decide whether or not its extension:
More ...
NSString is a very powerful class, let me show you some of the most used properties:
printf ()
1 2
| / / Printf () output = [ NSString stringWithFormat : @ "%@ / %@" , @ "primo" , @ "secondo" ] ; NSString * output = [ NSString stringWithFormat: @ "% @ /% @", @ "first", @ "second"]; |
Run the split ()
1 2 3
| / / Split () / explode () list = @ "Norman, Stanley, Fletcher" ; NSString * list = @ "Norman Stanley Fletcher"; listItems = [ list componentsSeparatedByString : @ ", " ] ; NSArray * ListItems = [list componentsSeparatedByString: @ ""]; |
Convert from string to value
1 2 3
| / / Converting doubleString = @ "123" ; NSString * doubleString @ = "123"; [ doubleString doubleValue ] ; double value = [doubleString doubleValue]; |
Within a string
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| / / Substring searchString = @ "age" ; NSString * searchString = @ "age"; beginsTest = @ "Agencies" ; NSString * beginsTest @ = "Agencies"; [ beginsTest rangeOfString : searchString NSRange prefixRange = [beginsTest rangeOfString: searchString NSAnchoredSearch | NSCaseInsensitiveSearch ) ] ; options: (NSAnchoredSearch | NSCaseInsensitiveSearch)]; / / PrefixRange = {0, 3} endsTest = @ "BRICOLAGE" ; NSString * endsTest = @ "DIY"; [ endsTest rangeOfString : searchString NSRange suffixRange = [endsTest rangeOfString: searchString NSAnchoredSearch | NSCaseInsensitiveSearch | NSBackwardsSearch ) ] ; options: (NSAnchoredSearch | NSCaseInsensitiveSearch | NSBackwardsSearch)]; / / SuffixRange = {6, 3} |
More ...
The MapKit framework provides many useful features, except the return of Latitude and Longitude from an address. In JavaScript, for example, you can use the service provided by Google Geocoding and discussed in Google Maps: How to get Latitude and Longitude from an address . On Apple iPhone or iPad, however, you can overcome the obstacle by using a different Google services. Specifically, you can directly call the url:
1
| http://maps.google.com/maps/geo?q = [address] & output = csv |
Where is [indirizzo] to enter the string with the address you want to transform coordinates. The output returned is of type:
1
| 200,8,41.9128300,12.2241172 |
). The first value, 200 , indicates that everything went well ( 200 OK ). The second, 8 , is the Google accuracy parameter (1-10). The last two values are, finally, latitude and longitude. Now we see a prototype of a method can be included in our applications:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| CLLocationCoordinate2D ) getLocationFromAddress : ( NSString * ) address { - (CLLocationCoordinate2D) getLocationFromAddress: ( NSString *) address { urlString = [ NSString stringWithFormat : @ "http://maps.google.com/maps/geo?q=%@&output=csv" , NSString * urlString = [ NSString stringWithFormat: @ "% @ http://maps.google.com/maps/geo?q = & output = csv" NSUTF8StringEncoding ] ] ; [Address stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; listItems = [ locationString componentsSeparatedByString : @ "," ] ; NSArray * ListItems = [locationString componentsSeparatedByString: @ ""]; / / Int zoom = 0; 0.0 ; double latitude = 0.0; 0.0 ; double longitude = 0.0; listItems count ] > = 4 && [ [ listItems objectAtIndex : 0 ] isEqualToString : @ "200" ] ) { if ([ListItems count]> = 4 && [[ListItems objectAtIndex: 0] isEqualToString: @ "200"]) { / / Zoom = [[ListItems objectAtIndex: 1] intValue]; listItems objectAtIndex : 2 ] doubleValue ] ; latitude = [[ListItems objectAtIndex: 2] doubleValue]; listItems objectAtIndex : 3 ] doubleValue ] ; longitude = [[ListItems objectAtIndex: 3] doubleValue]; { Else {} / / Error } CLLocationCoordinate2D location; location.latitude = latitude; location.longitude = longitude; return location; } |
Notes of Interest
, alla stregua della funzione explode ( ) del PHP per intenderci. The string returned in locationString is "splitted" by the method componentsSeparatedByString , like the function explode ( ) of PHP for instance. In the example I proposed I entered - but commented - the code to retrieve even the Google parameter accuracy, precision or scale factor, denoted by zoom .
Source as
For completeness, I made a small example application with which you can try the method proposed above, enter any address and the iPhone will display on the map.


Download Source
I thank the team devAPP for the inspiration of this article.
More ...
Latest Comments
Subject : very helpful indeed! I tried it and it is just what I needed. Now I wonder how do I get ...
vik : With strategic help!
Pepper : Hi there, I do not know if you're one of the creators of the WP plugin Bannerize. I have spotted a ...
Rosanna : Can anyone tell me how do I delete the Snap Shots window that opens automatically when I ...
blessed Maresca : I can not download any skypemote me spiegaaa