我试图将一个内部有一些字典的数组保存到plist文件中,但它失败了.我没有得到任何错误.我在代码中使用另一个数组执行完全相同的几行,并且可以工作..我无法弄清楚为什么它不保存文件.
这是我保存文件的地方:(参见下面的一些调试器输出)
// When built parse through dictionary and save to file
for ( NSString *keys in [dicByCountry allKeys] )
{
NSArray *arrr = [[NSArray alloc] initWithArray:[dicByCountry objectForKey:keys]];
NSString *fname = [self filePath:[NSString stringWithFormat:@"regions.cid%@.plist",keys]];
if (![arrr writeToFile:fname atomically:YES])
NSLog(@"Could not write file regions.cid%@.plist",keys);
}
Run Code Online (Sandbox Code Playgroud)
这里有一些GDB输出
(gdb) po fname
/Users/chris/Library/Application Support/iPhone Simulator/4.0/Applications/44A9FF9E-5715-4BF0-9BE2-525883281420/Documents/regions.cid0.plist
(gdb) po arrr
<__NSArrayI 0x8022b30>(
{
countryID = "<null>";
region = "?\U00e2vora";
regionID = 16;
},
{
countryID = "<null>";
region = Vicenza;
regionID = 14;
},
{
countryID …Run Code Online (Sandbox Code Playgroud) 我如何检查特定的NSString是否是NSArray中的presnet?
我有一个包含内容的数组.像往常一样,它包含20个对象.我希望在Tableview中将相同的数组拆分为2个部分.我试图用当前数组中的NSMake实现它.例如,我需要在第一个tableview部分获取3行,第二个将包含所有其余的(17行).
switch (section) {
case 0:
return
[[array subarrayWithRange:NSMakeRange(3, 8)] count];
// in this line, it always takes from the first object in array, despite I told hime start from 3 (If I understand right, how to works NSMakeRange)
break;
case 1:
return
[[array subarrayWithRange:NSMakeRange(9, 19)] count];
// here my app is crashing with an error
//*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray subarrayWithRange:]: range {9, 19} extends beyond bounds [0 .. 19]'
default:
break;
} …Run Code Online (Sandbox Code Playgroud) 现在和XCode一起玩了大约2个星期,并且稍微阅读了MVC.我试图将模型连接到控制器时遇到问题,因为我发现很难理解数组.当我用Java编程时,我可以处理简单的数组但是我很安静地被NSArrays我看到的Obj-C吓倒了.
如果有人能够如此友善地向我展示一些对象的简单调用,那么我将永远感激不尽.
我的模特:
Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *name;
NSNumber *age;
}
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSNumber *age;
@end
Run Code Online (Sandbox Code Playgroud)
Person.m
#import "Person.h"
@implementation Person
@synthesize name;
@synthesize age;
@end
Run Code Online (Sandbox Code Playgroud)
在我尝试学习的过程中,我保持非常简单.
现在我的Controller类.我想要做的是创建一个包含40个"人物"对象的数组.但我不知道将其放入Obj C的代码中的正确方法.
或者Controller.h
#import <Foundation/Foundation.h>
@class Person;
@interface Controller : NSObject
{
Person *person;
}
@property(nonatomic, retain) Person *person;
-(void) doSomeWork;
@end
Run Code Online (Sandbox Code Playgroud)
Controller.m或者
#import "Controller.h"
#import "Person.h"
@implementation Controller
@synthesize person;
-(IBAction)doSomeWork
{
// I guess here is where i should create …Run Code Online (Sandbox Code Playgroud) ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *tempPeoples=[[NSMutableArray alloc]init];
for(int i=0;i<nPeople;i++){
ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i);
[tempPeoples addObject:i1];
// [peoples addObject:i1];
}// end of the for loop
peoples=[tempPeoples copy];
Run Code Online (Sandbox Code Playgroud)
此代码提供异常b/c我想将NSMutableArray转换为NSArray请帮助
我正在从Java切换到Objective-c,我遇到了一些困难.我没有取得太大成功就找到了这个问题.
我有一个存储NSMutableArrays的NSMutableArray.如何向阵列添加数组?
我已经搜索了stackoverflow和其他资源,找不到答案.
有什么方法的NSArray之间的差异objectAtIndexedSubscript和objectAtIndex?
或者,如果没有差异,为什么两者都存在?
在Apple Docs中,它说它们"相同".
我是编程的新手,但如果他们是相同的,那是不是打破了DRY原则?显然,Apple的人都知道他们在做什么,但为什么如果他们是相同的话他们都提供了?或者更好的问题是,我为什么要使用另一个呢?
最近我使用数组工作很多,我很奇怪......这两行之间的差异是什么.
NSArray *array = [NSArray arrayWithArray:someArray];
Run Code Online (Sandbox Code Playgroud)
和
NSArray *array = [someArray copy];
Run Code Online (Sandbox Code Playgroud)
哪个更快?我们有什么NSMutableArray和mutableCopy?
我已经看过两个与我相似的问题,但这些问题的答案对我不起作用.我有一个旧项目,其中包含在一组方括号内手动输入的国家/地区列表.
我可以在我的pickerView中轻松使用它,但我想知道是否有更有效的方法来做到这一点?
我将使用UIPickerView中的国家/地区列表.
nsarray ×10
objective-c ×7
cocoa-touch ×3
ios ×3
iphone ×3
xcode ×2
arrays ×1
cocoa ×1
copy ×1
file ×1
nslocale ×1
nsrange ×1
nsstring ×1
properties ×1
retain ×1
swift ×1
uipickerview ×1