내 ViewController에 메서드를 추가하여 로컬 인증 프레임 워크를 성공적으로 구현했지만 MVC 패턴을보다 효과적으로 받아들이도록 리팩토링하고 싶습니다. 코드를 NSObject로 옮기고 별도로 호출하고 싶지만 두 가지 문제가 있습니다.클리너 코드 용 로컬 인증 프레임 워크 리팩토링
참고로이 내가 구현하고있어 코드입니다 : https://developer.apple.com/library/ios/documentation/LocalAuthentication/Reference/LocalAuthentication_Framework/
첫 번째 문제는 내가있는 UIButton의 터치를 테스트 할 때 코드가 발사되지 않으며, 두 번째 문제는 내가 performSegueWithIdentifier를 호출 할 것입니다 것입니다 성공했지만 UIViewController를 호출해야합니다. 그래서 내가 처음에 뭘하려 :
^Authenticate.h
@interface Authenticate : NSObject
- (void)startAuthenticating;
Authenticate.m
@implementation Authenticate
- (void)startAuthenticating{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
...
if (success) {
[self performSegueWithIdentifier: @"Success" sender:nil];
...
} ...
}
[자기 performSegue은 ...] 내가 이해하는, 여기에 오류가 발생합니다.
#import "Authenticate.h"
ViewController.h
@interface ViewController : UIViewController
@property(nonatomic, strong) Authenticate *touchID;
ViewController.m
@implementation ViewController
- (void)viewDidLoad{
...
[self.touchID startAuthenticating];
}
나는 또한 Authenticate.h에 #import "ViewController.h"
에 노력하고 @property(nonatomic, weak) ViewController *viewController;
를 추가하고 대신 [self performSegue...]
의 그것은 그가 유지 사이클처럼 보인다하더라도 [self.viewController performSegue...]
되었다.
현재 저는 로컬 인증 프레임 워크를 다른 UIViewController에 구현하여 코드를 리팩터링했으며 해당 AuthenticationViewController 아래에서 주 ViewController를 서브 클래 싱했습니다. 그러나 그 목표는 내가 의도 한 바가 아니기 때문에 속임수 같이 느껴집니다. 누군가가 더 나은 방법으로 이것을 달성하는 방법을 보여줄 수 있습니까?