0

So im very new to swift and im building an ios app that requires the date and time to be called from a website( such as http://www.timeanddate.com/worldclock/ or http://24timezones.com/world_directory/current_sydney_time.php). I have read some other posts related to this on stackoverflow but cant really find exactly what im looking for.

If anyone has any knowledge of this, it would be greatly appreciated.

Matt Wyeth
  • 1,124
  • 2
  • 10
  • 19
  • Well the first website does offer an api but it is only free for 3 months. Use this API instead https://developers.google.com/maps/documentation/timezone/intro?hl=en#Requests. What you need to learn is how to use API in your app and then how to specifically use google's api as APIs are different. https://developers.google.com/google-apps/calendar/quickstart/ios?ver=swift. Good luck! – mn1 Nov 24 '15 at 06:22
  • tyvm! i will try tonight! – Matt Wyeth Nov 25 '15 at 05:37

1 Answers1

0

You can get the html page using

    let url = NSURL(string: "http://24timezones.com/world_directory/current_sydney_time.php")
            let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
                print(NSString(data: data!, encoding: NSUTF8StringEncoding))
            }

task.resume()

Parse the HTML data using html parsing libraries such as

  • hpple
  • NDHpple
  • Swift-HTML-Parser

check the link for more details on parsing HTML contents.

Community
  • 1
  • 1
Anni S
  • 1,996
  • 19
  • 28
  • Thanks for the reply, I attempted to follow the steps under Swift-HTML-Parser but when I get to the point of adding 'import Kanna' I get the error 'No such module'. Is there a simpler method than using parse? As its a concept I barely understand . I appreciate your help all the same :) – Matt Wyeth Nov 24 '15 at 11:54