Run CLANGFORMAT on sample

Summary: This diff runs CLANGFORMAT lint on sample. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT.

Reviewed By: passy

Differential Revision: D19942174

fbshipit-source-id: bef3e67bf31f13bb52417c81c4c330d6c258872d
This commit is contained in:
Pritesh Nandgaonkar
2020-02-17 10:46:43 -08:00
committed by Facebook Github Bot
parent e8b20d5b15
commit 0e4250b4af
9 changed files with 236 additions and 181 deletions

View File

@@ -7,5 +7,5 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate> @interface AppDelegate : UIResponder<UIApplicationDelegate>
@end @end

View File

@@ -7,51 +7,61 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import <FlipperKit/FlipperClient.h> #import <FlipperKit/FlipperClient.h>
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
#import <FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> #import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitLayoutComponentKitSupport/FlipperKitLayoutComponentKitSupport.h>
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> #import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> #import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import "MainViewController.h" #import "MainViewController.h"
#import "RootViewController.h" #import "RootViewController.h"
#if !FB_SONARKIT_ENABLED #if !FB_SONARKIT_ENABLED
#error "Sample need to be run with SonarKit enabled in order to properly interact with Sonar. SonarKit is enabled by default if its a debug build." #error \
"Sample need to be run with SonarKit enabled in order to properly interact with Sonar. SonarKit is enabled by default if its a debug build."
#endif #endif
@implementation AppDelegate { @implementation AppDelegate {
UIWindow *_window; UIWindow* _window;
} }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication*)application
{ didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FlipperClient *client = [FlipperClient sharedClient]; FlipperClient* client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; SKDescriptorMapper* layoutDescriptorMapper =
[FlipperKitLayoutComponentKitSupport setUpWithDescriptorMapper: layoutDescriptorMapper]; [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application [FlipperKitLayoutComponentKitSupport
withDescriptorMapper: layoutDescriptorMapper]]; setUpWithDescriptorMapper:layoutDescriptorMapper];
[client addPlugin:[[FlipperKitLayoutPlugin alloc]
initWithRootNode:application
withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [[FlipperClient sharedClient]
addPlugin:[[FlipperKitNetworkPlugin alloc]
initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client addPlugin:[FlipperKitExamplePlugin sharedInstance]]; [client addPlugin:[FlipperKitExamplePlugin sharedInstance]];
[client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[FlipperKitReactPlugin new]];
[client start]; [client start];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
MainViewController *mainViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; bundle:nil];
MainViewController* mainViewController = [storyboard
instantiateViewControllerWithIdentifier:@"MainViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: mainViewController]; UINavigationController* navigationController = [[UINavigationController alloc]
initWithRootViewController:mainViewController];
navigationController.navigationBar.topItem.title = @"Sample"; navigationController.navigationBar.topItem.title = @"Sample";
navigationController.navigationBar.translucent = NO; navigationController.navigationBar.translucent = NO;
[_window setRootViewController: [[UINavigationController alloc] initWithRootViewController: mainViewController]]; [_window
setRootViewController:[[UINavigationController alloc]
initWithRootViewController:mainViewController]];
[_window makeKeyAndVisible]; [_window makeKeyAndVisible];
NSLog(@"Hello from Flipper in an Objc app!"); NSLog(@"Hello from Flipper in an Objc app!");

View File

@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface CommunicationDemoViewController : UIViewController<UITableViewDataSource> @interface CommunicationDemoViewController
: UIViewController<UITableViewDataSource>
@end @end

View File

@@ -8,49 +8,54 @@
#import "CommunicationDemoViewController.h" #import "CommunicationDemoViewController.h"
#import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h> #import <FlipperKitExamplePlugin/FlipperKitExamplePlugin.h>
@interface CommunicationDemoViewController()<FlipperKitExampleCommunicationResponderDelegate> @interface CommunicationDemoViewController ()<
@property (strong, nonatomic) NSMutableArray<NSString *> *messagesToDisplay; FlipperKitExampleCommunicationResponderDelegate>
@property (weak, nonatomic) IBOutlet UITextField *messageTextField; @property(strong, nonatomic) NSMutableArray<NSString*>* messagesToDisplay;
@property (weak, nonatomic) IBOutlet UITableView *tableView; @property(weak, nonatomic) IBOutlet UITextField* messageTextField;
@property(weak, nonatomic) IBOutlet UITableView* tableView;
@end @end
@implementation CommunicationDemoViewController @implementation CommunicationDemoViewController
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[FlipperKitExamplePlugin sharedInstance].delegate = self; [FlipperKitExamplePlugin sharedInstance].delegate = self;
} }
- (IBAction)tappedTriggerNotification:(UIButton *)sender { - (IBAction)tappedTriggerNotification:(UIButton*)sender {
[[FlipperKitExamplePlugin sharedInstance] triggerNotification]; [[FlipperKitExamplePlugin sharedInstance] triggerNotification];
} }
- (IBAction)tappedSendMessage:(UIButton *)sender { - (IBAction)tappedSendMessage:(UIButton*)sender {
if (self.messageTextField.text.length > 0) { if (self.messageTextField.text.length > 0) {
[[FlipperKitExamplePlugin sharedInstance] sendMessage:self.messageTextField.text]; [[FlipperKitExamplePlugin sharedInstance]
} sendMessage:self.messageTextField.text];
} }
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reusableCell"]; - (nonnull UITableViewCell*)tableView:(nonnull UITableView*)tableView
cell.textLabel.text = self.messagesToDisplay[indexPath.row]; cellForRowAtIndexPath:(nonnull NSIndexPath*)indexPath {
return cell; UITableViewCell* cell =
} [tableView dequeueReusableCellWithIdentifier:@"reusableCell"];
cell.textLabel.text = self.messagesToDisplay[indexPath.row];
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return cell;
return self.messagesToDisplay.count; }
}
- (NSInteger)tableView:(nonnull UITableView*)tableView
- (void)messageReceived:(NSString *)msg { numberOfRowsInSection:(NSInteger)section {
if (msg) { return self.messagesToDisplay.count;
if (!self.messagesToDisplay) { }
self.messagesToDisplay = @[].mutableCopy;
} - (void)messageReceived:(NSString*)msg {
[self.messagesToDisplay addObject:msg]; if (msg) {
dispatch_async(dispatch_get_main_queue(), ^{ if (!self.messagesToDisplay) {
[self.tableView reloadData]; self.messagesToDisplay = @[].mutableCopy;
});
} }
[self.messagesToDisplay addObject:msg];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
} }
@end @end

View File

@@ -7,11 +7,11 @@
#import "MainViewController.h" #import "MainViewController.h"
#import <FlipperKit/FlipperDiagnosticsViewController.h>
#import "CommunicationDemoViewController.h"
#import "NetworkViewController.h" #import "NetworkViewController.h"
#import "RootViewController.h" #import "RootViewController.h"
#import "UserDefaultsViewController.h" #import "UserDefaultsViewController.h"
#import "CommunicationDemoViewController.h"
#import <FlipperKit/FlipperDiagnosticsViewController.h>
@interface MainViewController () @interface MainViewController ()
@@ -20,42 +20,54 @@
@implementation MainViewController @implementation MainViewController
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
} }
- (IBAction)tappedDiagnosticScreen:(UIButton *)sender { - (IBAction)tappedDiagnosticScreen:(UIButton*)sender {
FlipperDiagnosticsViewController *controller = [[FlipperDiagnosticsViewController alloc] init]; FlipperDiagnosticsViewController* controller =
[self.navigationController pushViewController:controller animated:true]; [[FlipperDiagnosticsViewController alloc] init];
[self.navigationController pushViewController:controller animated:true];
} }
- (IBAction)tappedComponentKitLayout:(UIButton *)sender { - (IBAction)tappedComponentKitLayout:(UIButton*)sender {
RootViewController *rootViewController = [RootViewController new]; RootViewController* rootViewController = [RootViewController new];
[self.navigationController pushViewController:rootViewController animated:true]; [self.navigationController pushViewController:rootViewController
animated:true];
} }
- (IBAction)tappedNetworkInspector:(UIButton *)sender { - (IBAction)tappedNetworkInspector:(UIButton*)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
NetworkViewController *networkViewController = [storyboard instantiateViewControllerWithIdentifier:@"NetworkViewController"]; bundle:nil];
NetworkViewController* networkViewController = [storyboard
instantiateViewControllerWithIdentifier:@"NetworkViewController"];
[self.navigationController pushViewController:networkViewController animated:true]; [self.navigationController pushViewController:networkViewController
animated:true];
} }
- (IBAction)tappedUserDefaults:(id)sender { - (IBAction)tappedUserDefaults:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
UserDefaultsViewController *userDefaultsViewController = [storyboard instantiateViewControllerWithIdentifier:@"UserDefaultsViewController"]; bundle:nil];
UserDefaultsViewController* userDefaultsViewController = [storyboard
[self.navigationController pushViewController:userDefaultsViewController animated:true]; instantiateViewControllerWithIdentifier:@"UserDefaultsViewController"];
[self.navigationController pushViewController:userDefaultsViewController
animated:true];
} }
- (IBAction)tappedCommunicationDemo:(UIButton *)sender { - (IBAction)tappedCommunicationDemo:(UIButton*)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil]; UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryBoard"
CommunicationDemoViewController *communicationDemoViewController = [storyboard instantiateViewControllerWithIdentifier:@"CommunicationDemoViewController"]; bundle:nil];
[self.navigationController pushViewController:communicationDemoViewController animated:true]; CommunicationDemoViewController* communicationDemoViewController =
[storyboard instantiateViewControllerWithIdentifier:
@"CommunicationDemoViewController"];
[self.navigationController pushViewController:communicationDemoViewController
animated:true];
} }
- (IBAction)tappedCauseCrash:(UIButton *)sender { - (IBAction)tappedCauseCrash:(UIButton*)sender {
NSArray *arr = @[]; NSArray* arr = @[];
[arr objectAtIndex:10]; [arr objectAtIndex:10];
} }

View File

@@ -18,66 +18,100 @@
self.navigationItem.title = @"Network"; self.navigationItem.title = @"Network";
} }
- (IBAction)tappedGithubLitho:(UIButton *)sender { - (IBAction)tappedGithubLitho:(UIButton*)sender {
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/facebook/litho/master/docs/static/logo.png"] completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) { [[[NSURLSession sharedSession]
if (error && !data) { dataTaskWithURL:
return; [NSURL
} URLWithString:
NSLog(@"Got Image"); @"https://raw.githubusercontent.com/facebook/litho/master/docs/static/logo.png"]
}] resume]; completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable error) {
if (error && !data) {
return;
}
NSLog(@"Got Image");
}] resume];
} }
- (IBAction)tappedPOSTAPI:(UIButton *)sender { - (IBAction)tappedPOSTAPI:(UIButton*)sender {
NSString *post = @"https://demo9512366.mockable.io/FlipperPost"; NSString* post = @"https://demo9512366.mockable.io/FlipperPost";
NSURL *url = [NSURL URLWithString:post]; NSURL* url = [NSURL URLWithString:post];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: url]; NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"]; [urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"Flipper", @"app", NSDictionary* mapData =
@"Its awesome", @"remarks", [[NSDictionary alloc] initWithObjectsAndKeys:@"Flipper",
nil]; @"app",
NSError *error = nil; @"Its awesome",
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error]; @"remarks",
nil];
NSError* error = nil;
NSData* postData = [NSJSONSerialization dataWithJSONObject:mapData
options:0
error:&error];
[urlRequest setHTTPBody:postData]; [urlRequest setHTTPBody:postData];
[urlRequest setHTTPMethod:@"POST"]; [urlRequest setHTTPMethod:@"POST"];
__weak NetworkViewController *weakSelf = self; __weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession] dataTaskWithRequest:urlRequest completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable dataTaskError) { [[[NSURLSession sharedSession]
dataTaskWithRequest:urlRequest
completionHandler:^(
NSData* _Nullable data,
NSURLResponse* _Nullable response,
NSError* _Nullable dataTaskError) {
if (dataTaskError || !data) {
[weakSelf
showAlertWithMessage:@"Received error in POST API response"];
return;
}
NSDictionary* dict =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]);
if (dataTaskError || !data) { [weakSelf showAlertWithMessage:@"Received response from POST API"];
[weakSelf showAlertWithMessage:@"Received error in POST API response"]; }] resume];
return;
}
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&dataTaskError];
NSLog(@"MSG-POST: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from POST API"];
}] resume];
} }
- (IBAction)tappedGetAPI:(UIButton *)sender { - (IBAction)tappedGetAPI:(UIButton*)sender {
__weak NetworkViewController *weakSelf = self; __weak NetworkViewController* weakSelf = self;
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"] completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) { [[[NSURLSession sharedSession]
if (error || !data) { dataTaskWithURL:
[weakSelf showAlertWithMessage:@"Received error in GET API response"]; [NSURL URLWithString:@"https://demo9512366.mockable.io/FlipperGet"]
return; completionHandler:^(
} NSData* _Nullable data,
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; NSURLResponse* _Nullable response,
NSLog(@"MSG-GET: %@", dict[@"msg"]); NSError* _Nullable error) {
[weakSelf showAlertWithMessage:@"Received response from GET API"]; if (error || !data) {
}] resume]; [weakSelf showAlertWithMessage:@"Received error in GET API response"];
return;
}
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
NSLog(@"MSG-GET: %@", dict[@"msg"]);
[weakSelf showAlertWithMessage:@"Received response from GET API"];
}] resume];
} }
- (void)showAlertWithMessage:(nonnull NSString *)msg { - (void)showAlertWithMessage:(nonnull NSString*)msg {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [self alertControllerForMessage:msg]; UIAlertController* alertController = [self alertControllerForMessage:msg];
[self presentViewController:alertController animated:true completion:nil]; [self presentViewController:alertController animated:true completion:nil];
}); });
} }
- (UIAlertController *)alertControllerForMessage:(nonnull NSString *)msg { - (UIAlertController*)alertControllerForMessage:(nonnull NSString*)msg {
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Flipper" message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertController* controller =
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]; [UIAlertController alertControllerWithTitle:@"Flipper"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action =
[UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:nil];
[controller addAction:action]; [controller addAction:action];
return controller; return controller;
} }

View File

@@ -20,19 +20,19 @@
@interface RootViewController () @interface RootViewController ()
@property (strong, nonatomic) CKComponentHostingView *rootCKHostingView; @property(strong, nonatomic) CKComponentHostingView* rootCKHostingView;
@end @end
@implementation RootViewController @implementation RootViewController
- (instancetype)init - (instancetype)init {
{
if (self = [super init]) { if (self = [super init]) {
_rootCKHostingView = [[CKComponentHostingView alloc] _rootCKHostingView = [[CKComponentHostingView alloc]
initWithComponentProvider:[self class] initWithComponentProvider:[self class]
sizeRangeProvider: sizeRangeProvider:[CKComponentFlexibleSizeRangeProvider
[CKComponentFlexibleSizeRangeProvider providerWithFlexibility:CKComponentSizeRangeFlexibleHeight]]; providerWithFlexibility:
CKComponentSizeRangeFlexibleHeight]];
[self.view addSubview:_rootCKHostingView]; [self.view addSubview:_rootCKHostingView];
[self loadViewIfNeeded]; [self loadViewIfNeeded];
@@ -46,54 +46,45 @@
self.edgesForExtendedLayout = UIRectEdgeNone; self.edgesForExtendedLayout = UIRectEdgeNone;
} }
- (void)viewDidLayoutSubviews - (void)viewDidLayoutSubviews {
{
[super viewDidLayoutSubviews]; [super viewDidLayoutSubviews];
_rootCKHostingView.frame = self.view.bounds; _rootCKHostingView.frame = self.view.bounds;
} }
+ (CKComponent *)componentForModel:(id<NSObject>)model context:(id<NSObject>)context { + (CKComponent*)componentForModel:(id<NSObject>)model
context:(id<NSObject>)context {
return [CKBackgroundLayoutComponent return [CKBackgroundLayoutComponent
newWithComponent: newWithComponent:
[CKFlexboxComponent [CKFlexboxComponent newWithView:{}
newWithView:{ size:{}
} style:{}
size:{} children:{
style:{} {[CKButtonComponent
children: { newWithAction:nil
{ options:{
[CKButtonComponent .titles = @"Purple",
newWithAction:nil .titleColors =
options:{ UIColor.purpleColor,
.titles = @"Purple", }]},
.titleColors = UIColor.purpleColor, {[CKButtonComponent
} newWithAction:nil
] options:{
}, .titles = @"Brown",
{ .titleColors =
[CKButtonComponent UIColor.brownColor,
newWithAction:nil }]},
options:{ {[CKButtonComponent
.titles = @"Brown", newWithAction:nil
.titleColors = UIColor.brownColor, options:{
} .titles = @"Cyan",
] .titleColors =
}, UIColor.cyanColor,
{ }]},
[CKButtonComponent }]
newWithAction:nil background:[CKImageComponent
options:{ newWithImage:[UIImage imageNamed:@"sonarpattern"]
.titles = @"Cyan", attributes:{}
.titleColors = UIColor.cyanColor, size:{}]];
}
]
},
}]
background:
[CKImageComponent
newWithImage:[UIImage imageNamed:@"sonarpattern"]
attributes:{}
size:{}]];
} }
@end @end

View File

@@ -8,22 +8,23 @@
#import "UserDefaultsViewController.h" #import "UserDefaultsViewController.h"
@interface UserDefaultsViewController () @interface UserDefaultsViewController ()
@property (weak, nonatomic) IBOutlet UITextField *valueTextField; @property(weak, nonatomic) IBOutlet UITextField* valueTextField;
@property (weak, nonatomic) IBOutlet UITextField *keyTextField; @property(weak, nonatomic) IBOutlet UITextField* keyTextField;
@property (nonatomic, strong) NSUserDefaults *userDefaults; @property(nonatomic, strong) NSUserDefaults* userDefaults;
@end @end
@implementation UserDefaultsViewController @implementation UserDefaultsViewController
- (instancetype)initWithCoder:(NSCoder *)aDecoder { - (instancetype)initWithCoder:(NSCoder*)aDecoder {
if (self = [super initWithCoder:aDecoder]) { if (self = [super initWithCoder:aDecoder]) {
_userDefaults = [[NSUserDefaults alloc] initWithSuiteName:nil]; _userDefaults = [[NSUserDefaults alloc] initWithSuiteName:nil];
} }
return self; return self;
} }
- (IBAction)tappedSave:(id)sender { - (IBAction)tappedSave:(id)sender {
[self.userDefaults setObject:self.valueTextField.text forKey:self.keyTextField.text]; [self.userDefaults setObject:self.valueTextField.text
forKey:self.keyTextField.text];
} }
@end @end

View File

@@ -9,8 +9,9 @@
#import "AppDelegate.h" #import "AppDelegate.h"
int main(int argc, char * argv[]) { int main(int argc, char* argv[]) {
@autoreleasepool { @autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); return UIApplicationMain(
argc, argv, nil, NSStringFromClass([AppDelegate class]));
} }
} }