小编Meh*_*met的帖子

Swift:删除所有数组元素

我试图用这样的for循环删除所有数组元素:

for index 1...myArray.count {
   myArray.removeAtIndex(index)
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我在bulding之前得到这个错误:

预期';' 在'for'声明中

ios swift

97
推荐指数
5
解决办法
7万
查看次数

用prepareForSegue Swift传递对象

我试图用prepareForSegue()将对象传递给另一个场景

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using [segue destinationViewController].
        var nextScene =  segue.destinationViewController as! VehicleDetailsTableViewController

        // Pass the selected object to the new view controller.
        if let indexPath = self.tableView.indexPathForSelectedRow() {
            let selectedVehicle = vehicles[indexPath.row]
            nextScene.currentVehicle = selectedVehicle
        }
    }
Run Code Online (Sandbox Code Playgroud)

而且我有currentVehicle对象来捕获这些对象.但是,当我尝试运行时,它会破坏并获得有关向下转换的错误.

错误编辑

无法将"XXX.DisplayViewController"类型的值(0x1082dcd80)转换为"XXX.VehicleDetailsTableViewController"(0x1082dc9a0).(LLDB)

xcode storyboard ios uistoryboard swift

19
推荐指数
2
解决办法
4万
查看次数

在Swift中使用Alamofire处理XML数据

我开始在当前的ios项目中使用cocoapods.我需要使用SOAP以简单的方式为我的ios项目获取内容.我用Google搜索了它,Alamofire pod对我来说很棒.因为我使用的是Swift编程语言.

我很容易看到这个吊舱.但我的Web服务返回XML结果.我想序列化来排列这个XML结果.但我不能.

当我用浏览器调用我的Web服务时,我得到了这种结果

在此输入图像描述

Alamofire响应方法是这样的:

Alamofire.request(.GET, "http://my-web-service-domain.com", parameters: nil)
         .response { (request, response, data, error) in
                     println(request)
                     println(response)
                     println(error)
                   }
Run Code Online (Sandbox Code Playgroud)

当我运行此方法时,我在终端上看到此输出:

<NSMutableURLRequest: 0x170010a30> { URL: http://my-web-service-domain.com }
Optional(<NSHTTPURLResponse: 0x1704276c0> { URL: http://my-web-service-domain.com } { status code: 200, headers {
    "Cache-Control" = "private, max-age=0";
    "Content-Length" = 1020;
    "Content-Type" = "text/xml; charset=utf-8";
    Date = "Thu, 18 Jun 2015 10:57:07 GMT";
    Server = "Microsoft-IIS/7.5";
    "X-AspNet-Version" = "2.0.50727";
    "X-Powered-By" = "ASP.NET";
} })
nil
Run Code Online (Sandbox Code Playgroud)

我想得到一个数组的结果,在浏览器上看到我的故事板.任何人都可以帮助我如何使用Alamofire框架或Swift语言序列化这些数据?

xml ios swift alamofire

18
推荐指数
3
解决办法
2万
查看次数

SWIFT:如何为NSDate对象添加小时数

我从string生成一个NSDate对象.

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = NSTimeZone(abbreviation: "GMT")
let stringToDate = dateFormatter.dateFromString(dateFromService) // 2015-07-20 12:00:43 +0000
Run Code Online (Sandbox Code Playgroud)

我从网络服务器获取此字符串值.我需要修改个人设备时区.想要添加这个stringToDate对象的小时但不起作用

var addHours : Int = 2 // 2 hours will be added
var newDate = stringToDate.dateByAddingTimeInterval(addHours)
Run Code Online (Sandbox Code Playgroud)

nsdate ios swift

7
推荐指数
2
解决办法
1万
查看次数

如何在ubuntu 12.04上启动rails server localhost:3000

我是铁轨上的红宝石的初学者.

我在官方网页上做了一切.(http://rubyonrails.org/download)

我尝试启动新项目,但localhost doest无法在ubuntu 12.04上运行.

我使用这些命令:

rails new /home/mehmet/Desktop/test/
Run Code Online (Sandbox Code Playgroud)

这是控制台输出:

create  
  create  README.rdoc
  create  Rakefile
  create  config.ru
  create  .gitignore
  create  Gemfile
  create  app
  create  app/assets/images/rails.png
  create  app/assets/javascripts/application.js
  create  app/assets/stylesheets/application.css
  create  app/controllers/application_controller.rb
  create  app/helpers/application_helper.rb
  create  app/mailers
  create  app/models
  create  app/views/layouts/application.html.erb
  create  app/mailers/.gitkeep
  create  app/models/.gitkeep
  create  config
  create  config/routes.rb
  create  config/application.rb
  create  config/environment.rb
  create  config/environments
  create  config/environments/development.rb
  create  config/environments/production.rb
  create  config/environments/test.rb
  create  config/initializers
  create  config/initializers/backtrace_silencers.rb
  create  config/initializers/inflections.rb
  create  config/initializers/mime_types.rb
  create  config/initializers/secret_token.rb
  create  config/initializers/session_store.rb
  create  config/initializers/wrap_parameters.rb
  create  config/locales
  create  config/locales/en.yml
  create  config/boot.rb
  create …
Run Code Online (Sandbox Code Playgroud)

ruby linux ubuntu command ruby-on-rails

6
推荐指数
1
解决办法
2万
查看次数

如何在扩展 ListActivity 的 Activity 中使用 onCreateOptionsMenu()

我的 android 应用项目有问题。

我有一个 MainActivity 如下:

public class MainActivity extends ListActivity {

    private NotesDataSource datasource;
    List<NoteItem> notesList;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        datasource = new NotesDataSource(this);

        refreshDisplay();
    }

    private void refreshDisplay() {
        notesList = datasource.findAll();
        ArrayAdapter<NoteItem> adapter = new ArrayAdapter<NoteItem>(this, R.layout.list_item_layout, notesList);
        setListAdapter(adapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }


}
Run Code Online (Sandbox Code Playgroud)

而且我还有一个 menu_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" …
Run Code Online (Sandbox Code Playgroud)

java xml android android-studio

5
推荐指数
1
解决办法
2万
查看次数

如何使用可选参数创建构造函数?

我有__construct($参数)

public function __construct($nick) {
    $query = "SELECT * FROM Users WHERE nick='".$nick."'";
    $result = App::runQuery($query);
    $user = $result->fetch_object();

    $this->id = $user->id;
    $this->nick = $user->nick;
    $this->email = $user->email;
    $this->password = $user->password;
    $this->birthDay = $user->birthDay;
    $this->sex = $user->sex;
    $this->about = $user->about;
    $this->city = $user->city;
    $this->photo = $user->photo;
    $this->following = $user->following;
    $this->followers = $user->followers;
    $this->statu = $user->statu; 

}
Run Code Online (Sandbox Code Playgroud)

现在我想要一个没有这样参数的默认构造函数:

public function __construct() {

    $this->id = NULL;
    $this->nick = NULL;
    $this->email = NULL;
    $this->password = NULL;
    $this->birthDay = NULL;
    $this->sex = NULL;
    $this->about …
Run Code Online (Sandbox Code Playgroud)

php oop function

5
推荐指数
2
解决办法
1万
查看次数

如何使用PHAR在MAMP中配置PHPUnit

我想测试我的PHP代码,我决定使用PHPUnit进行测试.

我已经按照官方文档的步骤

 $ wget https://phar.phpunit.de/phpunit.phar
 $ chmod +x phpunit.phar
 $ sudo mv phpunit.phar /usr/local/bin/phpunit
 $ phpunit --version
 PHPUnit x.y.z by Sebastian Bergmann and contributors.
Run Code Online (Sandbox Code Playgroud)

但是我在MacOS X上使用MAMP.

所以我不确定如何在MAMP中实现PHAR文件.

通常,文档告诉在终端中使用此注释:

sudo mv phpunit.phar /usr/local/bin/phpunit
Run Code Online (Sandbox Code Playgroud)

我的PHP位置是:

/Applications/MAMP/bin/php/php5.2.17/bin/
Run Code Online (Sandbox Code Playgroud)

我试过运行这个评论:

sudo mv phpunit.phar /Applications/MAMP/bin/php/php5.2.17/bin/
Run Code Online (Sandbox Code Playgroud)

我不知道在这一步应该怎么做.请看一下,因为它不起作用.

php phpunit unit-testing

4
推荐指数
1
解决办法
2439
查看次数

Swift:MapKit自定义图像注释

在我的应用程序中,我有一个不同颜色的mapkit和注释.但是,只有三种颜色选项(红色,绿色,紫色).所以,我需要使用自定义图像更改注释.

我按照本教程创建了mapview

现在,我有一个艺术作品课:

import Foundation
import MapKit

class Artwork: NSObject, MKAnnotation {
    let title: String
    let locationName: String
    let color: String
    let coordinate: CLLocationCoordinate2D

    init(title: String, locationName: String, color: String, coordinate: CLLocationCoordinate2D) {
        self.title = title
        self.locationName = locationName
        self.color = color
        self.coordinate = coordinate

        super.init()
    }

    var subtitle: String {
        return locationName
    }

    // pinColor for disciplines: Sculpture, Plaque, Mural, Monument, other
    func pinColor() -> MKPinAnnotationColor  {
        switch color {
        case "Red":
            return .Red
        case "Purple":
            return …
Run Code Online (Sandbox Code Playgroud)

mapkit ios swift

3
推荐指数
1
解决办法
3714
查看次数