func nowTime() -> String { /* 2018-04-30 19:33:32.265253+0900 */
let format = DateFormatter()
format.dateFormat = "yyyy/MM/dd HH:mm:ss.SSS"
return format.string(from: Date())
}
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
// 配列を区切り文字で連結 | |
(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" |
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
// Check UINavigationController Pop or UIViewController dismiss | |
override func viewDidDisappear(animated: Bool) { | |
super.viewDidDisappear(animated) | |
let vcs = self.navigationController?.viewControllers | |
if ((vcs?.contains(self)) == nil) { | |
print("UINavigationController Pop") | |
} else { |
OlderNewer