我有NSMutableArray一些其中有一些NSDecimalNumber,比如(500,50.80,70,8000)
现在我想把所有这些加decimal numbers在一起.
我试过用
for (NSDecimalNumber *number in self.numbersArray)
{
NSDecimal *sum += [number decimalValue]
}
Run Code Online (Sandbox Code Playgroud)
但失败了.
这是我想要解决的另一个非常具体的问题.
我正在列出一个列在用户设置应用程序中的Twitter用户帐户的列表.这将以正确的顺序返回一个包含用户名的数组.
然后我将此数组传递给此twitter API:
https://api.twitter.com/1.1/users/lookup.json
Run Code Online (Sandbox Code Playgroud)
返回的数组包含我登录的每个用户帐户所需的所有附加数据.第一个数组包含NSStrings(用户名),返回的数组已被解析为包含具有用户名,名称和配置文件pic的键和值的字典.
现在的问题是订单与我传递的第一个数组完全不同.这是Twitter的预期行为,但它需要完全相同的顺序(我将引用AccountStore的原始索引,它将匹配第一个数组,但不是新的字典数组).
如何告诉新数组与包含的字典匹配与基于用户名密钥的第一个数组的顺序相同?
我知道这听起来很混乱,所以让我至少发布数据来帮助.
这是第一个数组输出:
(
kbegeman,
indeedyes,
soiownabusiness,
iphonedev4me
)
Run Code Online (Sandbox Code Playgroud)
这是第二个数组输出的内容:
(
{
image = "https://si0.twimg.com/profile_images/3518542448/3d2862eee546894a6b0600713a8de862_normal.jpeg";
name = "Kyle Begeman";
"screen_name" = kbegeman;
},
{
image = "https://si0.twimg.com/profile_images/481537542/image_normal.jpg";
name = "Jane Doe";
"screen_name" = iPhoneDev4Me;
},
{
image = "https://twimg0-a.akamaihd.net/profile_images/378800000139973355/787498ff5a80a5f45e234b79005f56b5_normal.jpeg";
name = "John Doe";
"screen_name" = indeedyes;
},
{
image = "https://si0.twimg.com/sticky/default_profile_images/default_profile_5_normal.png";
name = "Brad Pitt";
"screen_name" = soiownabusiness;
}
)
Run Code Online (Sandbox Code Playgroud)
由于Twitter返回数据的方式,它永远不是完全相同的顺序,所以每次调用这些方法时我都必须检查它.
任何帮助都会很棒,会挽救我的夜晚.提前致谢!
如何以相反的顺序在数组中订购这些值?
_gradientArrayToWhite = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", nil];
Run Code Online (Sandbox Code Playgroud) 在一个方法中,我需要读取一个NSArray或NSDictionary一个plist文件.
这是我的问题:当我不知道它是否是数组或字典时,如何从文件创建NSArrayOR ?NSDictionaryplist
我知道我可以做:
NSArray *myArray = [NSArray arrayWithContentsOfFile:filePath];
Run Code Online (Sandbox Code Playgroud)
要么
NSDictionary *myDico = [NSDictionary dictionaryWithContentsOfFile:filePath];
Run Code Online (Sandbox Code Playgroud)
但我不知道filePath是否包含a NSArray或a NSDictionary.我想要像:
id myObject = [... ...WithContentOfFile:filePath];
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我并给我最好的方法吗?
我有一个数组包含每个索引的数组.
array is :(
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-19g1.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-20g2.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-20g3.jpg"
),
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-49y1.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y2.jpg"
),
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg"
)
)
Run Code Online (Sandbox Code Playgroud)
我想制作一个类似的数组
(
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-50y3.jpg",
"http://localhost/ColorPicker/upload/2014-01-14-04-01-51y6.jpg"
)
Run Code Online (Sandbox Code Playgroud)
如何在数组中消除(),()并创建包含url的单个数组.
NSPredicate *predicate = [NSPredicate
predicateWithFormat:@"todo_category_id IN %@"
argumentArray:array];
Run Code Online (Sandbox Code Playgroud)
todo_category_id是一个NSNumber-type属性.
array仅包含3个也是NSNumber类型对象的元素.
我想根据这些ID从Core Data中获取类别.
我目前正在学习Objective-C.我正在学习的这本书给了我一个挑战,我给了两个数组,我应该创建一个程序来显示两个数组中列出的对象.
我已经把一切都搞定了,我唯一坚持的部分就是比较两个阵列并返回两者中出现的内容.它们都是很长的列表,我的所有尝试最终都没有显示出任何内容或崩溃.
任何有关如何做到这一点的帮助都会很棒.
编辑:这是我到目前为止所做的...我不能完全给出我之前尝试过的例子,因为我会使用像isEqualToString:,predicateWithFormat:这样的东西,并且在它不起作用之后我会删除代码.
如果我的代码包含明显的错误,我道歉,让我再次提到我是新的.
{@autoreleasepool {
// Read in a file as a huge string (ignoring the possibility of an error)
NSString *nameString =
[NSString stringWithContentsOfFile:@"/usr/share/dict/propernames"
encoding:NSUTF8StringEncoding
error:NULL];
// Read in a file for words
NSString *wordString =
[NSString stringWithContentsOfFile:@"/usr/share/dict/words"
encoding:NSUTF8StringEncoding
error:NULL];
// Break it into an array of strings
NSArray *namesArray = [nameString componentsSeparatedByString:@"\n"];
// Break words into an array of strings
NSArray *wordArray = [wordString componentsSeparatedByString:@"\n"];
// Go through the array one string at a time
for …Run Code Online (Sandbox Code Playgroud) 那么这是我的代码:
NSDictionary *dicto;
NSString *ndccode;
NSString *string=@" ";
for (int i=0; i<array.count; i++) {
dicto=[array objectAtIndex:i];
ndccode=[dicto objectForKey:@"NDCCode"];
string=[string stringByAppendingString:ndccode];
string=[string stringByAppendingString:@"\n"];
NSLog(@"%@",string);
}
NSLog(@"%@",string);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我有dicto nsdictionary中的值,它逐个循环的值并分配给ndccode,这是字符串.然后我添加到字符串,以便我可以将它附加到下一行.
输出:
name1
name2
name3
.....
而不是分配给字符串.我想将它分配给一个数组.请你告诉我如何将它分配给这个例子的数组,因为它是循环的.我想将该数组用于以后的目的.先感谢您.
哦,所以我在这里有很多情况。
案例:1一个NSArray字典,其键的类型为NSString,值的类型也为NSString。isEqualToArray返回false
case:2一个字典的NSArray,其键类型为NSString,某些模型对象的值类型具有name,address,DOB之类的属性。因此,如果我在模型对象(如名称)中更改一个值,并使用相同的键插入字典中。并将数组与旧数组进行比较仍然可以。isEqualToArray返回false
现在这可以继续进行下去。如果我的模型对象中有一个NSArray又是某个模型的原始类型,该怎么办?isEqualToArray是否会比较对象值中的几乎所有内容(如深度序列化比较),还是必须停在某个地方?
大家早上好,
我有一个表视图,显示从2个不同类保存的对象.我将这些结果组合成一个数组,以显示在tableView中.这是我的代码:
import UIKit
import RealmSwift
class BookmarksVC: UIViewController,UITableViewDelegate,UITableViewDataSource {
var articleList: Results<DynamicObject>!
var documentList: Results<DynamicObject>!
var list = [Any]()
var article: Any!
var searchBar:UISearchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 280, height: 20))
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "BookmarkCell", bundle: nil), forCellReuseIdentifier: "bookmarkCell")
tableView.delegate = self
tableView.dataSource = self
drawNavBarUI(navigationItem: self.navigationItem, searchBar: searchBar)
loadDataAndUpdateUI()
}
func loadDataAndUpdateUI() {
articleList = realm.dynamicObjects(NewsArticle.className())
documentList = realm.dynamicObjects(Documents.className())
list.append(articleList)
list.append(documentList)
tableView.setEditing(false, animated: true)
tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
但结果是: …
nsarray ×10
ios ×7
objective-c ×6
nsdictionary ×3
arrays ×2
sorting ×2
append ×1
cocoa-touch ×1
core-data ×1
json ×1
matching ×1
nspredicate ×1
plist ×1
realm ×1
swift3 ×1