Skip to content

Instantly share code, notes, and snippets.

张嘉夫 josephchang10

Block or report user

Report or block josephchang10

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@josephchang10
josephchang10 / blockchain.swift
Created Dec 27, 2017
在 iOS 中实现区块链
View blockchain.swift
import Cocoa
import Foundation
class Block {
var index: Int = 0
var dateCreated: String
var previousHash: String!
var hash: String!
var nonce: Int
@josephchang10
josephchang10 / ReviewRequest.swift
Created Aug 12, 2017
从 iOS 10.3 开始请求应用商店评分的正确姿势:SKStoreReviewController
View ReviewRequest.swift
//
// ReviewRequest.swift
//
// Created by 张嘉夫 on 12/8/17.
// Copyright © 2017 张嘉夫. All rights reserved.
import Foundation
import StoreKit
let runIncrementerSetting = "numberOfRuns" // 用于存储运行次数的 UserDefauls 字典键
@josephchang10
josephchang10 / str.swift
Created Nov 8, 2017
The more elegant way to remove all characters after specific character in the String object in Swift
View str.swift
var str = "str.str"
if let dotRange = str.range(of: ".") {
str.removeSubrange(dotRange.lowerBound..<str.endIndex)
}
View CoreDataStack.swift
//
// CoreDataStack.swift
// ChineseNewWords
//
// Created by 张嘉夫 on 06/11/2017.
// Copyright © 2017 张嘉夫. All rights reserved.
//
import Foundation
import CoreData
@josephchang10
josephchang10 / shuffle.m
Created Apr 18, 2017
How to shuffle a NSMutableArray [Objective-C]
View shuffle.m
/* myArray is a NSMutableArray with some objects */
NSUInteger count = [myArray count];
for (NSUInteger i = 0; i < count; ++i) {
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[myArray exchangeObjectAtIndex:i withObjectAtIndex:n];
}
@josephchang10
josephchang10 / orientation.swift
Created Apr 14, 2017
Setting device orientation in Swift iOS
View orientation.swift
override var prefersStatusBarHidden: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [UIInterfaceOrientationMask.portrait, UIInterfaceOrientationMask.portraitUpsideDown]
}
View MainThread.swift
DispatchQueue.main.async {
self.imageView.image = image
}
@josephchang10
josephchang10 / sort.m
Created Jan 23, 2017
Best way to sort an NSArray of NSDictionary objects
View sort.m
NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES];
stories = [stories sortedArrayUsingDescriptors:@[descriptor]];
recent = [stories copy];
@josephchang10
josephchang10 / FavoriteViewController.m
Created Jan 22, 2017
初次加载隐藏搜索框
View FavoriteViewController.m
- (void)initSearchBar
{
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
[searchBar sizeToFit];
searchBar.placeholder = [IFI18nUtils getLocalizedString:@"SEARCH"];
searchBar.delegate = self;
searchBar.backgroundColor = [UIColor clearColor];
[self.collectionView setContentInset:UIEdgeInsetsMake(-44, 0, 0, 0)];
}
@josephchang10
josephchang10 / FavoriteViewController.m
Created Jan 22, 2017
初次加载隐藏搜索框
View FavoriteViewController.m
- (void)initSearchBar
{
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
[searchBar sizeToFit];
searchBar.placeholder = [IFI18nUtils getLocalizedString:@"SEARCH"];
searchBar.delegate = self;
searchBar.backgroundColor = [UIColor clearColor];
[self.collectionView setContentInset:UIEdgeInsetsMake(-44, 0, 0, 0)];
}
You can’t perform that action at this time.