Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Swift Live Reload #94

Closed
tobinharris opened this issue Apr 18, 2015 · 4 comments
Closed

Swift Live Reload #94

tobinharris opened this issue Apr 18, 2015 · 4 comments

Comments

@tobinharris
Copy link

Would be great to see an example of how to get Live Reload working with Swift. I can't get CASAbsoluteFilePath to be available despite adding to the bridging header.

@keithnorm
Copy link
Contributor

I've found it helpful to write the watcher initializer in Obj-C still in order to take advantage of the #if TARGET_IPHONE_SIMULATOR preprocessor. I am doing it through an extension of CASStyler, but if doesn't have to be. e.g.:

// CASStyle+Additions.h
#import <Classy/Classy.h>

@interface CASStyler(Additions)

+ (void)initWatcher;

@end
// CASStyler+Additions.m

#import "CASStyler+Additions.h"

@implementation CASStyler (Additions)

+ (void)initWatcher {
#if TARGET_IPHONE_SIMULATOR
    NSString *absoluteFilePath = CASAbsoluteFilePath(@"../Resources/stylesheets/stylesheet.cas");
    [CASStyler defaultStyler].watchFilePath = absoluteFilePath;
#endif
}

@end
// AppDelegate.swift

import Classy

public class AppDelegate: UIResponder, UIApplicationDelegate {
   public func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        CASStyler.initWatcher()
  }
}

@greymouser
Copy link

Another option besides using the bridging header and the macro directly is just to use Swift and the FILE macro:

        if UIDevice.currentDevice().systemName.compare("iPhone Simulator") == .OrderedSame {
            let curFilePath = __FILE__
            let curFileDir = curFilePath.stringByDeletingLastPathComponent;
            let styleFilePath = curFileDir.stringByAppendingPathComponent("StyleSheets/stylesheet.cas")
            CASStyler.defaultStyler().watchFilePath = styleFilePath
        }

@keithnorm
Copy link
Contributor

Very nice, thanks!

@dnedrow
Copy link
Member

dnedrow commented Oct 19, 2017

Added to wiki.

@dnedrow dnedrow closed this as completed Oct 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants