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
#pragma mark - Check String (まっすーアルゴリズム) | |
- (NSString *)checkString:(NSString *)string | |
{ | |
NSRange searchResult = [string rangeOfString:@"="]; | |
NSString *numberString; | |
NSLog(@"string is %@", string); | |
if(searchResult.location == NSNotFound){ |
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
- (void)saveHighScoreToNSUserDefaults:(float)currentScore | |
{ | |
// Load last HighScore | |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; | |
float lastScore = [userDefaults floatForKey:@"highScore"]; | |
if (lastScore < currentScore) { | |
[userDefaults setFloat:currentScore forKey:@"highScore"]; | |
// Save now | |
[userDefaults synchronize]; |
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 UIKit | |
class ViewController: UIViewController { | |
@IBOutlet var label: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
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
func insertGradientLayer(view: UIView) { | |
let color1 = UIColor.redColor() | |
let color2 = UIColor(red: 255, green: 165, blue: 0, alpha: 1.0) | |
let color3 = UIColor.yellowColor() | |
let color4 = UIColor(red: 0, green: 128, blue: 0, alpha: 1.0) | |
let color5 = UIColor.cyanColor() | |
let color6 = UIColor.blueColor() | |
let color7 = UIColor.purpleColor() | |
let fromColors = [color1.CGColor, color2.CGColor, color3.CGColor, color4.CGColor, color5.CGColor, color6.CGColor, color7.CGColor] | |
let toColors = fromColors.reverse() |
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
func uploadProfileImage(imageData: Data, filename: String, result: @escaping (_ imageUrl: String?, _ error: Error?) -> Void) { | |
// 例えばアップロード先への参照ができるstorage変数に画像をアップロードし、アップロードが完了されたらその画像のダウンロードURLを取得する場合 | |
storage.putData(imageData, completion: { (metadata, error) in | |
// 追加 | |
print(metadata) // <- 呼ばれる | |
if let error = error { | |
// クロージャの呼び出し元に返す | |
result(nil, error) | |
} else { | |
metadata?.storageReference?.downloadURL(completion: { (url, error) 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
extension UITextView { | |
func setTextWithTypeAnimation(typedText: String, characterDelay: TimeInterval = 5.0) { | |
text = "" | |
var writingTask: DispatchWorkItem? | |
writingTask = DispatchWorkItem { [weak weakSelf = self] in | |
for character in typedText { | |
DispatchQueue.main.async { | |
weakSelf?.text!.append(character) | |
} | |
Thread.sleep(forTimeInterval: characterDelay/100) |
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
【カウントダウンタイマー】 | |
// ①Storyboardにタイマー用のLabelを置く | |
// ②変数宣言する | |
// タイマー用カウンター | |
var count: Double = 0.0 | |
// タイマー用ラベル | |
@IBOutlet var timerLabel: UILabel! | |
// ②func showQuizの最後に以下のコードを追加する | |
Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(countDownTimer(timer:)), userInfo: nil, repeats: true) |