将我们的代码库转换为Swift 3,我遇到了这个问题:
ABAddressBookRequestAccessWithCompletion(addressBookRef) { (granted: Bool, error: CFError?) in
DispatchQueue.main.async {
if let nsError = error as NSError {
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
编译器错误是:
Cannot convert value of type 'CFError?' to type 'NSError' in coercion
改为:
if let nsError = error as? NSError { ... }
Run Code Online (Sandbox Code Playgroud)
发出警告: Cast from 'CFError?' to unrelated type 'NSError' always fails
这是我添加 set 的地方users。每个user都有一个userID和一个socketID:
socket.on('login', function(userID){
console.log('io.sockets.on -- socket.on -- userID: ' + userID);
console.log('socket.id = ' + socket.id);
var user = userID;
// add first user
redis.sadd("users", user);
redis.hmset(user, "socketID", socket.id, "userID", userID);
});
Run Code Online (Sandbox Code Playgroud)
这是我尝试检索users集合中的所有内容并循环遍历它们的地方:
// Get the list of online users and show Presence
redis.smembers("users", function(err,results) {
var onlineUsers = results;
console.log("onlineUsers = " + onlineUsers);
for (var onlineUser in onlineUsers) {
console.log("onlineUser = " + onlineUser);
var userID …Run Code Online (Sandbox Code Playgroud) 网上有几个Vine观众有像官方网站一样的频道列表:

2 - 另一个:

据我所知,仍然没有正式的Vine API.但是,有这种非官方的方式来获取Feed:
http://khakimov.com/blog/2013/03/12/vines-undocumented-api/
它适用于popular和tags,但没有端点channels.该bottlr.co通道按照官方vine.co渠道准确,但http://seenive.com/渠道没有.
我尝试使用上面链接的无名API中的标签端点,例如.https://api.vineapp.com/timelines/tags/comedy,但它与官方频道不匹配,它只是拉动最新的标记媒体.我假设频道被策划并且想要那个饲料.
我试着https://api.vineapp.com/timelines/channels/comedy猜测但没有运气.
我没有试过刮vine.co,这可能是什么bottlr.com,但我宁愿不这样做.
有什么建议?
我正在开发一个语言学习应用程序.所以我有一个NSMutableDictionary'字'作为键.这些键的对象嵌套NSDictionaries了键'frequency'和'count'.NSNumbers是'频率'和'计数'的对象.
这是初始化代码:
NSString* path = [[NSBundle mainBundle] pathForResource:@"french_top_50000"
ofType:@"txt"];
NSString *fh = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
self.userWordlist = [[NSMutableDictionary alloc] init];
for (NSString *word in fh) {
NSArray *keyArray = [[NSArray alloc] initWithObjects:@"frequency", @"count", nil];
NSArray *objectArray = [[NSArray alloc] initWithObjects:frequency, count, nil];
NSDictionary *detailsDict = [[NSDictionary alloc] initWithObjects:objectArray forKeys:keyArray];
[self.userWordlist setObject:detailsDict forKey:word];
}
Run Code Online (Sandbox Code Playgroud)
我在表格中显示此列表的一部分,我想按"频率"排序,它是内部键之一.我无法弄清楚如何做到这一点.
如果第一个想法是"你为什么把它存储在嵌套字典中?",我希望这些单词成为键,因为在应用程序的其他部分我经常搜索一个单词是否在NSMutableDictionary中.
我想要一个带有以下键的扁平字典:'word','frequency','count'......但我必须枚举以检查是否包含单词.
如果对更好的数据结构策略有任何建议,我很乐意听到它们.我将非常频繁地检查是否包含"单词",并且不经常会根据"频率"或"计数"进行排序.
我已经看到了很多与此相似的问题,但它们都是针对平面词典的.
我正在尝试调整帧数.我有两个常量定义为浮点数 - viewTotalHeightExpanded和viewTotalHeight.我正在减去这两个differenceY.
CGFloat differenceY = viewTotalHeightExpanded - viewTotalHeight;
NSLog(@"viewTotalHeightExpanded = %f", viewTotalHeightExpanded);
NSLog(@"viewTotalHeight = %f", viewTotalHeight);
NSLog(@"differenceY = %f", differenceY);
Run Code Online (Sandbox Code Playgroud)
日志显示:
2013-08-24 12:30:48.305 WS[25737:c07] viewTotalHeightExpanded = 406.000000
2013-08-24 12:30:48.305 WS[25737:c07] viewTotalHeight = 366.000000
2013-08-24 12:30:48.306 WS[25737:c07] differenceY = 680.000000
Run Code Online (Sandbox Code Playgroud)
为什么differenceY不是40?
编辑
这是怎么viewTotalHeight和viewTotalHeightExpanded定义:
#define likeBarHeight 20.0f
#define viewTotalHeight likeBarY+likeBarHeight+sortBarHeight
Run Code Online (Sandbox Code Playgroud)
所有其他链式常量如likeBarY和sortBarHeight被定义为类似的浮点数likeBarHeight.
我正在更改一些预先编写的代码,视频时间标签的格式如下:
return [NSString stringWithFormat:@"%2d:%0.2d", minutes, seconds];
Run Code Online (Sandbox Code Playgroud)
发生的情况是,如果minutes是单个数字,它会在它之前返回一个空格,例如4:494 之前有一个空格。如果参数是 2 位数字minutes,但只有 1 个字符,如何格式化以使字符串中有 2 个字符如果minutes是1位数字?
objective-c ×3
ios ×1
node-redis ×1
node.js ×1
nsdictionary ×1
nsstring ×1
redis ×1
sorting ×1
swift ×1
swift3 ×1
vine ×1
xcode ×1