Try the search, it's linked to some great forums

Showing posts with label training. Show all posts
Showing posts with label training. Show all posts

Tuesday, September 29, 2015

Swift notes

Tips, tricks & notes about Apple's Swift;

Functions & Closures -  https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-ID94
  • Functions - Use func to declare a function. Call a function by following its name with a list of arguments in parentheses. Use -> to separate the parameter names and types from the function’s return type.
  • Functions can also take a variable number of arguments, collecting them into an array -      func sumOf(numbers: Int...) -> Int {
  • Functions can be nested. Nested functions have access to variables that were declared in the outer function. You can use nested functions to organize the code in a function that is long or complex.
  • Functions are a first-class type. This means that a function can return another function as its value. 
  • Functions are actually a special case of closures: blocks of code that can be called later. The code in a closure has access to things like variables and functions that were available in the scope where the closure was created, even if the closure is in a different scope when it is executed 
  • Closures are self-contained blocks of functionality that can be passed around and used in your code.
  • You can write a closure without a name by surrounding code with braces ({}). Use in to separate the arguments and return type from the body. 
  • Single statement closures implicitly return the value of their only statement -                         let mappedNumbers = numbers.map({ number in 3 * number })
  •  A closure passed as the last argument to a function can appear immediately after the parentheses. When a closure is the only argument to a function, you can omit the parentheses entirely - let sortedNumbers = numbers.sort { $0 > $1 }
Objects and Classes -  https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html#//apple_ref/doc/uid/TP40014097-CH13-ID82
  • Use class followed by the class’s name to create a class. A property declaration in a class is written the same way as a constant or variable declaration, except that it is in the context of a class. Likewise, method and function declarations are written the same way.
  •  Use an initializer to set up the class when an instance is created. Use init to create one.  
  •  init(name: String)  
    self.name = name
        }
  •  Notice how self is used to distinguish the name property from the name argument to the initializer.
  •  
Other Notes taken at random places:
  • Completion Handlers, used for closures in many functions (see AlertViews) - good post This is the BEST tutorial I found, it hs all the flavors - http://sourcefreeze.com/uialertcontroller-ios-8-using-swift/
  • Alert screens, used for popups & User instruction - good tutorial 
  • You use this representation to create an adaptive interface, which is an interface that automatically adjusts so that it looks good in the context of the current device and orientation.
  • var window: UIWindow? - the question mark means it's optional ( ie it may not exist ie (may be nil))
  • variables are mutable - var myVariable = 42
  • constants are immutable - let myConstant = 42
The AppDelegate class is where you write your custom app-level code. 

Singleton - Swift - ObjectiveC migration
Singletons provide a globally accessible, shared instance of an object. You can create your own singletons as a way to provide a unified access point to a resource or service that’s shared across an app, such as an audio channel to play sound effects or a network manager to make HTTP requests.

Importing Objective-C into Swift - To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app. 

Migration - Migration methodology
Provides an opportunity to revisit an existing Objective-C app and improve its architecture, logic, and performance by replacing pieces of it in Swift. For a straightforward, incremental migration of an app, you’ll be using the tools learned earlier—mix and match plus interoperability. Mix-and-match functionality makes it easy to choose which features and functionality to implement in Swift, and which to leave in Objective-C. Interoperability makes it possible to integrate those features back into Objective-C code with no hassle. Use these tools to explore Swift’s extensive functionality and integrate it back into your existing Objective-C app without having to rewrite the entire app in Swift at once

NSUserDefaults - Migration methodology 

class NSUserDefaults : NSObject
Description   
The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default.



Friday, July 24, 2015

WG Tutorial draft - ArcGIS Vector Layers

ESRI's ArcGIS platform has a huge number of datasets, as well as the ability to generate your own thru the ArcGIS application.  Here are a few examples of what we're going to build today.


You’ll need a sample project for this tutorial. Go back and start with the Hello Earth tutorial and work thru the CartoDB Tutorial.  We’ll want the tiling logic from that tutorial.  If you'd rather just get started with those files, you can download them here;
HelloEarth
OK to summarize, in this app we're are going to utilize remote datasets from ESRI's (that's the Environmental Systems Research Institute, I just finally learned) ArcGIS website.  ArcGIS is the premier GIS application out there, and it's used by everyone.  Check it out, join, whatever, but you'll have to do it on your own time.

In this app, we are going to load one of their great base maps a National Geographic globe found here.
And as a second act we are going to access one of their vector data sets showing New York City's flood zones found here.

As mentioned above, we're not going to get into much of the details of ArcGIS or how the Hello Earth vector tiling works, that's detailed elsewhere.  So, let's get setup.  I changed the CartoDB files to ArcGISLayer, and it's associated method to addVectors, just to be pedantic about it.  Run the app and you should get the CartoDB view of NYC's landlords or whatever.  If not, make it so.

ArcGIS Base Map - National Geographic World Map
So first thing we're going to load up one of ArcGIS's base maps, the beautiful & revered National Geographic World Map.  All we have to do change the URL reference in the existing code & the new map should appear, as if by magic.  Find where that's done in viewDidLoad, and replace the URL string with this URL;
http://services.arcgisonline.com/arcgis/rest/services/NatGeo_World_Map/MapServer

code chunk to find;
         // Portions Courtesy NASA/JPL­Caltech and U.S. Depart. of Agriculture, Farm Service Agency
        MaplyRemoteTileSource *tileSource =  [[MaplyRemoteTileSource alloc]
             initWithBaseURL:@"http://services.arcgisonline.com/arcgis/rest/services/                                 NatGeo_World_Map/MapServ/tile/{z}/{y}/{x}"
             ext:@"png" minZoom:0 maxZoom:maxZoom];

you also need to adjust the maxZoom value (in this case - 17) and make sure the ext:file is png.  The /tile/{z}/{y}/{x} appended to the end of the URL is a specific requirement of ??Whatever??

Run the app, zoom way out, and you should get a great rendition of everyone's favorite Nat Geo globe.  Easy Peasey!

Next up - Vector Layers
Vector layers are datasets that return polygons, attributes and other things.  The mechanics of how WhirlyGlobe handles this data is thoroughly detailed in the CartoDB tutorial, and you should review that there if you like.  Here today we are simply going to replace the CartoDB data with data from ArcGIS, specifically showing the various different flood zones in the NYC area.  We'll also make a few other changes to make the displayed data pop!  Here goes;

As discussed, we have created a CartoDBLayer object that conforms to the MaplyPagingDelegate.  This object then queries the remote data source for the data required by the tiles displayed with the method startFetchForTile:forLayer:.  This query is comprised of 2 portions, a URL for the remote server, and a SQL query that are joined together in the constructRequest method.  Let's start by changing the URL to -
http://services.arcgis.com/OfH668nDRN7tbJh0/ArcGIS/rest/services/NYCEvacZones2013/FeatureServer
in the CartoDBLayer constructRequest code

code chunk to find;
- (NSURLRequest *)constructRequest:(MaplyBoundingBox)bbox
{
    // construct a query string
    double toDeg = 180/M_PI;
    NSString *query = [NSString stringWithFormat:search,bbox.ll.x*toDeg,bbox.ll.y*toDeg,bbox.ur.x*toDeg,bbox.ur.y*toDeg];
    NSString *encodeQuery = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    encodeQuery = [encodeQuery stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
    NSString *fullUrl = [NSString stringWithFormat:@"https://pluto.cartodb.com/api/v2/sql?format=GeoJSON&q=%@",encodeQuery];
    NSURLRequest *urlReq = [NSURLRequest requestWithURL:[NSURL URLWithString:fullUrl]];
   
    return urlReq;
}

A we'll also need to change the query in the VController's addBuildings method

code chunk to find;
- (void)addBuildings
{
    NSString *search = @"WHERE=Zone>=1&f=pgeojson&outSR=4326";
    // NSString *search = @"SELECT the_geom,address,ownername,numfloors FROM mn_mappluto_13v1 WHERE the_geom && ST_SetSRID(ST_MakeBox2D(ST_Point(%f, %f), ST_Point(%f, %f)), 4326) LIMIT 2000;";
   
    CartoDBLayer *cartoLayer = [[CartoDBLayer alloc] initWithSearch:search];
    cartoLayer.minZoom = 13;
    cartoLayer.maxZoom = 15;

outSR is the ouptpu spacial reference, and pgeojson also defines the output format.
Run the project, and you should see the layers for the flood zones.  Not?  OK, lets adjust a few things to see what's going on;
  • Change the mni/maxZoom levels = 9 to 13
  • Modify the initial zoom level to 0.008
  • query for a single zone>=4
  • Also let's add in a NSLog statement to see if data is being returned
code chunk to find;
    [NSURLConnection sendAsynchronousRequest:urlReq queue:opQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
    {
        NSLog(@"returned data length is %lu", (unsigned long)data.length);

Run the project again, and you should see some data displayed.  It's not exactly what we want, but at least we know we're receiving data, Yay!  Now lets clean up this bad boy.

Through the magic of files fiddling, we finally end up with -
Tweaking the app to make it look Good!
Very pretty.

Here are the various completed files for your programming pleasure;
  • ViewController.m
  • ArcGISLayer.h
  • ArcGISLayer.m

Wednesday, December 26, 2012

Critical knowledge resources

Let's identify & catalog useful technologies for our professional development.  Also this can act as a central access point for learning about them and gaining expertise.

ESRI ArcGIS - This is the premier GIS application in the market today.  It's the AutoCAD of Geographical Information System software suites.  Their online program ArcGIS Online is a great introduction.
 PHP - Personal Home Page is a scripting language used for creating website ..............
  • Tutorials - 
  • examples - 
  • Overview -

 Xcode - Development SDK for Apple's mobile and desktop platforms ..............
  • Tutorials - 
  • examples - 
  • Overview -
  SQL - Structured Query Language are widely used database for the web & mobiles computing.  Apple's version is called SQLite, and provides a very compact (single file) database ..............
  • Tutorials - 
  • examples - 
  • Overview -
 .NET - Microsoft's C# SDK   ..............
  • Tutorials - 
  • examples - 
  • Overview -