This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createLayer(baseView: MaplyBaseViewController) -> (MaplyQuadImageTilesLayer) { | |
let precipTileSource = MaplyMultiplexTileSource(sources: tileSources) | |
// Create a precipitation layer that animates | |
let precipLayer = MaplyQuadImageTilesLayer(tileSource: precipTileSource!) | |
precipLayer?.imageDepth = UInt32(tileSources.count) | |
precipLayer?.animationPeriod = 1.0 | |
precipLayer?.imageFormat = MaplyQuadImageFormat.ImageUByteRed | |
precipLayer?.numSimultaneousFetches = 4 | |
precipLayer?.handleEdges = false | |
precipLayer?.coverPoles = false | |
precipLayer?.shaderProgramName = WeatherShader.setupWeatherShader(baseView) | |
precipLayer?.fade = 0.5 | |
return precipLayer! | |
} |
Why Swift?
I'm not the audience for Swift. My favorite language is a mixture of C++ and Objective-C. You get STL containers, blocks, and ARC. It's awesome. Why are you backing away? Let me tell you more!
This is why I work with other humans. José was quite interested in Swift and did the bulk of the work.
Swift Interfaces & Documentation
The main issue was Swift bindings for all the various methods. Swift can interface to Objective-C just fine, but if you want to make it pleasant, it should look like this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @brief Interpolate a new state between the given states A and B. | |
@details This does a simple interpolation (lat/lon, not great circle) between the two animation states. | |
*/ | |
+ (nonnull WhirlyGlobeViewControllerAnimationState *)Interpolate:(double)t from:(WhirlyGlobeViewControllerAnimationState *__nonnull)stateA to:(WhirlyGlobeViewControllerAnimationState *__nonnull)stateB; |
![]() |
Feel the learning! |
The tutorials have tabs for Objective-C and Swift!
Swift Tests
In the new AutoTester app (post forthcoming) José wrote a bunch of Swift test cases. These have a pleasing rhythm to them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func insertClusteredMarkers(compB : NSArray, theBaseView: MaplyBaseViewController) { | |
let size = CGSizeMake(32, 32) | |
let image = UIImage (named: "alcohol-shop-24@2x") | |
var markers = [MaplyScreenMarker]() | |
for object in compB { | |
let marker = MaplyScreenMarker() | |
marker.image = image | |
marker.loc = (object as! MaplyVectorObject).center() | |
marker.size = size | |
marker.userObject = object.userObject | |
markers.append(marker) | |
} | |
theBaseView.addScreenMarkers(markers, desc: [kMaplyClusterGroup: 0], mode: MaplyThreadMode.Current) | |
} |
Swift-ly into the Future
We're getting user submitted github Issues in Swift now. Not about Swift mind you, just in Swift. So that seems to be working.
As Apple changes the language we'll keep up and I think a few new WhirlyGlobe-Maply apps may be written in Swift.
No comments:
Post a Comment