2016-11-07 21:33:09 chwshuang 阅读数 9413
  • 微信h5支付开发-php开发微信h5支付demo

    会员免费看,http://edu.csdn.net/lecturer/842右侧可办理会员卡。微信h5支付开发是子恒老师《子恒说微信开发》视频教程的第17部。详细讲解了微信H5支付开发,内容包含开通H5支付,实现微信h5支付,订单查询,关闭订单等等。欢迎反馈,微信号:QQ68183131

    7977 人正在学习 去看看 秦子恒

XCode下Swift – WebView IOS demo

简介

我今天用Mac升级了XCode到8.1,swift版本应该到了swift3,按网上的demo写webview的例子,报一堆错,整了一天才搞定,不想其他人踩坑了!

XCode8.1 ,swift3,WebView的正确打开方式是这样的:

创建应用

打开XCode,创建一个新XCode项目
这里写图片描述

然后选择创建一个Simple View Aplication:

这里写图片描述

然后填写项目名称,组织名称,包名等信息
这里写图片描述

最后选择一个存放项目的目录,我选择的是在个人目录的xcodeprojects目录
这里写图片描述

设置Web View控件

第一步,选中根目录下的Main.storyboard文件,
第二步,选择第一面
第三步,搜索web view控件
第四步,按住Web View控件
第五步,拖拽Web View控件到页面
这里写图片描述

然后调整Web View控件达到充满整个屏幕,选择右上角的双环按钮,调出代码框
这里写图片描述

右键单击代码框,调出菜单,按住【Referencing Outlets】选项下【New Referencing Outlet】右边的【➕】号,拖拽到代码【ViewController】中
这里写图片描述

然后需要填入控件名称,这里输入webview这个名称:
这里写图片描述

处理网络请求

然后在【viewDidLoad】方法中加入代码

        // 1.设置访问资源 - 百度搜索
        let url = URL(string: "https://www.hushuang.me/");

        // 2.建立网络请求
        let request = URLRequest(url: url!);

        // 3.加载网络请求
        webview.loadRequest(request)

这里写图片描述

运行程序

最后,先选择【iPhone7】设备,然后点击左上角的运行按钮,就可以看到你所期待的内容了:
这里写图片描述

这里写图片描述

一定要看

如果你发现WebView请求不到数据,而你的的url是http://开头,日志中出现以下内容:

objc[11003]: Class PLBuildVersion is implemented in both
 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.
framework/AssetsLibraryServices (0x12160d998) and 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.
platform/Developer/SDKs/iPhoneSimulator.
sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.
framework/PhotoLibraryServices (0x121432d38).
One of the two will be used. 
Which one is undefined.
2016-11-07 21:28:23.217 webview[11003:404249] 
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. 
Temporary exceptions can be configured via your app's Info.
plist file.

说明XCode对http请求做了限制,具体处理方式请参考我的另外一篇博文:解开XCode开发工具的http协议限制问题

2017-05-25 19:56:55 appiox8 阅读数 359
  • 微信h5支付开发-php开发微信h5支付demo

    会员免费看,http://edu.csdn.net/lecturer/842右侧可办理会员卡。微信h5支付开发是子恒老师《子恒说微信开发》视频教程的第17部。详细讲解了微信H5支付开发,内容包含开通H5支付,实现微信h5支付,订单查询,关闭订单等等。欢迎反馈,微信号:QQ68183131

    7977 人正在学习 去看看 秦子恒
import UIKit


class ViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let viewRect = CGRect(x: 50, y: 50, width: 100, height: 100)
        let view1 = MyView(frame: viewRect)
        self.view.addSubview(view1)
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}


class MyView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        //把背景色设为透明
        self.backgroundColor = UIColor.clear
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func draw(_ rect: CGRect) {
        let pathRect = self.bounds.insetBy(dx: 1, dy: 1)
        let path = UIBezierPath(roundedRect: pathRect, cornerRadius: 10)
        path.lineWidth = 3
        
        UIColor.green.setFill()
        UIColor.blue.setStroke()
        
        path.fill()
        path.stroke()
    }
}
2016-11-24 17:56:34 qin8752 阅读数 346
  • 微信h5支付开发-php开发微信h5支付demo

    会员免费看,http://edu.csdn.net/lecturer/842右侧可办理会员卡。微信h5支付开发是子恒老师《子恒说微信开发》视频教程的第17部。详细讲解了微信H5支付开发,内容包含开通H5支付,实现微信h5支付,订单查询,关闭订单等等。欢迎反馈,微信号:QQ68183131

    7977 人正在学习 去看看 秦子恒

分享一个基于Swift3.0的ios入门学习Demo
看Swift基础有一段时间了,但是很少实践,最近准备抽时间把ios的基础过一遍,就给自己设计了这样一套作业(还有很多没完成,后续更新)。根据以前android的自学经验,入门涉及UI组件基础、自定义组件、数据存储、线程、网络、多媒体,当然你还有可能接触游戏开发。
这里写图片描述
目前工程已经涉及到Autolayout、网络、json和一些基本UI组件的使用,还有一些线程的使用(之前学习线程有单独写过帖子,这次就没有专门做这部分),以下是部分事例代码。
这里写图片描述

@objc func showCustom() {
    let  customAlert = UIAlertController(title: "登陆", message: "请输入用户名跟密码", preferredStyle: .alert)
    customAlert.addTextField{
        (textfield: UITextField) -> Void in
        textfield.placeholder="输入用户名"
    }
    customAlert.addTextField{
        (textfield: UITextField) -> Void in
        textfield.placeholder="输入密码"
    }
    let oneAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
    let twoAction = UIAlertAction(title: "登陆", style: .destructive, handler: nil)
    customAlert.addAction(oneAction)
    customAlert.addAction(twoAction)
    controller?.present(customAlert, animated: true, completion: nil)
}

这里写图片描述

    override func loadUi(controller: UIViewController) {
    super.loadUi(controller: controller)
    guard let rootView = controller.view else {
        return
    }
    //UISlider
    slider = UISlider()
    AutoLayoutUtils.utils.setView(view: slider, parent: rootView)
    .markSize(height: 60)
    .markTo(toView: rootView)
    .mark(top: 72, leading: 6, trailing: -6)
    .cimmit()

    slider!.minimumValue = 0
    slider!.maximumValue = 1
    slider!.value = 0.5

    //设置滑块停止后通知改变 默认true
//        slider.isContinuous = false
    slider!.addTarget(self, action: #selector(WidgetsLoader_01.sliderValueChanged(slider:)), for: .valueChanged)

    //UIProgressView
    progress = UIProgressView()
    AutoLayoutUtils.utils.setView(view: progress, parent: rootView)
        .markSize(height: 5)
        .markTo(toView: slider)
        .align(top: 10)
        .mark(leading: 6, trailing: -6, to: rootView)
        .cimmit()

    progress!.progress = 0.5

    let label = UILabel()
    AutoLayoutUtils.utils.setView(view: label, parent: rootView)
        .markSize(width: 280, height: 60)
        .markTo(toView: progress)
        .align(top: 6)
        .mark(leading:0)
        .cimmit()
    label.text = "slider变化是否在滑块停止后更新"

    //UISwitch
    let sw = UISwitch()
    AutoLayoutUtils.utils.setView(view: sw, parent: rootView)
        .mark(centerY: 0, to: label)
        .mark(trailing: 0, to: progress)
        .cimmit()
    sw.addTarget(self, action: #selector(WidgetsLoader_01.swithDidChanged(swith:)), for: .valueChanged)

    //UISegmentedControl
    let items = ["第一项","第二项","第三项"]
    let segmentCtl = UISegmentedControl(items: items)
    AutoLayoutUtils.utils.setView(view: segmentCtl, parent: rootView)
        .align(top: 10, to: label)
        .mark(centerX: 0, to: rootView)
        .cimmit()

    //
    segmentCtl.addTarget(self, action: #selector(WidgetsLoader_01.segmentDidChanged(segment:)), for: .valueChanged)
    segmentCtl.selectedSegmentIndex = 0
    self.segmentCtl = segmentCtl
    let segmentStateLabel = UILabel()
    segmentStateLabel.text="选择了第0项"
    AutoLayoutUtils.utils.setView(view: segmentStateLabel, parent: rootView)
        .markSize(width: 200, height: 40)
        .align(top: 2, to: segmentCtl)
        .mark(centerX: 0, to: rootView)
        .cimmit()
    segmentStateLabel.textAlignment = .center
    self.segmentStateLabel = segmentStateLabel


    let addBtn = UIButton()
    addBtn.setTitle("添加", for: .normal)
    addBtn.setTitleColor(UIColor.blue, for: .normal)
    addBtn.setTitleColor(UIColor.green, for: .highlighted)
    addBtn.addTarget(self, action: #selector(WidgetsLoader_01.addItem), for: .touchUpInside)
    AutoLayoutUtils.utils.setView(view: addBtn, parent: rootView)
        .markSize(width: 100, height: 30)
        .align(top: 2, to: segmentStateLabel)
        .mark(leading: 0, to: segmentCtl)
        .cimmit()


    let deleteBtn = UIButton()
    deleteBtn.setTitle("删除", for: .normal)
    deleteBtn.setTitleColor(UIColor.blue, for: .normal)
    deleteBtn.setTitleColor(UIColor.green, for: .highlighted)
    deleteBtn.addTarget(self, action: #selector(WidgetsLoader_01.removeItem), for: .touchUpInside)
    AutoLayoutUtils.utils.setView(view: deleteBtn, parent: rootView)
        .markSize(width: 100, height: 30)
        .align(top: 2, to: segmentStateLabel)
        .mark(trailing: 0, to: segmentCtl)
        .cimmit()
}

这里写图片描述

func get(url: String, callback: @escaping (_ weather: [String: Any]?)->()) {
    let  url = URL(string: url)
    let session = URLSession(configuration: URLSessionConfiguration.default)
    let  task = session.dataTask(with: url!, completionHandler: {
        (data: Data?, reponse: URLResponse?, error: Error?) -> Void in
        if error == nil {
            do {
                let dict = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any]

                DispatchQueue.main.async{
                    let weatherinfo = dict?["weatherinfo"] as? [String: Any]
                    for (name, value) in weatherinfo! {
                        print("name : \(name)  value : \(value)")
                    }
                    callback(weatherinfo)
                }
            } catch {
            }
        }
    })

    operationQueue.addOperation(){
        task.resume()
    }
}

下载:http://download.csdn.net/detail/qin8752/9692740

2014-06-07 17:55:15 iascchen 阅读数 2510
  • 微信h5支付开发-php开发微信h5支付demo

    会员免费看,http://edu.csdn.net/lecturer/842右侧可办理会员卡。微信h5支付开发是子恒老师《子恒说微信开发》视频教程的第17部。详细讲解了微信H5支付开发,内容包含开通H5支付,实现微信h5支付,订单查询,关闭订单等等。欢迎反馈,微信号:QQ68183131

    7977 人正在学习 去看看 秦子恒

简介

这篇文章记录了在 IOS 中使用 Swift 操作 CoreData 的一些基础性内容,由于缺乏文档,基本上都是自行实验的结果,错漏不可避免,还请谅解。

部分内容借鉴了 Tim Roadley 的《Learning.Core.Data.for.iOS(2013.11)》, 这本书主要介绍 ObjC的 CoreData 。


创建一个新 XCode 项目

  • 创建一个新的 XCode 项目。

  • 创建一个 Empty Application

  • 填写项目相关信息,如设置项目名称为: SwiftCoreDataSimpleDemo, 注意选择语言为 Swift, 并且勾选上 Use Core Data。

  • 选择存储项目的目录

  • 创建的新项目如下图所示


修改 Core Data Model

  • 选择 SwiftCoreDataSimpleDemo.xcdatamodeld 文件,目前还是空的。

  • 创建两个 Entity, 分别命名为 Family 和 Member。

  • 在生成模型文件之前,我们可以创建一个名为 models 的 Group , 用于存放生成的模型文件。

  • 选中 SwiftCoreDataSimpleDemo.xcdatamodeld 文件的某个 Entity 之后,能够在 Editor 菜单中找到 Create NSManagedObject Subclass,选择此项目,开始创建模型文件。

  • 跟随向导,完成模型创建,可以选中所有的 Entity ,并将存储位置指定为我们刚创建的 models Group 中。

  • 在结束之前,XCode 会弹出对话框,问是否创建用于 Swift 和 ObjC 协同工作的库文件 SwiftCoreDataSimpleDemo-Bridging-Header.h, 此时当然是选择 Yes。

生成完成之后,就能够在 Project 中看见新的模型文件了。此时,SwiftCoreDataSimpleDemo-Bridging-Header.h 还是空的,我们需要在其中增加需要被 Swift 访问的头文件。结果如下图所示:

#import "Family.h"
#import "Member.h"


修改 AppDelegate

和新建 ObjC App 类似,新建项目将操作 CoreData 的代码添加在 AppDelegate.swift 文件中。为了能够使代码更简洁和清晰,我们将这部分代码提炼出来,移动到 CoreDataHelper.swift 中去。

  • 打开原始的 AppDelegate.swift,在程序的后半部分,能够看见操作 CoreData 相关的代码.如下图所示。

  • 创建新 CoreDataHelper.swift 文件。修改文件名为 CoreDataHelper。

  • 在 AppDelegate.swift 中将 func saveContext () 及其后面的代码选中,转移到 CoreDataHelper.swift 文件中。并对其做些小调整,将所用到的项目名称提成常量,放在 CoreDataHelper 前部,这样,以后如果需要在历史项目中使用 CoreDataHelper,就十分方便了。

完成后的 CoreDataHelper.swift 代码如下:

//
//  CoreDataHelper.swift
//  SwiftCoreDataSimpleDemo
//
//  Created by CHENHAO on 14-6-7.
//  Copyright (c) 2014年 CHENHAO. All rights reserved.
//

import CoreData

class CoreDataHelper{

    let storeName = "SwiftCoreDataSimpleDemo"
    let storeFilename = "SwiftCoreDataSimpleDemo.sqlite"

    // #pragma mark - Core Data stack

    // Returns the managed object context for the application.
    // If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
    var managedObjectContext: NSManagedObjectContext {
    if !_managedObjectContext {
        let coordinator = self.persistentStoreCoordinator
        if coordinator != nil {
            _managedObjectContext = NSManagedObjectContext()
            _managedObjectContext!.persistentStoreCoordinator = coordinator
        }
        }
        return _managedObjectContext!
    }
    var _managedObjectContext: NSManagedObjectContext? = nil

    // Returns the managed object model for the application.
    // If the model doesn't already exist, it is created from the application's model.
    var managedObjectModel: NSManagedObjectModel {
    if !_managedObjectModel {
        let modelURL = NSBundle.mainBundle().URLForResource(storeName, withExtension: "momd")
        _managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL)
        }
        return _managedObjectModel!
    }
    var _managedObjectModel: NSManagedObjectModel? = nil

    // Returns the persistent store coordinator for the application.
    // If the coordinator doesn't already exist, it is created and the application's store added to it.
    var persistentStoreCoordinator: NSPersistentStoreCoordinator {
    if !_persistentStoreCoordinator {
        let storeURL = self.applicationDocumentsDirectory.URLByAppendingPathComponent(storeFilename)
        var error: NSError? = nil
        _persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
        if _persistentStoreCoordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: &error) == nil {
            /*
            Replace this implementation with code to handle the error appropriately.

            abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

            Typical reasons for an error here include:
            * The persistent store is not accessible;
            * The schema for the persistent store is incompatible with current managed object model.
            Check the error message to determine what the actual problem was.


            If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.

            If you encounter schema incompatibility errors during development, you can reduce their frequency by:
            * Simply deleting the existing store:
            NSFileManager.defaultManager().removeItemAtURL(storeURL, error: nil)

            * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
            [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true}

            Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

            */
            //println("Unresolved error \(error), \(error.userInfo)")
            abort()
        }
        }
        return _persistentStoreCoordinator!
    }
    var _persistentStoreCoordinator: NSPersistentStoreCoordinator? = nil

    // #pragma mark - Application's Documents directory

    // Returns the URL to the application's Documents directory.
    var applicationDocumentsDirectory: NSURL {
    let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
        return urls[urls.endIndex-1] as NSURL
    }

    func saveContext () {
        var error: NSError? = nil
        let managedObjectContext = self.managedObjectContext
        if managedObjectContext != nil {
            if managedObjectContext.hasChanges && !managedObjectContext.save(&error) {
                // Replace this implementation with code to handle the error appropriately.
                // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                //println("Unresolved error \(error), \(error.userInfo)")
                abort()
            }
        }
    }
}
  • 修改 AppDelegate.swift。并创建一个 CoreDataHelper 的实例,用于操作 CoreData。

applicationWillTerminate(application: UIApplication) 方法之后的内容全部替换为以下代码。

var cdh: CoreDataHelper {
if !_cdh {
    _cdh = CoreDataHelper()
    }
    return _cdh!
}
var _cdh: CoreDataHelper? = nil
  • 修改 AppDelegate.swift,以自动保存 CoreData。

代码如下:

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    self.cdh.saveContext()
}
...
func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    // Saves changes in the application's managed object context before the application terminates.

    self.cdh.saveContext()
}

操作模型对象

接下来我们将在 AppDelegate.swift 中创建一个访问 CoreData 的 demoFamily 方法,用于操作 CoreData。这段代码放在 func applicationDidBecomeActive(application: UIApplication) 中执行,操作结果从 Log 文件中查看。

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    self.demoFamily()
}

demoFamily() 的具体实现如下,代码说明请参考注释:

func demoFamily(){
    var newItemNames = ["Apples", "Milk", "Bread", "Cheese", "Sausages", "Butter", "Orange Juice", "Cereal", "Coffee", "Eggs", "Tomatoes", "Fish"]

    // add families
    NSLog(" ======== Insert ======== ")

    for newItemName in newItemNames {
        var newItem: Family = NSEntityDescription.insertNewObjectForEntityForName("Family", inManagedObjectContext: self.cdh.managedObjectContext) as Family

        newItem.name = newItemName
        NSLog("Inserted New Family for \(newItemName) ")
    }

    //self.cdh.saveContext()

    //fetch families
    NSLog(" ======== Fetch ======== ")

    var error: NSError? = nil
    var fReq: NSFetchRequest = NSFetchRequest(entityName: "Family")

    // 设置过滤条件
    fReq.predicate = NSPredicate(format:"name CONTAINS 'B' ")

    // 设置结果排序规则,此处设置为按 Name 逆序
    var sorter: NSSortDescriptor = NSSortDescriptor(key: "name" , ascending: false)
    fReq.sortDescriptors = [sorter]

    var result = self.cdh.managedObjectContext.executeFetchRequest(fReq, error:&error)
    for resultItem : AnyObject in result {
        var familyItem = resultItem as Family
        NSLog("Fetched Family for \(familyItem.name) ")
    }

    //delete families
    NSLog(" ======== Delete ======== ")

    fReq = NSFetchRequest(entityName: "Family")
    result = self.cdh.managedObjectContext.executeFetchRequest(fReq, error:&error)

    for resultItem : AnyObject in result {
        var familyItem = resultItem as Family
        NSLog("Deleted Family for \(familyItem.name) ")
        self.cdh.managedObjectContext.deleteObject(familyItem)
    }

    //self.cdh.saveContext()

    NSLog(" ======== Check Delete ======== ")

    result = self.cdh.managedObjectContext.executeFetchRequest(fReq, error:&error)
    if result.isEmpty {
        NSLog("Deleted All Families")
    }
    else{
        for resultItem : AnyObject in result {
            var familyItem = resultItem as Family
            NSLog("Fetched Error Family for \(familyItem.name) ")
        }
    }
}

Log输出如下:

2014-06-07 14:01:53.717 SwiftCoreDataSimpleDemo[18348:1419062] Application windows are expected to have a root view controller at the end of application launch
2014-06-07 14:01:54.100 SwiftCoreDataSimpleDemo[18348:1419062]  ======== Insert ======== 
2014-06-07 14:01:54.115 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Apples 
2014-06-07 14:01:54.115 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Milk 
2014-06-07 14:01:54.115 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Bread 
2014-06-07 14:01:54.116 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Cheese 
2014-06-07 14:01:54.116 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Sausages 
2014-06-07 14:01:54.116 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Butter 
2014-06-07 14:01:54.117 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Orange Juice 
2014-06-07 14:01:54.117 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Cereal 
2014-06-07 14:01:54.117 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Coffee 
2014-06-07 14:01:54.118 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Eggs 
2014-06-07 14:01:54.118 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Tomatoes 
2014-06-07 14:01:54.118 SwiftCoreDataSimpleDemo[18348:1419062] Inserted New Family for Fish 
2014-06-07 14:01:54.118 SwiftCoreDataSimpleDemo[18348:1419062]  ======== Fetch ======== 
2014-06-07 14:01:54.121 SwiftCoreDataSimpleDemo[18348:1419062] Fetched Family for Butter 
2014-06-07 14:01:54.122 SwiftCoreDataSimpleDemo[18348:1419062] Fetched Family for Bread 
2014-06-07 14:01:54.122 SwiftCoreDataSimpleDemo[18348:1419062]  ======== Delete ======== 
2014-06-07 14:01:54.123 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Tomatoes 
2014-06-07 14:01:54.123 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Cereal 
2014-06-07 14:01:54.123 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Orange Juice 
2014-06-07 14:01:54.123 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Eggs 
2014-06-07 14:01:54.124 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Milk 
2014-06-07 14:01:54.124 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Butter 
2014-06-07 14:01:54.124 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Sausages 
2014-06-07 14:01:54.125 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Cheese 
2014-06-07 14:01:54.125 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Apples 
2014-06-07 14:01:54.125 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Bread 
2014-06-07 14:01:54.125 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Fish 
2014-06-07 14:01:54.126 SwiftCoreDataSimpleDemo[18348:1419062] Deleted Family for Coffee 
2014-06-07 14:01:54.126 SwiftCoreDataSimpleDemo[18348:1419062]  ======== Check Delete ======== 
2014-06-07 14:01:54.127 SwiftCoreDataSimpleDemo[18348:1419062] Deleted All Families
Program ended with exit code: 9

不工作的 Member.swift 代码

参考 Swift 文档,尝试创建 Member.swift,编译通过,运行测试失败。因文档有限,没法进一步确定原因。记录在此,以供大家探讨。

Swift 文档的相关说明如下,Implementing Core Data Managed Object Subclasses

Implementing Core Data Managed Object Subclasses

Core Data provides the underlying storage and implementation of properties in subclasses
 of the NSManagedObject class. Add the @NSManaged attribute before each property definition
  in your managed object subclass that corresponds to an attribute or relationship in your 
  Core Data model. Like the @dynamic attribute in Objective-C, the @NSManaged attribute 
  informs the Swift compiler that the storage and implementation of a property will be 
  provided at runtime. However, unlike @dynamic, the @NSManaged attribute is available only 
  for Core Data support. 

根据文档编写 Member.swift 如下:

import CoreData

class Member: NSManagedObject {
    @NSManaged var name: String
    @NSManaged var sex: String
    @NSManaged var birthday: NSDate
}

将 SwiftCoreDataSimpleDemo-Bridging-Header.h 中的 Member.h 行注释掉:

#import "Family.h"
// #import "Member.h"

运行之后,编译成功,但运行出错闪退,出错界面如下。


代码地址

https://github.com/iascchen/SwiftCoreDataSimpleDemo/


打完收工


Author : iascchen(at)gmail(dot)com

Date : 2014-6-7

新浪微博 : @问天鼓

2017-04-12 17:37:42 UFO00001 阅读数 1075
  • 微信h5支付开发-php开发微信h5支付demo

    会员免费看,http://edu.csdn.net/lecturer/842右侧可办理会员卡。微信h5支付开发是子恒老师《子恒说微信开发》视频教程的第17部。详细讲解了微信H5支付开发,内容包含开通H5支付,实现微信h5支付,订单查询,关闭订单等等。欢迎反馈,微信号:QQ68183131

    7977 人正在学习 去看看 秦子恒

Github地址:BaiduMapDemo

iOS百度地图 Demo

阅读数 5027

iOS百度地图 Demo

博文 来自: yangmeng13930719363
没有更多推荐了,返回首页