batoulapps / Adhan

High precision prayer time library
MIT License
331 stars 63 forks source link

How to view data on simulator #32

Closed sabrefm1-zz closed 7 years ago

sabrefm1-zz commented 7 years ago

I am using the swift version of this app. It works without issues but the results are displated in the xcode output menu. see below link.

http://i191.photobucket.com/albums/z219/fawaazm/output_zps62vpc6cm.png

How do I set this up in xcode to display the output data prayer times in a tableview or textview or imageview.

this is my code below

import UIKit import Adhan

class ViewController: UIViewController, UIAlertViewDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

    let cal = Calendar(identifier: Calendar.Identifier.gregorian)
    let date = cal.dateComponents([.year, .month, .day], from: Date())
    let coordinates = Coordinates(latitude: 33.9249, longitude: 18.4241) //cape town
    var params = CalculationMethod.moonsightingCommittee.params
    params.madhab = .shafi
    if let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params) {
        let formatter = DateFormatter()
        formatter.timeStyle = .medium
        formatter.timeZone = TimeZone(identifier: "Etc/GMT-2")!

        print("Fajr", formatter.string(from: prayers.fajr))

// NSLog("Sunrise %@", formatter.string(from: prayers.sunrise)) print("Thur", formatter.string(from: prayers.dhuhr)) print("Asr", formatter.string(from: prayers.asr)) print("Maghrib", formatter.string(from: prayers.maghrib)) print("Eshaai", formatter.string(from: prayers.isha))

}

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.

}

}

z3bi commented 7 years ago

That's because the sample app is just showing how to get the times from the framework. How you choose to display those times is completely up to you. Here is a good tutorial on using a tableview https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson7.html

sabrefm1-zz commented 7 years ago

would i need the code above and then implement it for tableview. sorry I am new to xcode so not sure where to start

z3bi commented 7 years ago

@sabrefm1 yes, instead of printing the string to the console you would assign it as the text of a label.

myLabel.text = formatter.string(from: prayers.asr)