Skip to content

Instantly share code, notes, and snippets.

@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];
// ☆.。.:* CustomObject.h *・°☆*:..
@interface CustomObject : NSObject <NSCoding> // NSCodingプロトコルを利用
NSString *name;
NSString *address;
@end
// ☆.。.:* CustomObject.m *・°☆*:..
// デシリアライズの際に呼ばれる
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];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"places.plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:filePath];
for (NSData *data in [YSPlaceDataManager loadFromPropertyList]) {
// プリパティリストから取り出したNSData型のデータをCustomObject型に再変換
CustomObject *customObj = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSLog(@"%@", customObj);
}
@yoshimin
yoshimin / gist:142e359443c8c14eec3a
Created August 10, 2014 08:04
UIViewのサブクラスでCoreTextを使い文字を描画
#import "YMNCoreTextView.h"
#import <CoreText/CoreText.h>
#import <QuartzCore/QuartzCore.h>
@interface YMNCoreTextView()
@property (nonatomic, strong) NSMutableAttributedString *attributedString;
@end
@yoshimin
yoshimin / gist:7fc6c8759899583be101
Last active August 29, 2015 14:05
CoreTextを使って特定の文字をリンクっぽい見た目にする
#import "YMNCoreTextView.h"
#import <CoreText/CoreText.h>
#import <QuartzCore/QuartzCore.h>
@interface YMNCoreTextView()
@property (nonatomic, strong) NSMutableAttributedString *attributedString;
@end
@yoshimin
yoshimin / gist:b4ed78b58bbb12c20bf6
Created August 10, 2014 16:01
CoreTextを使って描画した文字をリンカブルにする
#import "YMNCoreTextView.h"
#import <CoreText/CoreText.h>
#import <QuartzCore/QuartzCore.h>
@interface YMNCoreTextView()
@property (nonatomic, strong) NSMutableAttributedString *attributedString;
@property (nonatomic, assign) CTFrameRef drawingFrame;
@property (nonatomic, assign) NSRange linkableWordRange;
@yoshimin
yoshimin / gist:82a31fc1f3d3f2a4c325
Created August 24, 2014 09:08
YMNImageCropViewControllerのインスタンスを生成
self.imageCropViewController = [[YMNImageCropViewController alloc] initWithImage:image];
self.imageCropViewController.delegate = self;
[self presentViewController:self.imageCropViewController animated:NO completion:nil];
@yoshimin
yoshimin / gist:e5bbb1d57285e9fd146f
Created August 24, 2014 09:11
delegateで画像が返される
- (void)imageCropViewController:(UIViewController* )controller didFinishCroppingImage:(UIImage *)image
{
//ここでimageを受け取る
}
@yoshimin
yoshimin / gist:1a26147f8c81e0e389fb
Created August 24, 2014 09:12
YMNImageCropMode
/// クロップの枠の拡縮の仕方
typedef NS_ENUM(NSUInteger, YMNImageCropMode) {
/// 枠のアスペクト比は自由
YMNImageCropModeFlexible,
/// 枠のアスペクト比は固定
YMNImageCropModeFixedAspect
};