Objective-Cに投稿されたコード一覧

Objective-C OCMockの引数検査

[[mockDelegate expect] didComplete:downloader withReceivedData:[OCMArg checkWithBlock:^BOOL(id obj) {

        NSData* input = (NSData*)obj;
        NSData* expected = [@"abc" dataUsingEncoding:NSUTF8StringEncoding];

        return [input isEqualToData:expected];
}]];

Objective-C ゆるふわ言語Objective-C

#import <Foundation/Foundation.h>

@interface TestClass : NSObject
{	@public
	NSString *myValue;

	@private
	NSString *myValue2;
}
@end

@implementation TestClass
@end

int main(void)
{
	TestClass *obj = [[TestClass alloc] init];
	[obj setValue:@"hogehoge" forKey:@"myValue"];
	[obj setValue:@"hogehogehoge" forKey:@"myValue2"];

	NSLog(@"%@", [obj valueForKey:@"myValue"]);
	//2012-11-25 18:49:00.636 a.out[61231:707] hogehoge
	NSLog(@"%@", obj->myValue);
	//2012-11-25 18:49:00.642 a.out[61231:707] hogehoge

	NSLog(@"%@", [obj valueForKey:@"myValue2"]);
	//2012-11-25 18:49:00.643 a.out[61231:707] hogehogehoge
	NSLog(@"%@", obj->myValue2);	// ここでWarning
	//2012-11-25 18:49:00.644 a.out[61231:707] hogehogehoge
	// ↑それでも表示出来る!!

	[obj release];

	return 0;
}

Objective-C UISearchbarをデフォルトの機能っぽいのつかいたいとき

#pragma mark - 検索バー Delegate

/*

 //UISearchBar
 schBar = [[UISearchBar alloc] init];//]WithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
 schBar.delegate = self;
 schBar.placeholder = @"検索";
 schBar.barStyle = UIBarStyleDefault;
 self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 88);
 self.navigationItem.titleView = schBar;
 self.navigationItem.titleView.frame = CGRectMake(0, 0, 320, 44);

 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
 label.text = @"これはテストです";
 label.textAlignment = UITextAlignmentCenter;
 label.textColor = [UIColor blackColor];
 [self.view addSubview:label];
 */

//検索ボタンがクリックされたときの処理
-(void) searchBarSearchButtonClicked:(UISearchBar *)searchBar {

    schFlg = YES;

    //NSLog(@"%@",searchBar.text);
    [searchBar resignFirstResponder];

    //サーチ用テキストを受信
    schText = searchBar.text;
    //[self tableView:nil didSelectRowAtIndexPath:nil];
}

-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    searchBar.showsCancelButton = YES;
}

-(void) searchBarTextDidEndEditing:(UISearchBar *)searchBar {
    searchBar.showsCancelButton = NO;
}

-(void) searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    [searchBar resignFirstResponder];
}

Objective-C バックグラウンドに入る時にmodalViewControllerをdismiss、ここでは(UIImagePickerController)

#import <UIKit/UIKit.h>
//hファイル
@interface PickerImageTestAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (weak, nonatomic) UIImagePickerController *picker;
@end

//mファイル
#import "PickerImageTestAppDelegate.h"

//↓ デフォルトでできるViewController
#import "PickerImageTestViewController.h"
@implementation PickerImageTestAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@"%s\n\n",__func__);
    UIStoryboard *storyBoard = [self.window.rootViewController storyboard];
    PickerImageTestViewController *myPicker = [storyBoard instantiateViewControllerWithIdentifier:@"MyPicker"];
    self.window.rootViewController = myPicker;
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    UIViewController *vc = [self.window.rootViewController presentedViewController];
    if ([vc isKindOfClass:[UIImagePickerController class]]) {
        [vc dismissModalViewControllerAnimated:NO];
    }
}

Objective-C Objective-Cのテスト

#import <stdio.h>
#import <objc/Object.h>

@interface Test : Object
- (void)Write;
@end

@implementation Test
- (void)Write {
	printf("I am the bone of my sword.\n");
}
@end

int main() {
	id obj;
	SEL method;

	obj = [Test new];
	method = @selector(Write);
	[obj perform:method];

	return 0;
}

よく投稿されているコード

タグ

最近投稿されたコード