user3032488
user3032488

Reputation: 23

How would I translate this Swift to Obj-C?

This is probably simple enough, but Im not a regular iOS dev but have a decent understanding of Obj-C and Xcode however not so much with Swift yet.

I am playing around with a mapping SDK called Skobbler and downloaded both Swift and iOS examples. The Swift example gives me some useful text/console logs of directions turn by turn however the Obj-C doesn't and having a tough time exposing them.

The Swift example looks like this

let advices: Array<SKRouteAdvice> =  SKRoutingService.sharedInstance().routeAdviceListWithDistanceFormat(SKDistanceFormat.Metric) as! Array<SKRouteAdvice>
    for advice: SKRouteAdvice in advices
    {
       let instructions = advice.adviceInstruction
       print(instructions)
    }

Upvotes: 1

Views: 95

Answers (3)

vaibby
vaibby

Reputation: 1265

NSArray *advices = [[SKRoutingService sharedInstance]routeAdviceListWithDistanceFormat:SKDistanceFormat.Metric];
for (SKRouteAdvice *advice in advices) {
NSLog(@"%@", [advice adviceInstruction]);
}

Upvotes: 2

Luca D&#39;Alberti
Luca D&#39;Alberti

Reputation: 4849

NSArray<SKRouteAdvice *> *advices = [[SKRoutingService sharedInstance] routeAdviceListWIthDistanceFormat:SKDistanceFormat.Metric];

for (SKRouteAdvice *advice in advices)
{
    NSLog(@"%@", instructions);
}

Upvotes: 2

gnasher729
gnasher729

Reputation: 52566

as! doesn't need translating - the compiler will just believe you (you might want to add an assert for identical behaviour). The print is replaced with NSLog (@"%@", instructions).

Upvotes: 1

Related Questions