实际上每种方法的优点/缺点是什么?我之前使用过图形API,它似乎可以在Facebook上做任何我想做的事情.
在iOS 6中我可以这样做:
NSDictionary *d = @{anObject : "key"};
Run Code Online (Sandbox Code Playgroud)
但显然当对象是UIImageView或UIWebView(或者也可能是其他对象)时,它会崩溃:
'NSInvalidArgumentException', reason: '-[UIWebView copyWithZone:]: unrecognized selector sent
Run Code Online (Sandbox Code Playgroud)
将字典声明更改为旧方法有效:
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:anObject,@"key", nil];
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
我有一个同步的函数,但似乎我无法直接更改该块中的实例变量的值.
+(id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [super allocWithZone:zone];
//This is not allowed
something = @"hello";
//This is allowed
self.something = @"hello world!";
return sharedInstance;
}
}
return nil;
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我有一个我需要直接访问的变量(我不想合成该变量).我该如何解决这个问题?
我正在构建某种推特客户端,但是如果在推文中有网络链接,我希望能够在我的应用中显示它而无需跳转到Safari.
有没有开源项目呢?我知道我可以使用UIWebView,但我希望获得所有功能,如后退按钮,前进按钮,刷新,进度条等.
我正在尝试将我的JSON解析为NSDictionary.这是我用于解析的方法.
+ (NSDictionary *)executeGenkFetch:(NSString *)query
{
query = [NSString stringWithFormat:@"%@", query];
query = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"[%@ %@] sent %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), query);
NSData *jsonData = [[NSString stringWithContentsOfURL:[NSURL URLWithString:query] encoding:NSUTF8StringEncoding error:nil] dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *results = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:&error] : nil;
if (error) NSLog(@"[%@ %@] JSON error: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), error.localizedDescription);
NSLog(@"[%@ %@] received %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), results);
return results;
}
Run Code Online (Sandbox Code Playgroud)
以下是我如何使用此功能.
+(NSArray *)getCommentsWithParam:(NSString *)Param
{
NSString *request = [NSString stringWithFormat:@"https://graph.facebook.com/comments/?ids=%@",Param];
NSLog(@"request …Run Code Online (Sandbox Code Playgroud) objective-c ×4
ios ×3
facebook ×1
ios4 ×1
ios6 ×1
iphone ×1
json ×1
nsdictionary ×1
open-source ×1