我有两个文件定义协议,用于实现观察者模式,我从其中一个获得编译器错误.
// ObserverDelegate.h
#import <Foundation/Foundation.h>
@protocol ObserverDelegate <NSObject>
@required
@end
// ObservableDelegate.h
#import <Foundation/Foundation.h>
#import "ObserverDelegate.h"
@protocol ObservableDelegate <NSObject>
@required
-(void) addObserver: (ObservableDelegate*) observer; // ERROR ON THIS LINE WHEN COMPILE
@end
Run Code Online (Sandbox Code Playgroud)
我只有.h文件,ObserverDelegate并ObservableDelegate没有相应的.m文件.
该错误在ObserveableDelegate.h中显示"预期的类型" -(void) addObserver: (ObservableDelegate*) observer;
我创建了一个UIImageView允许异步加载图像的类别:
@implementation UIImageView (ImageLoader)
- (void) asyncLoadImageIntoView:(NSURL *)imageURL withLoadingIndicator:(BOOL)isLoadingIndicator {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:imageURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"didReceiveData %@", data);
(void)[self.image initWithData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
//[textView setString:@"Unable to fetch data"];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeeded! Received image data");
}
@end
Run Code Online (Sandbox Code Playgroud)
我的问题是,即使connection:didReceiveData:调用该方法并将数据打印到控制台,[self.image initWithData:data]似乎也没有将图像加载到视图中.这里有什么问题?
以iOS App Store上的两个应用程序为例:"Witness"和"Witness Remote".但是,如果你同时下载它们,你会注意到它们实际上都只在iPhone上命名为"Witness".
因此,当Apple说应用程序名称必须是唯一的时,他们只讨论商店中出现的应用程序名称,而不是在设备上安装时的实际名称吗?
我有一个本地化NSString的东西,比如"你赢了.这是查克诺里斯.".法语翻译是"Gagne.il s'agissait bien de Chuck Norris".但当名字以元音开头时,应该说"Gagné.ils'agissait bien d'Alfred Hitchcock".
是否NSString为这些情况提供支持,还是我需要手动翻译每种可能性?
我需要做一个必须在主线程上发生的一系列可能的调用(因为否则UIKit会讨厌)."长"是指在iPad 3上每次持续运行10,000次.
显然,立即循环遍历所有这些可能不是最好的主意.
我不知道如何在主线程上执行所有这些,同时留下足够的呼吸空间来保持UIKit响应并且看门狗睡着了(即不会因为占用运行循环而终止).
有人有想法吗?我将瞄准iOS 5.
具体来说,我正在尝试做的是缓存UITextPositions,因为a UITextView显然采用非缓存的迭代方法来获取UITextPositions,这意味着它非常非常慢positionFromPosition:textview.beginningOfDocument offset:600011,但获取速度要快得多positionFromPosition:aPositionAt600000 offset:11.事实上,在我的测试案例中,前者需要超过100秒(在主线程上!),而后者几乎是瞬时的.
当我这样做时,我得到了错误的值
NSLog(@"cos 90 is %.f", cos(90.0));
Run Code Online (Sandbox Code Playgroud)
我得到的答案是-0.当我进行谷歌搜索时,这就是我得到的:
cos(90弧度)= - 0.448073616.
然而,我的卡西欧计算器给我的答案是0,而且当我小时候长大的时候,cos 90 = 0我的脑子就钻了进去.
谁是对的,是ObjC,谷歌还是我的卡西欧计算器?
我正在尝试构建一个安全应用程序,提示用户在允许访问应用程序之前输入密码.这是在第一次启动时或应用程序恢复时完成的.
现在,我正在使用一个视图控制器,PasscodeViewController它在应用程序启动或恢复时以模态方式呈现,即在应用程序委托中:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (!self.passcodeViewController.view.window)
[self.window.rootViewController presentViewController:self.passcodeViewController animated:NO completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
问题是主视图控制器的视图在PasscodeViewController呈现之前暂时闪烁.这是一种安全风险,因为用户可以在被要求输入密码之前快速查看数据.
你是如何解决这个问题的?DotLockData等程序和其他安全程序如何实现这样的功能?
我想一次启动多个线程,所以我使用了以下代码.
我很困惑我是否应该创建一个队列并在其中放入许多操作,或者通过单个操作创建多个队列.
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
for(int INDEX = 0; INDEX < 5; INDEX++) {
dispatch_async(queue, ^{
/*some code*/
});
}
Run Code Online (Sandbox Code Playgroud)
for(int INDEX = 0; INDEX < 5; INDEX++) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
/*some code*/
});
}
Run Code Online (Sandbox Code Playgroud)
哪个是最佳的?另外,GCD中的线程数是否有限制?
我可以NSString轻松创建一个常规:
NSString *string = @"string value"; // Case 1
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
NSMutableString *mutableString = @"mutableString value"; // Case 2
Run Code Online (Sandbox Code Playgroud) 我知道你可以注释掉一整段代码,如下所示:
/*
line of code
line of code
line of code
*/
Run Code Online (Sandbox Code Playgroud)
但是如果你在试图评论的代码中已经有一个/*...*/部分,则注释块的*/end将关闭我试图创建的"更大"注释块.
例:
/* wanting to comment this big section out
line of code
line of code
line of code
line of code
line of code
line of code
/* this section was already commented out before
line of code
line of code
line of code
*/ this section was already commented out before
line of code
line of code
line of code
line of code
line of code …Run Code Online (Sandbox Code Playgroud) objective-c ×8
cocoa-touch ×3
cocoa ×2
ios ×2
app-store ×1
comments ×1
localization ×1
math ×1
nsstring ×1
protocols ×1
trigonometry ×1
uikit ×1
uitextview ×1
xcode ×1