我不确定我在这里做错了什么,但是当我第一次保存到coredata时,它运行得很好.当我试图覆盖它时,它没有.
func testStuff() {
var token = loadLoginData()
println("Token \(token)")
saveLoginData("New Token")
var newToken = loadLoginData()
println("Token \(newToken)")
}
func saveLoginData(accessToken: String) {
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context: NSManagedObjectContext = appDel.managedObjectContext!
// save data to core data
var loginData = NSEntityDescription.insertNewObjectForEntityForName("LoginData", inManagedObjectContext: context) as NSManagedObject
loginData.setValue(accessToken, forKey: "accessToken")
context.save(nil)
println("Done saving user")
}
/* Output
Token Optional("12345")
Done saving user
Token Optional("12345")
*/
Run Code Online (Sandbox Code Playgroud)
加载登录数据启用调用saveLogin数据的函数
func loadLoginData() -> String? {
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate) …Run Code Online (Sandbox Code Playgroud) 在我的主页面中,我为UITableViewCell创建了一个xib文件.我正在从该xib文件中加载单元格,并且工作正常.
在细胞内部,我有一些标签和按钮.我的目标是通过单击单元格上的按钮来更改标签.
我的代码喜欢以下
import UIKit
class SepetCell: UITableViewCell{
@IBOutlet var barcode: UILabel!
@IBOutlet var name: UILabel!
@IBOutlet var fav: UIButton!
@IBOutlet var strep: UIStepper!
@IBOutlet var times: UILabel!
@IBAction func favoriteClicked(sender: UIButton) {
println(sender.tag)
println(times.text)
SepetViewController().favorite(sender.tag)
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
Run Code Online (Sandbox Code Playgroud)
这是代码后面的xib文件,如.swift.
主页面中的代码如下:
import UIKit
import CoreData
class SepetViewController: UIViewController, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate {
@ …Run Code Online (Sandbox Code Playgroud) 我正在关注pluralsight 上的教程,这是一个全栈react/redux 教程,并且我正在使用以下代码创建一个saga.mock.js 文件。
这是我不熟悉的东西,希望得到解释,以便我能理解这一点。
import { take, put, select } from 'redux-saga/effects';
import * as mutations from './mutations';
import uuid from 'uuid';
export default function* taskCreationSaga(){
while (true) {
const {groupID} = yield take(mutations.REQUEST_TASK_CREATION);
console.log("Got group ID", groupID);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我商店的 index.js 中,我在星号**中添加了底部代码
import { createStore, applyMiddleware } from 'redux';
import { defaultState } from '../../server/defaultState';
import { createLogger } from 'redux-logger';
import createSagaMiddleware from 'redux-saga';
const sagaMiddleware = createSagaMiddleware();
import * as sagas from './sagas.mock'
export const store …Run Code Online (Sandbox Code Playgroud) 我一直在创建一个项目,只是为了帮助我自己学习核心数据,但是我来到了每个项目的一部分,我根本无法解决这个问题,这里是 - 我正在尝试创建一个UIAlert窗口,它调用我写的更新名称函数,用户可以输入新名称并点击更新,看起来很容易,而且我有我需要的代码,减去一小块.
我将发布我的代码,但我得到的错误是"无法将类型'String'的值转换为预期的参数类型'NameObject'",我明白,我的NameObject类是NSManagedObject类型,我只是不确定在哪里我错了或做了什么.
class NameObject: NSManagedObject {
static let entityName = "Person"
@NSManaged var name: String?}`class NameObject: NSManagedObject {
static let entityName = "Person"
@NSManaged var name: String? }
Run Code Online (Sandbox Code Playgroud)
func updateName(index: Int, newName: NameObject){
//1
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
// 2
peoples[index].name = newName.name
appDelegate.saveContext()
}
Run Code Online (Sandbox Code Playgroud)
据我所知,它完全正常.
这是我的UIAlert代码,
@IBAction func updateNameButton(sender: AnyObject, indexPath: NSIndexPath) {
//customCell().updateNameAlert()
func updateNameAlert(){
let alert = UIAlertController(title: "Update",
message: "Please enter the new name.",
preferredStyle: .Alert)
// 1
let …Run Code Online (Sandbox Code Playgroud) 这是我的困境,我正在做一些非常简单的事情,只是在做一些发现.基本上,我有一个按钮和一个标签,我将按钮设置为从3倒数到0,但我不是显示0,我希望它停止倒计时,并显示一个字符串,显示"是!"
class ViewController: UIViewController {
var myTimer: NSTimer = NSTimer()
var count: Int = 4
func startCountdown(){
myTimer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(myUpdate), userInfo: nil, repeats: true)
}
func myUpdate() {
if(count > 0) {
count -= 1
timerLabel.text = "\(count)"
}
}
func countdownReachedZero(){
if count == 1{
myTimer.invalidate()
timerLabel.text = "Yes!"
}
}
@IBOutlet weak var resultButtonOutlet: UIButton!
@IBOutlet weak var timerLabel: UILabel!
@IBAction func resultButton(sender: AnyObject) {
//button actions, starts countdown from 3-1
startCountdown()
} …Run Code Online (Sandbox Code Playgroud) ios ×4
swift ×4
core-data ×2
cocoa ×1
cocoa-touch ×1
javascript ×1
nstimer ×1
react-redux ×1
uitableview ×1