Skip to content

Commit

Permalink
swift 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
时点软件 冯成林 authored and 时点软件 冯成林 committed Jun 6, 2017
1 parent bdeb651 commit 7b12bd3
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 124 deletions.
13 changes: 11 additions & 2 deletions Reflect.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@
TargetAttributes = {
89B833691B842549002C60EB = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0820;
ProvisioningStyle = Manual;
};
89B8337E1B84254A002C60EB = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0820;
TestTargetID = 89B833691B842549002C60EB;
};
};
Expand Down Expand Up @@ -500,11 +503,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Reflect/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "cn.CF.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -513,11 +518,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Reflect/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "cn.CF.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -537,6 +544,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "cn.CF.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Reflect.app/Reflect";
};
name = Debug;
Expand All @@ -553,6 +561,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "cn.CF.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Reflect.app/Reflect";
};
name = Release;
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions Reflect/Archiver3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Book3: Reflect{

let bookArr = [b1,b2,b3]

let path = Book3.save(obj: bookArr, name: "book3", duration: 0)
let path = Book3.save(obj: bookArr as AnyObject!, name: "book3", duration: 0)

print(path)

Expand All @@ -43,4 +43,4 @@ class Book3: Reflect{

}

}
}
4 changes: 2 additions & 2 deletions Reflect/BugFix1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

let UserDict = ["name": "jack", "age": "28", "img_model": ["url":"http://host.com/1.jpg"]]
let UserDict = ["name": "jack", "age": "28", "img_model": ["url":"http://host.com/1.jpg"]] as [String : Any]

class ImageModel: Reflect {

Expand All @@ -25,7 +25,7 @@ class UserModel: Reflect {

class func parse(){

let user = UserModel.parse(dict: UserDict)
let user = UserModel.parse(dict: UserDict as NSDictionary)

print("解析成功:\(user)")
}
Expand Down
6 changes: 3 additions & 3 deletions Reflect/JsonConvert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class CoachModel: Reflect {

static func parse(){

let d = jsonStr.dataUsingEncoding(NSUTF8StringEncoding)
let d = jsonStr.data(using: String.Encoding.utf8)

do{
// id obj=[NSJSONSerialization JSONObjectWithData:correctStringData options:NSJSONReadingAllowFragments error:&error];
let dict = try? NSJSONSerialization.JSONObjectWithData(d!, options: NSJSONReadingOptions.AllowFragments)
let dict = try? JSONSerialization.jsonObject(with: d!, options: JSONSerialization.ReadingOptions.allowFragments)
let m = CoachModel.parse(dict: dict as! NSDictionary)

print(m)
Expand All @@ -36,4 +36,4 @@ class CoachModel: Reflect {


}
}
}
2 changes: 1 addition & 1 deletion Reflect/Parse1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit


let Student1Dict = ["name": "jack", "age": "28", "age2": 28,"v1": 98.5, "v2": 568.32414,"isVip":"1"]
let Student1Dict: NSDictionary = ["name": "jack", "age": "28", "age2": 28,"v1": 98.5, "v2": 568.32414,"isVip":"1"]

/** 基本测试: 最常见类型的转换 */
class Student1: Reflect {
Expand Down
9 changes: 5 additions & 4 deletions Reflect/Parse2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//

import UIKit
import Foundation


let Student2Dict = ["name": "jack", "age": 28, "bag": ["color": "blue", "price": 14.5]]
let Student2Dict = ["name": "jack", "age": 28, "bag": ["color": "blue", "price": 14.5]] as [String : Any]


/** 在test1的基础上增加自定义对象 */
Expand All @@ -28,7 +28,7 @@ class Student2: Reflect {

class func parse(){

let stu2 = Student2.parse(dict: Student2Dict)
let stu2 = Student2.parse(dict: Student2Dict as NSDictionary)

print("\(stu2)")
}
Expand All @@ -48,7 +48,8 @@ class Bag: Reflect {
init (color: String, price: Float){

self.color = color
self.price = price

self.price = NSNumber(floatLiteral: Double(price))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Reflect/Parse3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

let Student3Dict = ["name": "jack", "age": 28, "pens": [["length":5.5],["length":6.5],["length":7.5]],"score": ["88",66,99.5]]
let Student3Dict: NSDictionary = ["name": "jack", "age": 28, "pens": [["length":5.5],["length":6.5],["length":7.5]],"score": ["88",66,99.5]]


/** 主要完成数组的转换 */
Expand Down
6 changes: 3 additions & 3 deletions Reflect/Parse4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

let Student4Dict = ["id":1, "name": "jack", "age": 26,"func": "zoom"]
let Student4Dict = ["id":1, "name": "jack", "age": 26,"func": "zoom"] as [String : Any]

/** 主要测试以下功能 */
// 模型中有多余的key
Expand Down Expand Up @@ -42,8 +42,8 @@ class Student4: Reflect {

class func parse(){

let stu4 = Student4.parse(dict: Student4Dict)
let stu4 = Student4.parse(dict: Student4Dict as NSDictionary)
print(stu4)
}

}
}
4 changes: 2 additions & 2 deletions Reflect/Parse5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

let Student5Dict = ["name": "jack", "age": 28,"items1": ["a1","b1","c1"],"items2": ["a2","b2","c2"],"bags": [["color": "red","price": 12.5],["color": "blue","price": 15]]]
let Student5Dict: NSDictionary = ["name": "jack", "age": 28,"items1": ["a1","b1","c1"],"items2": ["a2","b2","c2"],"bags": [["color": "red","price": 12.5],["color": "blue","price": 15]]]


/** 主要测试:隐式可选,事实表明,直接可用 */
Expand All @@ -27,4 +27,4 @@ class Student5: Reflect {

print(stu5)
}
}
}
6 changes: 3 additions & 3 deletions Reflect/Parse6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

let Student6Dict = ["name": "jack", "age": "28","score":"98","items1": ["a1","b1","c1"],"items2": ["a2","b2","c2"],"bags": [["color": "red","price": 12.5],["color": "blue","price": 15]]]
let Student6Dict = ["name": "jack", "age": "28","score":"98","items1": ["a1","b1","c1"],"items2": ["a2","b2","c2"],"bags": [["color": "red","price": 12.5],["color": "blue","price": 15]]] as [String : Any]


/** 主要测试:显式可选 */
Expand All @@ -24,8 +24,8 @@ class Student6: Reflect {

class func parse(){

let stu6 = Student6.parse(dict: Student6Dict)
let stu6 = Student6.parse(dict: Student6Dict as NSDictionary)

print(stu6)
}
}
}
6 changes: 3 additions & 3 deletions Reflect/Parse7.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class Student7: Reflect {


/** bool */
override func setValue(value: AnyObject?, forUndefinedKey key: String) {
override func setValue(_ value: Any?, forUndefinedKey key: String) {

self.age2 = value as! NSNumber != 0
}

class func parse(){

let stus = Student7.parses(arr: Student7DictArr)
let stus = Student7.parses(arr: Student7DictArr as NSArray)

for stu in stus {
print(stu)
}
}
}
}
4 changes: 2 additions & 2 deletions Reflect/Parse8.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Author: Reflect {

class func parse(){

let author = Author.parsePlist("Author")
let author = Author.parsePlist(name: "Author")
print(author)

}
}
}
42 changes: 21 additions & 21 deletions Reflect/Reflect/Coding/Reflect+ArcFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ extension Reflect{
static var DurationKey: String {return "Duration"}


class func save(obj obj: AnyObject! , name: String, duration: NSTimeInterval) -> String{
class func save(obj obj: AnyObject! , name: String, duration: TimeInterval) -> String{

if duration > 0 {

NSUserDefaults.standardUserDefaults().setDouble(NSDate().timeIntervalSince1970, forKey: name)
NSUserDefaults.standardUserDefaults().setDouble(duration, forKey: name + DurationKey)
UserDefaults.standard.set(NSDate().timeIntervalSince1970, forKey: name)
UserDefaults.standard.set(duration, forKey: name + DurationKey)
}

let path = pathWithName(name)
let path = pathWithName(name: name)

if obj != nil {

NSKeyedArchiver.archiveRootObject(obj, toFile: path)

}else{

let fm = NSFileManager.defaultManager()
if fm.fileExistsAtPath(path) {
let fm = FileManager.default
if fm.fileExists(atPath: path) {

if fm.isDeletableFileAtPath(path){
if fm.isDeletableFile(atPath: path){
do {
try fm.removeItemAtPath(path)
try fm.removeItem(atPath: path)
}catch {
print("删除失败")
}
Expand All @@ -48,19 +48,19 @@ extension Reflect{
return path
}

class func read(name name: String) -> (Bool, AnyObject!){
class func read(name name: String) -> (Bool, AnyObject?){

let time = NSUserDefaults.standardUserDefaults().doubleForKey(name)
let duration = NSUserDefaults.standardUserDefaults().doubleForKey(name + DurationKey)
let time = UserDefaults.standard.double(forKey: name)
let duration = UserDefaults.standard.double(forKey: name + DurationKey)
let now = NSDate().timeIntervalSince1970
let path = pathWithName(name)
let path = pathWithName(name: name)

let obj = NSKeyedUnarchiver.unarchiveObjectWithFile(path)
let obj = NSKeyedUnarchiver.unarchiveObject(withFile: path)

if time > 0 && duration > 0 && time + duration < now {return (false,obj)}
if obj == nil {return (false,obj)}
if time > 0 && duration > 0 && time + duration < now {return (false,obj as AnyObject?)}
if obj == nil {return (false,obj as AnyObject?)}

return (true,obj)
return (true,obj as AnyObject?)
}

class func deleteReflectModel(name name: String){save(obj: nil, name: name, duration: 0)}
Expand All @@ -74,18 +74,18 @@ extension Reflect{

static var cachesFolder: String? {

let cacheRootPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomainMask.UserDomainMask, true).last
let cacheRootPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last

let cache_reflect_path = cacheRootPath! + "/" + "Reflect"

let fm = NSFileManager.defaultManager()
let fm = FileManager.default

let existed = fm.fileExistsAtPath(cache_reflect_path)
let existed = fm.fileExists(atPath: cache_reflect_path)

if !existed {

do {
try fm.createDirectoryAtPath(cache_reflect_path, withIntermediateDirectories: true, attributes: nil)
try fm.createDirectory(atPath: cache_reflect_path, withIntermediateDirectories: true, attributes: nil)

}catch {}

Expand All @@ -98,4 +98,4 @@ extension Reflect{


func ignoreCodingPropertiesForCoding() -> [String]? {return nil}
}
}
Loading

0 comments on commit 7b12bd3

Please sign in to comment.