Skip to content

Instantly share code, notes, and snippets.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"places.plist"];
// NSKeyedArchiverを使ってNSData型に変換
NSData *data1 = [NSKeyedArchiver archivedDataWithRootObject:customObj1];
NSData *data2 = [NSKeyedArchiver archivedDataWithRootObject:customObj2];
NSArray *array = @[data1, data2];
[array writeToFile:[self dataFilePath] atomically:YES];
// ☆.。.:* CustomObject.h *・°☆*:..
@interface CustomObject : NSObject <NSCoding> // NSCodingプロトコルを利用
NSString *name;
NSString *address;
@end
// ☆.。.:* CustomObject.m *・°☆*:..
// デシリアライズの際に呼ばれる
@yoshimin
yoshimin / gist:9848554
Created March 29, 2014 04:40
カスタムオブジェクトを格納した配列をプロパティリストに保存(間違った方法)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"places.plist"];
NSArray *array = @[customObj1, customObj2];
[array writeToFile:[self dataFilePath] atomically:YES];
@yoshimin
yoshimin / gist:8514127
Created January 20, 2014 02:53
UIButton+block.m
#import "UIButton+block.h"
#import <objc/runtime.h>
static char BUTTON_BLOCK;
@implementation UIButton (block)
- (void)addBlock:(void (^)(void))block forControlEvents:(UIControlEvents)event {
self.didTapped = block;
[self addTarget:self action:@selector(callBlock:) forControlEvents:event];
@yoshimin
yoshimin / gist:8514122
Created January 20, 2014 02:52
UIButton+block.h
#import <UIKit/UIKit.h>
@interface UIButton (block)
@property (nonatomic, copy) void (^didTapped)();
- (void)addBlock:(void (^)(void))block forControlEvents:(UIControlEvents)event;
@end
@yoshimin
yoshimin / gist:8254289
Last active January 2, 2016 04:59
基本的なNSAttributedStringの実装
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
label.font = [UIFont systemFontOfSize:10.f];
[self.view addSubview:label];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"UILabelにNSAttributedStringを表示〆(∀`*)"];
NSDictionary *attributes = @{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}; // ここではアンダーラインをセット
[attrStr addAttributes:attributes range:NSMakeRange(0, attrStr.length)];
label.attributedText = attrStr;
@yoshimin
yoshimin / gist:6255401
Last active December 21, 2015 05:18
UILabelにCAGradientLayerをつかってグラデーションをかける
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
//レイヤをビューの中央に配置する
gradientLayer.bounds = self.layer.bounds;
gradientLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
gradientLayer.startPoint = CGPointMake(0, CGRectGetMidY(self.frame)); //開始ポイント
gradientLayer.endPoint = CGPointMake(1, CGRectGetMidY(self.frame)); //終了ポイント
id opaque = (id)[UIColor blackColor].CGColor; //開始色
@yoshimin
yoshimin / gist:6060200
Created July 23, 2013 06:06
htmlでファイルをアップロード
<form enctype="multipart/form-data" action="アクション" method="post">
<input type="file" name="movie" /><br />
<br />
<input type="submit" value="送信" />
</form>
@yoshimin
yoshimin / gist:6060188
Last active December 20, 2015 02:59
PHPでPOSTで送信されたデータを受け取る処理
$updir = "./movies/";
$filename = $_FILES['movie']['name'];
//is_uploaded_file でファイルがアップロードされたかどうか調べる
if (is_uploaded_file($_FILES["movie"]["tmp_name"])) {
//move_uploaded_file を使って一時的な保存先から指定のフォルダに移動させる
if (move_uploaded_file($_FILES["movie"]["tmp_name"], $updir.$filename)) {
var_dump("成功");
@yoshimin
yoshimin / gist:6060096
Last active December 20, 2015 02:59
objective-cのNSMutableURLRequestを使ってファイルをアップロードする
#import "YSViewController.h"
@interface YSViewController ()
@end
@implementation YSViewController
- (void)viewDidLoad {