假设我的游戏中有以下数据.我用cocos2d开发了游戏.
Name Score
Sagar 10000
Amit 2000
Vishal 90
Run Code Online (Sandbox Code Playgroud)
以上数据存储在plist文件中.
Plist有一个数组作为root.
其中有10个字典.
每个字典都有两个值:
我用的时候
NSMutableArray *x=[[NSMutableArray alloc] initWithContentsOfFile:@"Sagar.plist"];
Run Code Online (Sandbox Code Playgroud)
我想按分数对这个可变数组进行排序.
可能吗?
我正在使用以下行创建一个带有CGRects的NSArray:
[self setMyArray:[NSArray arrayWithObjects:[NSValue valueWithCGRect:CGRectMake(x,y,z,a)], [NSValue valueWithCGRect:CGRectMake(x,y,z,a)], nil]]
Run Code Online (Sandbox Code Playgroud)
然后,我经常尝试更新数组中的CGrects,如下所示:
for (NSValue *bound in myArray)
{
CGRect myRect = [bound CGRectValue];
myRect.origin.y += 2;
}
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,当循环再次运行时,原点仍然相同.我假设这与NSValue包装器有关?,我该怎么做才能在数组中实际更新该值?谢谢.
-Oscar
有人可以帮我一些代码来检查NSArray中的重复项是否有针对性C.我在vb.net做了我想要的但是翻译对我来说很难.
'True means no duplicates'
Public Shared Function checkDuplicate(ByVal list As ArrayList) As [Boolean]
Dim [set] As New HashSet(Of Integer)
For i As Integer = 0 To list.Count - 1
Dim val As Boolean = [set].Add(list(i))
If val = False Then
Return val
End If
Next
Return True
End Function
Run Code Online (Sandbox Code Playgroud) 嘿伙计们,我想知道如何在数组中找到特定类型对象的对象数.例如,我在随机位置的NSMutableArray中有6个'云',我在这个NSMutableArray中也有4个'龙'.
我怎样才能收集整数6?
我正在思考以下问题:
int z = [[SomeClass *clouds in _somearray] count];
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.Thnx,奥利弗.
我只是需要一些帮助来创建一个可以存储多个词典的数组.我有 :
.H
NSArray * projects;
NSDictionary *project1;
NSDictionary * project2;
Run Code Online (Sandbox Code Playgroud)
.M
projects = /* What should I write here to store the
above two dictionaries in my array. */
Run Code Online (Sandbox Code Playgroud)
谢谢,
所以我不断遇到这个崩溃并打破我的代码,但我无法确切地知道它来自哪里.Xcode没有在与此相关的行上中断,我查看了所有的线程堆栈,但没有一个显示中断.这是我得到的:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '***
Collection <CALayerArray: 0x17746b10> was mutated while being enumerated.'
Run Code Online (Sandbox Code Playgroud)
我的问题是,我如何找到这个数组的位置?有没有办法通过地址在Xcode控制台中查找它,以指出我到底发生了什么?我只是通过关注我的代码找不到我会改变某些数组的位置.
我有一个NSArray包含NSDictionary客户数据.我使用的NSPredicate过滤array,并使之通过ViewControllers用segues.我正处于一个阶段,我想改变存储在其中的键的一些值dictionary.这怎么可以实现?
我的prepareForSegue方法
if ([[segue identifier] isEqualToString:@"showClients"]) {
// Detect selected row
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// Extract value from the Clinic_Location attribute
NSString *cString = [[_clinicList valueForKey:@"Clinic_Location"] objectAtIndex:indexPath.row];
NSLog(@"Row pressed: %@", cString);
// Set predicate where Clinic_Location equals the clinic string extracted from the selected row
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Clinic_Location == %@", cString];
// Filter the client array using this predicate
filteredClientArray …Run Code Online (Sandbox Code Playgroud) StackOverflow上已经存在一些类似的问题.我确实检查了它们,并且在大多数情况下它返回nil,因为它NSMutableArray尚未初始化.但在我的情况下,我做了初始化.
这是我的代码的一部分:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.storedTimeZones = [[NSMutableArray alloc] init];
NSData *storedData = [[NSUserDefaults standardUserDefaults] dataForKey:@"timeZones"];
if (storedData != nil ) {
self.storedTimeZones = [NSKeyedUnarchiver unarchiveObjectWithData:storedData];
}
NSString *str = [self.smallRegionArray[indexPath.row] stringByReplacingOccurrencesOfString:@"_" withString:@" "];
[self.storedTimeZones addObject: str];
NSLog(str); //the string was printed successfully.
NSLog(@"%lu", (unsigned long)self.storedTimeZones.count); //'0' was printed
}
Run Code Online (Sandbox Code Playgroud)
更新
@Caleb是对的,[NSKeyedUnarchiver unarchiveObjectWithData:storedData返回零.我解决了这个问题:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.storedTimeZones = [[NSMutableArray alloc] init];
NSData *storedData = [[NSUserDefaults standardUserDefaults] dataForKey:@"timeZones"];
NSMutableArray *ary = …Run Code Online (Sandbox Code Playgroud) 我在这段代码中做错了什么?
为什么我会收到错误?
"类型'NSMutableArray'的值没有成员'追加'"
static func saveUserData()
{
let item:NSDictionary = ["TIME":"12:00","LOCATION":"here"]
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
let filePath = documentsDirectory + "/datafile.dat"
var readArray:NSMutableArray? = NSMutableArray(contentsOfFile: filePath)
if var array = readArray {
print("loaded array - appending..." )
// PROBLEM IS HERE
var damnArray:NSMutableArray = array
damnArray.append(item)
} else {
//
}
}
Run Code Online (Sandbox Code Playgroud) 我有保存以下值的数组:
globalarray_beacon: (
"(01000466)",
"(01000008)",
"(01000003)",
"(01000001)",
"(01000006)",
"(01000004)",
"(01000007)",
"(01000005)",
"(01000469)",
"(01000468)",
"(01000420)",
"(01000002)",
"(01000444)",
"(01000463)",
"(01000468)",
"(01000466)",
"(01000001)",
)
Run Code Online (Sandbox Code Playgroud)
我想将此值转换为以下内容:
globalarray_beacon: (
01000468,
01000004,
01000006,
01000420,
01000444,
01000466,
01000469,
01000003,
01000005,
01000008,
01000001,
01000007,
01000002
)
Run Code Online (Sandbox Code Playgroud)
try1.
NSArray *items = [theString componentsSeparatedByString:@" " "];
Run Code Online (Sandbox Code Playgroud)
try2.
NSString *stringWithoutSpaces = [myString
stringByReplacingOccurrencesOfString:@"()" withString:@""];
Run Code Online (Sandbox Code Playgroud)
try3.
for (int i=0; i<array_lastname.count; i++) {
[array_data addObject:[[array_lastname objectAtIndex:i] componentsSeparatedByString:@"()"]];
}
Run Code Online (Sandbox Code Playgroud)
如何转换数组的值我必须尝试很多东西.如何将字符串值转换为数据.提前致谢.
nsarray ×10
objective-c ×7
ios ×3
iphone ×3
nsdictionary ×2
append ×1
cocoa-touch ×1
crash ×1
enumeration ×1
nspredicate ×1
nsstring ×1
segue ×1
sorting ×1
swift ×1