我有一些代码从数组中获取URL并将其存储为字符串然后使用该字符串加载URL.
NSString *first = [urls objectAtIndex:[sender clickedRow]];
NSLog(@"%@", first);
[[webview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first]]];
Run Code Online (Sandbox Code Playgroud)
但是,当我运行这个时,我收到此错误:
-[NSURL length]: unrecognized selector sent to instance 0x164dc0
Run Code Online (Sandbox Code Playgroud)
本案例中的链接是http://www.digg.com
我知道这个bug就行了
NSString *first = [urls objectAtIndex:[sender clickedRow]];
Run Code Online (Sandbox Code Playgroud)
因为我尝试将字符串的值直接设置为URL而不是数组,并且它有效.
我需要创建一个结构数组,例如:
typedef struct
{
int fill;
BOOL busy;
} MapCellST;
Run Code Online (Sandbox Code Playgroud)
如何在NSMutableArray中添加此结构的实例以及如何提取结构的副本并在以后使用其属性?
有许多线程采用相反的方法,但是我有兴趣从原始C数组转换为NSArray。原因是我想从数组内容创建一个NSString。要创建NSString,我将使用:
NSArray *array;
NSString *stringFromArray = [array componentsJoinedByString:@","];
Run Code Online (Sandbox Code Playgroud)
我用逗号连接数组的元素,因为稍后将字符串保存为.csv文件。我认为这并不重要,但是我要处理的C数组的类型为double,大小为43。
double c_array = new double [43];
Run Code Online (Sandbox Code Playgroud)
谢谢!
在objectiveC中给出一个包含字符串的NSArray fred,我可以说:
NSString *s = [fred ObjectAtIndex:5];
Run Code Online (Sandbox Code Playgroud)
什么是c#等价物?罗塞塔石头说要使用这种方法ValueAt但是会返回一个IntPtr.
var i = fred.ValueAt(5);
Run Code Online (Sandbox Code Playgroud)
但是你剩下的就是如何将一个转换IntPtr为NSString指针.
编辑:
我有两个不同的数组与一些重复的字符串,我想创建一个只有唯一字符串的新数组.
例如,取这两个数组:
NSArray *array1 = [[NSArray alloc] initWithObjects:@"a",@"b",@"c",nil];
NSArray *array2 = [[NSArray alloc] initWithObjects:@"a",@"d",@"c",nil];
// Result should be an array with objects "b", and "d"
// since they are the only two that are not repeated in the other array.
Run Code Online (Sandbox Code Playgroud) 试图转换objectAtIndex的返回.
(MyClass *)[myArray objectAtIndex:1].name;
Run Code Online (Sandbox Code Playgroud)
你能在Objective-C中像这样投射内联吗?
我正在使用NSPredicate过滤NSArray并将过滤后的数组用于我的UITableView.当用户在UITextField中输入文本时,我正在使用此过滤.因此,每次UITextField中的文本发生更改时,我都会调用我的过滤器函数.
它看起来像这样:
NSArray *hugeArray = ...;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", input];
_resultArray = [hugeArray filteredArrayUsingPredicate:predicate];
[_myTableView reloadData];
Run Code Online (Sandbox Code Playgroud)
当我使用带有大量对象的NSArray时,输入变得非常慢(UI中的完整输入变慢).是否有可能获得更好的性能或在后台运行已过滤的命令?
不应阻止在UITextField中写入内容.当UITableView在输入后很短的时间后刷新它可能没问题.
我使用NSSet有以下星座:
NSSet {
NSDictionary {
"Unique-Identifier-Key": Unique Value
"Key2": ValueABC
"Key3": ValueDEF
}
NSDictionary {
"Unique-Identifier-Key": Unique Value
"Key2": ValueFGH
"Key3": ValueJKL
}
NSDictionary {
"Unique-Identifier-Key": Unique Value
"Key2": ValueRST
"Key3": ValueXYZ
}
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种通过其唯一值从NSSet中获取一个字典的方法.NSSet中有很多NSDictionaries,因此我正在寻找具有最佳性能的方式.
如何使用(NSSet *)objectsPassingTest:(BOOL (^)(id obj, BOOL *stop))predicate以下方式?
NSString *idSearched = ...;
NSSet *results = [MySet objectsPassingTest:^(id obj,BOOL *stop){
if ([obj valueForKey:@"Unique-Identifier-Key"] == idSearched) return YES;
else return NO;
}];
Run Code Online (Sandbox Code Playgroud)
这是最高性能的解决方案吗?我使用NSSet,因为我读到NSSets比NSArrays有更好的性能来查找对象.而且我不需要有序的对象序列.
我有一个NSArray,其中包含一些重复的对象.我想打印哪些对象正在重复,例如:
NSArray * array = [NSArray arrayWithObjects: A, B, C, A, B];
Run Code Online (Sandbox Code Playgroud)
现在,我想在我的控制台打印A和B这些被复制.
我该怎么做呢?
我有一个NSArray在字符串对象中的名字,如下所示:@[@"john", @"smith", @"alex",
@"louis"],我有另一个包含许多名称的数组.如何检查第一个数组中的所有对象是否在第二个数组中?
nsarray ×10
objective-c ×6
ios ×3
cocoa ×2
cocoa-touch ×2
c ×1
c# ×1
casting ×1
collections ×1
enumeration ×1
ios5 ×1
iphone ×1
nsdictionary ×1
nspredicate ×1
nsset ×1
nsstring ×1
struct ×1
webkit ×1