将自定义对象保存到NSUserDefaults中[重复](Save custom objects into NSUserDefaults [duplicate])
这个问题在这里已经有了答案:
我有一个新闻
ViewController
和一个TeamViewController
。TeamViewController
包含一个teamView的tableView,它在被选中时被添加到数组中。 我想将此数组添加到NSUserDefaults
以便我可以从NewsController
访问它们,其中包含需要teamObjects的url请求。 不过,我不断收到:'尝试插入非属性列表对象(“”)
我打开其他建议,如果有更好的方法比存储在
NSUserDefaults
didSelectRowAtIndexPath
方法override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.deselectRowAtIndexPath(indexPath, animated: true) let team = self.teamArray[indexPath.row] as Team var removed = false for (index, value) in enumerate(self.teamSelected) { if (value == team) { self.teamSelected.removeAtIndex(index) removed = true } } if (!removed) { self.teamSelected.append(team) } var userDefaults = NSUserDefaults.standardUserDefaults() userDefaults.setValue(self.teamSelected, forKey: "teams") userDefaults.synchronize() tableView.reloadData() }
我的对象
class Team: NSObject{ var id: Int! var name: NSString! var shortname: NSString! init(id: Int, name:NSString, shortname: NSString) { self.id = id self.name = name self.shortname = shortname } }
This question already has an answer here:
I'm having a news
ViewController
and aTeamViewController
. TheTeamViewController
contain a tableView of teamObjects which when selected is added into array. I want to add this array intoNSUserDefaults
so i can access them from theNewsController
which contain a url request where the teamObjects is needed. However i keep getting:'Attempt to insert non-property list object ( "" ) for key teams'
I'm open for other suggestions if there is better ways than storing it in
NSUserDefaults
didSelectRowAtIndexPath
methodoverride func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.deselectRowAtIndexPath(indexPath, animated: true) let team = self.teamArray[indexPath.row] as Team var removed = false for (index, value) in enumerate(self.teamSelected) { if (value == team) { self.teamSelected.removeAtIndex(index) removed = true } } if (!removed) { self.teamSelected.append(team) } var userDefaults = NSUserDefaults.standardUserDefaults() userDefaults.setValue(self.teamSelected, forKey: "teams") userDefaults.synchronize() tableView.reloadData() }
My object
class Team: NSObject{ var id: Int! var name: NSString! var shortname: NSString! init(id: Int, name:NSString, shortname: NSString) { self.id = id self.name = name self.shortname = shortname } }
原文:https://stackoverflow.com/questions/29986957
最满意答案
laravel 部署到万网的虚拟主机上: 改变一下Laravel的文件目录结构,为应用选择低位的加密方式,就可以在万网云虚拟主机上成功运行。 拿laravel5.1来说: 在根目录下创建一个local文件夹,把网站根目录下除了public文件夹以外所有文件及文件夹复制到local文件夹中 然后把public文件夹下的所有文件复制到网站根目录,接着删除public文件夹,这样入口就变成根目录而不是public了 打开根目录下的index.php(之前/public/index.php) 将 require __DIR__.'/../bootstrap/autoload.php'; 修改为 require __DIR__.'/local/bootstrap/autoload.php'; 将 $app = require_once __DIR__.'/../bootstrap/app.php'; 修改为 $app = require_once __DIR__.'/local/bootstrap/app.php'; 打开/local/config/app.php(之前的/config/app.php) 将 'key' => env('APP_KEY', 'SomeRandomString'), 'cipher' => 'AES-256-CBC', 改为 'key' => env('APP_KEY', '1234567890qwerty'), 'cipher' => 'AES-128-CBC', 其中key使用长度为16的随机字符串,由于万网不支持'AES-256-CBC'所以用128位加密就可以了,128用16个随机字符串做key,256用32个。 上传到万网虚拟主机,然后再后台把PHP版本改成5.5就可以了,妥妥的就运行成功laravel了。
其他回答
laravel 部署到万网的虚拟主机上: 改变一下laravel的文件目录结构,为应用选择低位的加密方式,就可以在万网云虚拟主机上成功运行。 拿laravel5.1来说: 在根目录下创建一个local文件夹,把网站根目录下除了public文件夹以外所有文件及文件夹复制到local文件夹中 然后把public文件夹下的所有文件复制到网站根目录,接着删除public文件夹,这样入口就变成根目录而不是public了 打开根目录下的index.php(之前/public/index.php) 将 require __dir__.'/../bootstrap/autoload.php'; 修改为 require __dir__.'/local/bootstrap/autoload.php'; 将 $app = require_once __dir__.'/../bootstrap/app.php'; 修改为 $app = require_once __dir__.'/local/bootstrap/app.php'; 打开/local/config/app.php(之前的/config/app.php) 将 'key' => env('app_key', 'somerandomstring'), 'cipher' => 'aes-256-cbc', 改为 'key' => env('app_key', '1234567890qwerty'), 'cipher' => 'aes-128-cbc', 其中key使用长度为16的随机字符串,由于万网不支持'aes-256-cbc'所以用128位加密就可以了,128用16个随机字符串做key,256用32个。 上传到万网虚拟主机,然后再后台把php版本改成5.5就可以了,妥妥的就运行成功laravel了。
相关问答
更多-
有人部署过 Laravel 吗[2022-03-11]
我的部署方式: 本地和线上都是nginx,先配好rewrite规则(就是把.htaccess里面的规则原样翻译到nginx.conf里面去) 服务器上,我是直接导SQL, 毕竟我还不习惯用php命令去创建数据库,当然了,这个见仁见智了,laravel的迁移功能是很强大的,在同步本地... -
有人部署过 Laravel 吗[2024-01-20]
laravel 部署到万网的虚拟主机上: 改变一下Laravel的文件目录结构,为应用选择低位的加密方式,就可以在万网云虚拟主机上成功运行。 拿laravel5.1来说: 在根目录下创建一个local文件夹,把网站根目录下除了public文件夹以外所有文件及文件夹复制到local文件夹中 然后把public文件夹下的所有文件复制到网站根目录,接着删除public文件夹,这样入口就变成根目录而不是public了 打开根目录下的index.php(之前/public/index.php) 将 require _ ... -
需要关于laravel资源的帮助(Need help on laravel resource)[2021-09-27]
由于您将集合传递给资源,因此无法直接访问Modal的属性。 相反,对于资源实例,您将获得一个Collection,让您可以访问收集方法 。 所以你可以改变你的资源toArray() public function toArray($request) { return $this->pluck('word_name')->keyBy(function ($item) { return 'word'; }); } Since you are passing a collec ... -
因此,我们可以使用Doctrine将Data Mapper模式实现到Laravel中; Packagist: https ://packagist.org/packages/atrauzzi/laravel-doctrine Laravel Doc: http ://bundles.laravel.com/bundle/doctrine So, we can implement the Data Mapper pattern into Laravel using Doctrine; Packagist: h ...
-
我的典型清单: 将文档根目录修改为/ public文件夹 使/storage和bootstrap/cache文件夹可写。 设置数据库 修改.env文件以适应实时环境 运行php artisan migrate 这应该让你启动并运行,或者至少让你的错误足够详细以解决问题 My typical checklist: Modify the document root to the /public folder Make the /storage and bootstrap/cache folders writea ...
-
Laravel项目部署(Laravel project deploy)[2022-11-07]
如果是,那么是共享主机吗?那么: 将公共(L5)的内容直接放在public_html上(注意不要意外覆盖.htaccess文件),然后修改你的index.php和你的bootstrap.php,它会工作得很好 Is it a shared hosting you're using if yes then : Put the content of public (L5) directly on public_html (be aware of don't overwrite the .htaccess fil ... -
无法运行laravel 4(unable to run laravel 4)[2023-12-14]
我再看看我的文件夹结构,我注意到作曲家没有正确运行并且丢失了文件。 我已重新安装它,它似乎正在工作。 I had another look at my folder structure and I noticed that composer had not run correctly and there were missing files. I've reinstalled it and it appears to be working. -
为什么使用npm和laravel?(Why use npm with laravel?)[2021-11-19]
我做了那个样板。 该命令特定于下载Laravel Elixir软件包的依赖项( http://laravel.com/docs/5.0/elixir )但是除此之外还有许多用途。 Elixir文档很好地解释了它。 I made that boilerplate. That command is specific to download the dependencies for the Laravel Elixir package (http://laravel.com/docs/5.0/elixir) Bu ... -
在laravel上的贝宝(Paypal on laravel)[2021-11-03]
$ _ClientId和$ _ClientSecret对应。 您需要创建具有正确ID和密码的应用程序 ,这通过https://developer.paypal.com完成。创建应用程序后,您将在应用程序详细信息中找到这些信息。 编辑 使用相同的库和Laravel查看本教程视频 ,大约3:20的人正在显示您需要做什么。 $_ClientId and $_ClientSecret correspond to. You need to create your application to have right i ... -
在共享主机上你不能运行artisan命令,你不能享受共享主机上的所有laravel功能,你需要vps或专用服务器,在共享主机上你需要做很多手工工作,比如旧的php网站上传和数据库更新,如果您想在共享主机上上载laravel项目,请按照以下步骤进行操作。 在托管根目录上创建一个目录名框架,并从本地目录上除了公共目录之外的所有内容。 从主机上www目录中的公共目录上传所有内容。 现在修改你的index.php文件 转到index.php并编辑第22行 #From this require __DIR__.'/. ...