<分区> 分区>
我完全是 swift 和 ios 编程的初学者 我通过观看由 swift 1 和 xcode 6 beta 编写的编码类(class)视频遇到了一个问题。 我知道 swift 的版本发生了变化,语法也发生了很大的变化。 我已经解决了一些问题,但仍然有一个我无法处理。 那是“调用中缺少参数标签”
以下是我的代码:
import UIKit
import CoreLocation
class ViewController: UIViewController,CLLocationManagerDelegate {
let locationManger:CLLocationManager = CLLocationManager()
@IBOutlet weak var location: UILabel!
@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var temperature: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManger.delegate = self
locationManger.desiredAccuracy = kCLLocationAccuracyBest
if(ios10()) {
locationManger.requestWhenInUseAuthorization()
}
locationManger.startUpdatingLocation()
}
func ios10() ->Bool {
return UIDevice.current.systemVersion == "10.2"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
let location:CLLocation = locations[locations.count-1] as CLLocation
if(location.horizontalAccuracy > 0) {
print(location.coordinate.latitude)
print(location.coordinate.longitude)
self.updateWeatherInfo(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude)
locationManger.stopUpdatingLocation()
}
}
func updateWeatherInfo(latitude:CLLocationDegrees,longitude:CLLocationDegrees){
let manager = AFHTTPRequestOperationManager()
let url = "http://api.openweathermap.org/data/2.5/weather?APPID=c5a8f49ee6e86f1aaa2be178f25f37f2"
let params = ["lat":latitude,"lon":longitude,"cnt":0]
manager.get(url,
parameters: params,
success: { (operation:AFHTTPRequestOperation!, responseObject: Any!) in
print("JSON:" + (responseObject as AnyObject).description!)
updateUISuccess(responseObject as! NSDictionary!)
//that's where my error1 :missing argument label 'jsonResult' in call
}
)
}
func updateUISuccess(jsonResult:NSDictionary){
if let tempResult = (jsonResult["main"] as? [String:Double])?["type"] {
//if let tempResult = (jsonResult["main"] as? [String:Double])?["type"] current
//if let tempResult = jsonResult["main"]?["temp"]? as? Double pre
var temperature:Double
if ((jsonResult["sys"] as? [String:String])?["country"] == "US"){
//CONVERT TO FAHRENHEIT IF USER IN US
temperature = round(((temperature - 273.15) * 1.8) + 32)
}
else{
//CONVERT TO CELSIUS
temperature = round(temperature - 273.15)
}
self.temperature.text = "\(temperature)°"
print(temperature)
var name = jsonResult["name"] as! String
self.location.text = "\(name)"
var conditionArray = (jsonResult["weather"] as! NSArray)[0] as! NSDictionary
var condition = conditionArray["id"] as! Int
var sunrise = (jsonResult["sys"] as? [String:Double])?["sunrise"]
var sunset = (jsonResult["sys"] as? [String:Double])?["sunset"]
var nightTime = false
var now = NSDate().timeIntervalSince1970
if (now < sunrise! || now > sunset!) {
nightTime = true
}
//self.icon.image = UIImage(named:"sunny")
updateWeatherIcon(condition,nightTime: nightTime)
//that's where my error2 :missing argument label 'condition:' in call
}
else {
print("error!")
}
}
func updateWeatherIcon(condition: Int,nightTime: Bool){
//thunderstorm
if(condition < 300) {
if nightTime {
self.icon.image = UIImage(named:"tstorm1_night")
}
else {
self.icon.image = UIImage(named:"tstorm1")
}
}
//drizzle
else if (condition < 500) {
}
//rain
else if (condition < 600) {
}
//snow
else if (condition < 700) {
}
//fog
else if (condition < 771) {
if nightTime {
self.icon.image = UIImage(named: "fog_night")
}
else {
self.icon.image = UIImage(named: "fog")
}
}
//tornado
else if (condition < 800) {
self.icon.image = UIImage(named:"tstorm3")
}
//clear
else if (condition == 800) {
if nightTime {
self.icon.image = UIImage(named:"sunny_night")
}
else {
self.icon.image = UIImage(named:"sunny")
}
}
//few clouds
else if (condition < 804) {
if nightTime {
self.icon.image = UIImage(named:"cloudy2_night")
}
else {
self.icon.image = UIImage(named:"cloudy2")
}
}
//overcast
else if (condition == 804) {
self.icon.image = UIImage(named:"overcast")
}
//extreme
else if ((condition >= 900 && condition < 903) || (condition >= 904 && condition < 1000)){
self.icon.image = UIImage(named:"tstorm3")
}
//cold
else if (condition == 903) {
self.icon.image = UIImage(named:"snow5")
}
//hot
else if (condition == 904) {
self.icon.image = UIImage(named:"sunny")
}
//dont know
else {
self.icon.image = UIImage(named:"dono")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){
print(error)
}
}
我想知道怎么解决 非常感谢!
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121