This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIViewをUIImageに変換する(objective-c) | |
- (UIImage*)convertUIimageFromUIview:(UIView*)view { | |
UIGraphicsBeginImageContext(view.frame.size); | |
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a: AnyObject? = 1 | |
var c = (a as! NSNumber) | |
var array = ["a","b","c"] | |
var b = array[c.integerValue] | |
//=> b = "b" | |
var d = array[(a as! NSNumber).integerValue + 1] | |
//=> d = "c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
#import <CoreBluetooth/CoreBluetooth.h> | |
@interface ViewController ()<CBCentralManagerDelegate> | |
@end | |
@interface ViewController () { | |
@property (nonatomic) CBCentralManager *bluetoothManager; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let limitByte: Int = 1000000 | |
var compressionQuality: CGFloat = 1.0 | |
var data: NSData! | |
repeat { | |
data = UIImageJPEGRepresentation(images,compressionQuality) | |
print("Quality\((compressionQuality)) = \(data!.length)") | |
compressionQuality -= 0.1 | |
} while data?.length > limitByte |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ViewController | |
var focusCellIndex: NSIndexPath! | |
func keyboardDidShow(notification: NSNotification) { | |
let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() | |
UIView.animateWithDuration(0, animations: { | |
self.mainTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.viewHeight - rect.height) | |
}) { (boolValue) -> Void in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ~= パターンマッチ(左辺の範囲内に右辺が有ればtrue) | |
200 //=> Contains | |
300 //=> Not Contains | |
let status = 299 | |
//=> Contains | |
if (200 ..< 300) ~= status { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dict = ["key1":"value1","key2":"value2","key3":"value3"] | |
// 変数を宣言(初期値を設定) | |
var value1: String = "defaultValue" | |
// 値が取得できれば代入 | |
if let tmpValue = dict["key"] { | |
value1 = tmpValue | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 使用例 | |
let errorMessage = MessageManager.LoginView.IDMaxLengthError | |
//=> IDは10桁で入力してください。 | |
struct MessageManager { | |
/** 入力画面 */ | |
struct InputView { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 配列を区切り文字で連結 | |
(Obj-C) | |
NSArray *array = @[@"1",@"2",@"3",@"4",@"5"]; | |
NSString *joinedString = [array componentsJoinedByString:@","]; | |
(Swift) | |
let joinedString = ["1", "2", "3", "4", "5"].joinWithSeparator(",") | |
//=> "1,2,3,4,5" |
OlderNewer