-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update sample Core Data project to include settings screen for toggli…
…ng both the stemmingDisabled and supportStemmedPrefixSearches properties of CLuceneSearchService dynamically at runtime.
- Loading branch information
Showing
8 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
|
||
@property (nonatomic, strong) id<BRSearchService> searchService; | ||
|
||
- (void)reindex; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
SampleCoreDataProject/SampleCoreDataProject/SettingsViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// SettingsViewController.h | ||
// SampleCoreDataProject | ||
// | ||
// Created by Matt on 4/22/15. | ||
// Copyright (c) 2015 Blue Rocket, Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
extern NSString * const kStemmingDisabledKey; | ||
extern NSString * const kStemmingPrefixSupportEnabledKey; | ||
|
||
/** | ||
Provide a UI for changing system settings. Add settings are stored in @c NSUserDefaults. | ||
*/ | ||
@interface SettingsViewController : UIViewController | ||
|
||
@end |
49 changes: 49 additions & 0 deletions
49
SampleCoreDataProject/SampleCoreDataProject/SettingsViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// SettingsViewController.m | ||
// SampleCoreDataProject | ||
// | ||
// Created by Matt on 4/22/15. | ||
// Copyright (c) 2015 Blue Rocket, Inc. All rights reserved. | ||
// | ||
|
||
#import "SettingsViewController.h" | ||
|
||
NSString * const kStemmingDisabledKey = @"StemmingDisabled"; | ||
NSString * const kStemmingPrefixSupportEnabledKey = @"StemmingPrefixSupportEnabled"; | ||
|
||
@interface SettingsViewController () | ||
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topMarginConstraint; | ||
@property (strong, nonatomic) IBOutlet UISwitch *stemmingSwitch; | ||
@property (strong, nonatomic) IBOutlet UISwitch *stemmingPrefixSwitch; | ||
@end | ||
|
||
@implementation SettingsViewController | ||
|
||
- (void)viewWillAppear:(BOOL)animated { | ||
[super viewWillAppear:animated]; | ||
[self updateUIFromModel]; | ||
} | ||
|
||
- (void)viewWillLayoutSubviews { | ||
[super viewWillLayoutSubviews]; | ||
self.topMarginConstraint.constant = (self.topLayoutGuide.length + 20); | ||
} | ||
|
||
- (void)updateUIFromModel { | ||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | ||
self.stemmingSwitch.on = ([defaults boolForKey:kStemmingDisabledKey] != YES); | ||
self.stemmingPrefixSwitch.enabled = self.stemmingSwitch.on; | ||
self.stemmingPrefixSwitch.on = [defaults boolForKey:kStemmingPrefixSupportEnabledKey]; | ||
} | ||
|
||
- (IBAction)switchDidChange:(UISwitch *)sender { | ||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | ||
if ( sender == self.stemmingSwitch ) { | ||
[defaults setBool:!sender.on forKey:kStemmingDisabledKey]; | ||
[self updateUIFromModel]; | ||
} else if ( sender == self.stemmingPrefixSwitch ) { | ||
[defaults setBool:sender.on forKey:kStemmingPrefixSupportEnabledKey]; | ||
} | ||
} | ||
|
||
@end |
62 changes: 62 additions & 0 deletions
62
SampleCoreDataProject/SampleCoreDataProject/SettingsViewController.xib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7531" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/> | ||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SettingsViewController"> | ||
<connections> | ||
<outlet property="stemmingPrefixSwitch" destination="Edd-UJ-tLj" id="Uck-R4-iBx"/> | ||
<outlet property="stemmingSwitch" destination="qgV-k5-ZgA" id="N1T-Qs-S6V"/> | ||
<outlet property="topMarginConstraint" destination="dGm-3Q-FNx" id="jiO-C1-iBo"/> | ||
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | ||
</connections> | ||
</placeholder> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" text="Stemming enabled" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="JdM-cd-HDl"> | ||
<rect key="frame" x="18" y="34" width="507" height="20"/> | ||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qgV-k5-ZgA"> | ||
<rect key="frame" x="533" y="28" width="51" height="31"/> | ||
<connections> | ||
<action selector="switchDidChange:" destination="-1" eventType="valueChanged" id="zRT-ko-8Pa"/> | ||
</connections> | ||
</switch> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" text="Stemming prefix query support" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="SLs-6L-KfE"> | ||
<rect key="frame" x="18" y="85" width="507" height="20"/> | ||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Edd-UJ-tLj"> | ||
<rect key="frame" x="533" y="79" width="51" height="31"/> | ||
<connections> | ||
<action selector="switchDidChange:" destination="-1" eventType="valueChanged" id="pwt-r9-faY"/> | ||
</connections> | ||
</switch> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="qgV-k5-ZgA" firstAttribute="leading" secondItem="JdM-cd-HDl" secondAttribute="trailing" constant="8" symbolic="YES" id="0aP-5D-FOf"/> | ||
<constraint firstItem="Edd-UJ-tLj" firstAttribute="top" secondItem="qgV-k5-ZgA" secondAttribute="bottom" constant="20" id="3Ev-bu-OoJ"/> | ||
<constraint firstItem="JdM-cd-HDl" firstAttribute="leading" secondItem="SLs-6L-KfE" secondAttribute="leading" id="8Uq-Gf-MIn"/> | ||
<constraint firstItem="qgV-k5-ZgA" firstAttribute="trailing" secondItem="Edd-UJ-tLj" secondAttribute="trailing" id="JIL-Jh-K4H"/> | ||
<constraint firstAttribute="trailingMargin" secondItem="qgV-k5-ZgA" secondAttribute="trailing" constant="10" id="MSD-45-ugT"/> | ||
<constraint firstItem="JdM-cd-HDl" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leadingMargin" constant="10" id="bpM-Su-WWX"/> | ||
<constraint firstItem="qgV-k5-ZgA" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="topMargin" constant="20" id="dGm-3Q-FNx"/> | ||
<constraint firstItem="Edd-UJ-tLj" firstAttribute="leading" secondItem="SLs-6L-KfE" secondAttribute="trailing" constant="8" symbolic="YES" id="j0S-J3-h7l"/> | ||
<constraint firstItem="SLs-6L-KfE" firstAttribute="centerY" secondItem="Edd-UJ-tLj" secondAttribute="centerY" id="r8K-ED-Qlk"/> | ||
<constraint firstItem="JdM-cd-HDl" firstAttribute="centerY" secondItem="qgV-k5-ZgA" secondAttribute="centerY" id="xED-z6-xfI"/> | ||
</constraints> | ||
</view> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters