Closed tobinharris closed 6 years ago
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()
}
}
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
}
Very nice, thanks!
Added to wiki.
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.