我尝试存储对象数组NSUserDefaults.
我有以下代码片段:
var accounts = MyAccounts()
var array:Array<MyAccounts.MyCalendar> = accounts.populateFromCalendars()
NSUserDefaults.standardUserDefaults().
setObject(array, forKey: "test_storeAccounts_array") // <- get error here
NSUserDefaults.standardUserDefaults().synchronize()
Run Code Online (Sandbox Code Playgroud)
但是我得到了例外:
does not implement methodSignatureForSelector: -- trouble ahead
Run Code Online (Sandbox Code Playgroud)
我的班级结构:
class MyAccounts {
/* ... */
class MyCalendar {
var title:String?
var identifier:String?
var email:String?
var calType:String?
var isActive:Bool?
var isMainAcount:Bool?
init(){}
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有控制器'reportCtrl'和HTML代表6个表数据,只有几行我一次显示.
app.js
var appReport = angular.module('myAppReport', []);
appReport.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/showreport', {templateUrl: 'app/reports/reportsView.html', controller: 'reportCtrl'});
$routeProvider.when('/showreport/:type', {templateUrl: 'app/reports/reportsView.html', controller: 'reportCtrl'});
Run Code Online (Sandbox Code Playgroud)
每个表都有一个单击按钮,应该在浏览器中打开带有扩展表的新选项卡:
scope.onClick = function(path){
var real_path = $location.path() + '/' + path + '/';
$location.path( real_path );
// $window.open($location.path()); // doesn't work
};
Run Code Online (Sandbox Code Playgroud)
例如,我有根视图URL:
http://dev.test.com/reports/date/#/showreport
Run Code Online (Sandbox Code Playgroud)
现在,按下按钮后我想创建:
http://dev.test.com/reports/date/#/showreport/table_name
Run Code Online (Sandbox Code Playgroud)
并在新标签中打开它.如你所见,我试过$window.open($location.path());但它不起作用,没有任何反应.
谢谢,
我有方法:
func getByEmail(email:String) -> MeeterAccount{
for acct in accountsList {
if acct.getEmail().equalsIgnoreCase(email) {
return acct;
}
}
return nil; // here I get an error: type 'MeeterAccount' does not conform to protocol NilliteralConvertible
}
Run Code Online (Sandbox Code Playgroud)
如何摆脱这个错误?
我想写下这样的东西:
func getByEmail(email:String) -> MeeterAccount{
var out:MeeterAccount!
for acct in accountsList {
if acct.getEmail().equalsIgnoreCase(email) {
out = acct
}
}
return out;
}
Run Code Online (Sandbox Code Playgroud)
这不会引发此错误.听起来像Swift让我只写第二种方式.
为什么我不能回来nil?
到目前为止我在控制器中:
$scope.currentPage = 0;
Run Code Online (Sandbox Code Playgroud)
现在,在控制器中没有任何额外的代码(方法)我想0.4在图像 上设置不透明度currentPage ==0
所以我写道:
<div ng-controller="ctrlRead">
<div class="pagination no-margin ">
<ul>
<li ng-class="{disabled: currentPage == 0}">
<a href=""
ng-class="{disabled: currentPage == 0}">
<i class="icon-fast-backward"
ng-style="{opacity : (currentPage == 0)?'0.4':'1'}">
</i>
</a>
</li>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
Unexpected next character at columns 29-29 [?] in expression [{opacity : (currentPage == 0)?'0.4':'1'}]
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
谢谢,
[编辑]
我可以写 ng-style="myOpacity"
在控制器中:
$scope.myOpacity = {
'opacity': ($scope.currentPage == 0)?0.4:1
};
Run Code Online (Sandbox Code Playgroud)
但它需要控制器中的其他代码
我不是iOS开发人员,但开始学习Swift.
我尝试将一些逻辑从Android项目转换为iOS
我有以下方法:
func addGroupItemSample(sample : WmGroupItemSample){ // some custom class
var seconds: NSTimeInterval = NSDate().timeIntervalSince1970
var cuttDate:Double = seconds*1000;
var sampleDate: UInt64 = sample.getStartDate(); // <-- problematic place
if(sampleDate > cuttDate){
// ....
}
}
Run Code Online (Sandbox Code Playgroud)
从上面的方法,您可以看到sample.getStartDate()返回类型UInt64.
我认为它long在Java中是这样的:System.currentTimeMillis()
但当前时间以毫秒为单位定义为Double.
是混合的正确方法Double,UInt64还是我只需要代表所有毫秒Double?
谢谢,
我有md-autocomplete:
<md-autocomplete
md-min-length="1"
ng-enter="presEnter();"
md-no-cache="true"
md-selected-item="selectedItem"
md-search-text="searchText"
md-items="item in querySearch(searchText)"
md-item-text="item.name"
placeholder="Search for a vegetable">
<span md-highlight-text="searchText">{{item.name}} :: {{item.type}}</span>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)
与指令:ng-enter.
我的目标:当用户按下时Enter我想隐藏md-autocomplete-suggestions下拉列表
我从HTML中知道我需要以某种方式调用:$mdAutocompleteCtrl.hidden = true;但不知道如何$mdAutocompleteCtrl在Controller中使用.
我用Google搜索并发现:
$timeout( function() { $scope.$$childHead.$mdAutocompleteCtrl.hidden = true; },100);
Run Code Online (Sandbox Code Playgroud)
但没有$mdAutocompleteCtrl(至少在我的JS中,只在HTML中,我不知道它的范围)
我玩这个例子:输入'a'并在下拉列表后按Enter键.
有任何想法吗?
我将moment对象定义为:
var moment = require('moment');
moment('2015-12-20T12:00:00+02:00');
Run Code Online (Sandbox Code Playgroud)
当我打印它时,我得到:
_d: Sun Dec 20 2015 12:00:00 GMT+0200 (EET)
_f: "YYYY-MM-DDTHH:mm:ssZ"
_i: "2015-12-20T12:00:00+02:00"
_isAMomentObject: true
_isUTC: false
_locale: r
_pf: Object
_tzm: 120
Run Code Online (Sandbox Code Playgroud)
如何以正确的方式获取_tzm?(假设其以分钟为单位的偏移量)
谢谢,
我为iOS编写SDK,我想验证是否StoreKit.framework链接到使用我的SDK的应用程序,所以我运行:
if ([SKStoreProductViewController class]) {
SKStoreProductViewController *storeController =
[[ SKStoreProductViewController alloc ] init ];
// ...
}
Run Code Online (Sandbox Code Playgroud)
但即使StoreKit.framework没有链接[SKStoreProductViewController class仍然返回true.
如何解决这个问题呢?
编辑1
因为@ x4h1d指出我创建了新的空项目并添加到默认的Controller:
BOOL isStoreKitAvailable =
(NSClassFromString(@"SKStoreProductViewController") != nil);
// => YES (there is no linked frameworks at all, why I get YES?)
Run Code Online (Sandbox Code Playgroud)
编辑2
我的配置文件已In-App Purchase启用(不是项目本身)
来自iOS App ID:
但是来自Xcode:
也许这就是为什么即使是空应用程序内置 StoreKit也是如此?
我想知道为什么xCode 6 Beta的管理器不包含"设备"标签?
无论如何,xCode显示设备已连接.

谢谢,
我在Java中使用了特定的逻辑HashSet<String>.集合集仅包含唯一项.
例如:
Set<String> mySets = new HashSet<String>();
mySets.add("a");
mySets.add("a");
mySets.add("b");
mySets.add("a");
Run Code Online (Sandbox Code Playgroud)
我明白了:["a","b"].
什么是Swift中的等效集合?
谢谢,