Application Support You don’t have permission to save the file

Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “data” in the folder “gamedata”." UserInfo={NSFilePath=file:///var/mobile/Containers/Data/Application/651354D9-30FF-4156-9D31-5F90D92D13C7/Library/Application%20Support/gamedata/data, NSUnderlyingError=0x14010cbf0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

do {
            try NSFileManager.defaultManager().createDirectoryAtPath(GameData.filePath, withIntermediateDirectories: true, attributes: nil)
        } catch {
            print(error)
        }

        NSKeyedArchiver.archiveRootObject(GameData.data!, toFile: GameData.filePath)
        print(GameData.filePath)

createDirectoryAtPath will say You don’t have permission

OK, so use URL:

let fileManager = NSFileManager.defaultManager()
        let appSupportPath:[NSURL] = fileManager.URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
        let store:NSURL = appSupportPath.first!

        do {
            try NSFileManager.defaultManager().createDirectoryAtURL(store, withIntermediateDirectories: true, attributes: nil)
        } catch {
            print(error)
        }

        NSKeyedArchiver.archiveRootObject(GameData.data!, toFile: GameData.filePath)
        print(GameData.filePath)

SKView please presentScene(nil) or the scene will still here and eat the memory

me design LevelViewController (TableView) -> present -> GameViewController . SKView . Scene

When I dismiss the GameViewController, the scene “update” (onEnterFrame) still running, to prove that the scene has not been killed

And after several time present the GameViewController, the app will lag becoz too many SKScene is running.

So please (self.view as! SKView).presentScene(nil) when GameViewController self.dismissViewControllerAnimated(true, completion: nil)

scrollview with a uiview in masonry

A tableview which scrollview and the tableview can scroll to right

self.tableView = [[UITableView alloc]init];
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
self.tableView.backgroundColor = [UIColor whiteColor];
[self.tableView setAllowsSelection:NO];

    //build the scrollabe view
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;

    // add subview tree
    [self.scrollView addSubview:self.tableView];
    [self.view addSubview:self.scrollView];

    //build footer view
    self.footerView = [[DetailsTableVTViewFooterView alloc] init];
    self.footerView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.footerView];
    [self.footerView.saveButton addTarget:self action:@selector(saveLocalChanges) forControlEvents:UIControlEventTouchUpInside];

    // Using Masonry for autolayout
    [self.footerView makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@footerHeight);
        make.width.equalTo(frame.size.width);
        make.right.equalTo(self.view.right);
    }];

    self.scrollView.backgroundColor = [UIColor redColor];

    [self.scrollView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.right);
        make.left.equalTo(self.view.left);
        make.top.equalTo(self.view.top);
        make.bottom.equalTo(self.footerView.top);
    }];

    [self.tableView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(tableViewWidth);
        make.bottom.equalTo(self.footerView.top);
        make.left.equalTo(self.scrollView.left);
        make.right.equalTo(self.scrollView.right);
        make.top.equalTo(self.scrollView.top);
    }];

[android] center a drawText

For y :

int yPos = (int) ((canvas.getHeight() / 2) – ((paint.descent() + paint.ascent()) / 2)) ; //((textPaint.descent() + textPaint.ascent()) / 2) is the distance from the baseline to the center.

For x :

http://stackoverflow.com/questions/4909367/how-to-align-text-vertically