小编use*_*173的帖子

设置要检索的节点的环境变量

我正在尝试按照教程说它:

"有几种方法可以加载凭据.

  1. 从环境变量加载,
  2. 从磁盘上的JSON文件加载,

密钥需要如下:

USER_ID, USER_KEY
Run Code Online (Sandbox Code Playgroud)

...这意味着如果您正确设置环境变量,则根本不需要在应用程序中管理凭据."

基于一些谷歌搜索,似乎我需要设置变量process.env?我如何以及在何处设置这些凭据?示例请.

environment-variables node.js

386
推荐指数
12
解决办法
58万
查看次数

Sequelize:销毁/删除表中的所有记录

我正在使用Mocha进行单元测试.

测试开始时,我想删除表中的所有先前记录.

我尝试过的:

db.User.destroy({ force: true }).then(() => {
}).then(() => done());


db.User.destroy(
    {where: undefined},
    {truncate: false}
).then(() => {
    return 
}).then(() => done());


db.User.destroy({}).then(() => {
    return db.User.bulkCreate(users)
}).then(() => done());
Run Code Online (Sandbox Code Playgroud)

我一直收到以下错误:

 Error: Missing where or truncate attribute in the options parameter of model.destroy.
Run Code Online (Sandbox Code Playgroud)

如何删除/销毁表中的所有记录?

mysql node.js sequelize.js

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

Swift 4:使用Codable`通用参数'T'无法推断

我收到以下错误:

Generic parameter 'T' could not be inferred

在线: let data = try encoder.encode(obj)

这是代码

import Foundation

struct User: Codable {
    var firstName: String
    var lastName: String
}

let u1 = User(firstName: "Ann", lastName: "A")
let u2 = User(firstName: "Ben", lastName: "B")
let u3 = User(firstName: "Charlie", lastName: "C")
let u4 = User(firstName: "David", lastName: "D")

let a = [u1, u2, u3, u4]

var ret = [[String: Any]]()
for i in 0..<a.count {
        let param = [
            "a" : a[i], …
Run Code Online (Sandbox Code Playgroud)

encoder swift swift4 xcode9 codable

12
推荐指数
1
解决办法
6929
查看次数

摩卡:超出2000毫秒的错误超时

我正在尝试为数据库进行单元测试.

以下是seed.js文件:

.......
const app = require('./app')
const db = app.get('db')

const saveUsersToDB = (done) => {
    db.User.bulkCreate(users)
         .then(() => (done))
}

module.exports = {saveUsersToDB};
Run Code Online (Sandbox Code Playgroud)

我的app.test.js档案:

.......
const expect = require('expect')
const request = require('supertest')
const {saveUsersToDB} = require('./seed/seed');

before(saveUsersToDB)
Run Code Online (Sandbox Code Playgroud)

当我运行下面的测试是我得到的错误:

Express listening on port 3000!
  1) "before all" hook: saveUsersToDB

  0 passing (2s)
  1 failing

  1)  "before all" hook: saveUsersToDB:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if …
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js node.js ecmascript-6 es6-promise

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

iOS:NSPredicate使用NSDate进行比较

我有一个NSDate名为startDate存储在持久性存储中的属性,格式如下(下图).

在此输入图像描述

426174354 = 2014年7月4日

我需要NSFetchRequest使用谓词创建(3).

用于startDate:

  1. fetchRequest1 使用谓词需要根据用户的设备时间获取当前日期的所有内容.
  2. fetchRequest2 使用谓词需要根据用户的设备时间获取过去的所有内容,即昨天和之前的内容.
  3. fetchRequest3 使用谓词需要获取将来的所有内容,即根据用户的设备时间明天和之后开始.

以下是我到目前为止的代码:

-(NSMutableArray *)getFetchPredicate:(NSUInteger)fetchRequestType
{
    NSDate *now = [self getcurrentTime:[NSDate date]];
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    format.dateFormat = @"dd-MM-yyyy";
    format.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSString *stringDate = [format stringFromDate:now];
    NSDate *todaysDate = [format dateFromString:stringDate];
    //today's date is now a date without time. 

    NSMutableArray *subpredicates;

    if (fetchRequestType == 1)
    {
        NSPredicate *subPredToday = [NSPredicate predicateWithFormat:@"startDate == %@ ", todaysDate];
        [subpredicates addObject:subPredToday];
    } …
Run Code Online (Sandbox Code Playgroud)

nsdate nspredicate nsfetchrequest ios ios7

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

SwiftyJSON:将对象转换为JSON

我知道使用SwiftyJSON你可以将对象转换JSONSwift.

SwiftyJSON允许你回去吗?即将NSManagedObjects与关系进行转换并将其转换为JSON?

示例请.

nsmanagedobject swift swifty-json

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

Swift:将参数传递给选择器

使用Swift 3,Xcode 8.2.1

方法:

func moveToNextTextField(tag: Int) {
   print(tag)
}
Run Code Online (Sandbox Code Playgroud)

下面的行编译正常,但tag有一个未初始化的值:

let selector = #selector(moveToNextTextField)
Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: selector, userInfo: nil, repeats: false)
Run Code Online (Sandbox Code Playgroud)

但是,我需要传递一个参数.以下编译无法:

let selector = #selector(moveToNextTextField(tag: 2))

Swift Compile Error:
Argument of #selector does not refer to an @objc method, property, or initializer.
Run Code Online (Sandbox Code Playgroud)

如何将参数传递给选择器?

ios swift3

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

cellForRowAtIndexPath:滚动后UILabel重叠

的cellForRowAtIndexPath:

cell.textLabel.text工作正常.

滚动后UILabel重叠.这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell==nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

        // I have tried it by removing views and without.  No difference.   
        NSArray *viewsToRemove = [self.tableView subviews];
        for (UITableView *table in viewsToRemove)
        {
            [table removeFromSuperview];
        }
    }


    NSManagedObject *managedObject = [newClass objectAtIndex:indexPath.row];
    NSString  *entityName= [[managedObject entity]name];
    cell.textLabel.text = [NSString stringWithFormat:@"%@   %i", entityName, [indexPath row]];
    cell.textLabel.font=[UIFont systemFontOfSize:14.0];


    NSDate *date = [managedObject valueForKey:@"lastmoddate"]; …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview cell-formatting ios

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

iOS8:自定义Swift Framework访问用Objective-C编写的外部框架

我正在尝试CouchbaseKit在Swift中创建一个名为(Xcode中的新目标)的自定义框架.在我的内部CouchbaseKit,我需要访问CouchBaseLite Framework完全用Obj-C编写的内容.我正在使用Cocoapods管理CouchBaseLite和其他几个框架.下面是我的podfile.

Podfile

# Uncomment this line to define a global platform for your project
link_with ['CouchbaseKit']
# platform :ios, '8.0'

use_frameworks!
target 'CouchbaseDB' do
link_with ['CouchbaseKit']

pod 'couchbase-lite-ios'
pod 'SwiftyJSON', '~> 2.2.0'
pod 'Alamofire', '~> 1.2'
pod 'XCGLogger', '~> 2.0'
end

target 'CouchbaseDBTests' do
end

target 'CouchbaseKit' do
end

target 'CouchbaseKitTests' do
end
Run Code Online (Sandbox Code Playgroud)

项目内的Pod:

在此输入图像描述

对于我的TARGETS,我在Build Phases中有以下设置.

定义模块

允许框架模块中的非模块化包含

问题: 当我尝试访问CouchbaseKit(我的自定义框架)中的CouchbaseLite框架时,出现错误,"没有这样的模块'CouchbaseLite'不存在.

在此输入图像描述

尝试:

  1. 由于项目是在Swift中,我创建了一个Objective-C文件并点击是" 你想配置一个Objective-C桥接头吗? …

frameworks couchbase-lite xcode6 ios8

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

iOS9:在Simulator和Device中使用动态框架

我创建了一个动态可可框架,我希望在我的应用程序中使用它.

在为实际设备构建框架之后,我将其带到了应用程序.我只能在该设备上运行该应用程序.

当我尝试在模拟器上运行它时,框架文件无法识别.我收到错误消息: 'ViewController' is unavailable: cannot find swift for declaration for this class

我尝试构建iPhone 6模拟器的框架并在iPhone 6模拟器上运行应用程序,但同样的问题仍然存在.

如何创建/构建一个我可以带入任何应用程序并能够在模拟器和设备上使用它的框架?

ios-frameworks swift ios9 swift2

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